src/Pure/PIDE/markup.scala
author wenzelm
Tue Mar 18 12:25:17 2014 +0100 (2014-03-18 ago)
changeset 56202 0a11d17eeeff
parent 55919 2eb8c13339a5
child 56278 2576d3a40ed6
permissions -rw-r--r--
more markup for improper elements;
     1 /*  Title:      Pure/PIDE/markup.scala
     2     Module:     PIDE
     3     Author:     Makarius
     4 
     5 Isabelle-specific implementation of quasi-abstract markup elements.
     6 */
     7 
     8 package isabelle
     9 
    10 
    11 object Markup
    12 {
    13   /* properties */
    14 
    15   val NAME = "name"
    16   val Name = new Properties.String(NAME)
    17 
    18   val KIND = "kind"
    19   val Kind = new Properties.String(KIND)
    20 
    21   val INSTANCE = "instance"
    22   val Instance = new Properties.String(INSTANCE)
    23 
    24 
    25   /* basic markup */
    26 
    27   val Empty = Markup("", Nil)
    28   val Broken = Markup("broken", Nil)
    29 
    30   class Markup_String(val name: String, prop: String)
    31   {
    32     private val Prop = new Properties.String(prop)
    33 
    34     def apply(s: String): Markup = Markup(name, Prop(s))
    35     def unapply(markup: Markup): Option[String] =
    36       if (markup.name == name) Prop.unapply(markup.properties) else None
    37   }
    38 
    39   class Markup_Int(val name: String, prop: String)
    40   {
    41     private val Prop = new Properties.Int(prop)
    42 
    43     def apply(i: Int): Markup = Markup(name, Prop(i))
    44     def unapply(markup: Markup): Option[Int] =
    45       if (markup.name == name) Prop.unapply(markup.properties) else None
    46   }
    47 
    48 
    49   /* formal entities */
    50 
    51   val BINDING = "binding"
    52   val ENTITY = "entity"
    53   val DEF = "def"
    54   val REF = "ref"
    55 
    56   object Entity
    57   {
    58     def unapply(markup: Markup): Option[(String, String)] =
    59       markup match {
    60         case Markup(ENTITY, props) =>
    61           (props, props) match {
    62             case (Kind(kind), Name(name)) => Some((kind, name))
    63             case _ => None
    64           }
    65         case _ => None
    66       }
    67   }
    68 
    69 
    70   /* completion */
    71 
    72   val COMPLETION = "completion"
    73   val NO_COMPLETION = "no_completion"
    74 
    75 
    76   /* position */
    77 
    78   val LINE = "line"
    79   val OFFSET = "offset"
    80   val END_OFFSET = "end_offset"
    81   val FILE = "file"
    82   val ID = "id"
    83 
    84   val DEF_LINE = "def_line"
    85   val DEF_OFFSET = "def_offset"
    86   val DEF_END_OFFSET = "def_end_offset"
    87   val DEF_FILE = "def_file"
    88   val DEF_ID = "def_id"
    89 
    90   val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
    91   val POSITION = "position"
    92 
    93 
    94   /* embedded languages */
    95 
    96   val Symbols = new Properties.Boolean("symbols")
    97   val Antiquotes = new Properties.Boolean("antiquotes")
    98   val Delimited = new Properties.Boolean("delimited")
    99 
   100   val LANGUAGE = "language"
   101   object Language
   102   {
   103     val ML = "ML"
   104     val UNKNOWN = "unknown"
   105 
   106     def unapply(markup: Markup): Option[(String, Boolean, Boolean, Boolean)] =
   107       markup match {
   108         case Markup(LANGUAGE, props) =>
   109           (props, props, props, props) match {
   110             case (Name(name), Symbols(symbols), Antiquotes(antiquotes), Delimited(delimited)) =>
   111               Some((name, symbols, antiquotes, delimited))
   112             case _ => None
   113           }
   114         case _ => None
   115       }
   116   }
   117 
   118 
   119   /* external resources */
   120 
   121   val PATH = "path"
   122   val Path = new Markup_String(PATH, NAME)
   123 
   124   val URL = "url"
   125   val Url = new Markup_String(URL, NAME)
   126 
   127 
   128   /* pretty printing */
   129 
   130   val Block = new Markup_Int("block", "indent")
   131   val Break = new Markup_Int("break", "width")
   132 
   133   val ITEM = "item"
   134   val BULLET = "bullet"
   135 
   136   val SEPARATOR = "separator"
   137 
   138 
   139   /* hidden text */
   140 
   141   val HIDDEN = "hidden"
   142 
   143 
   144   /* logical entities */
   145 
   146   val CLASS = "class"
   147   val TYPE_NAME = "type_name"
   148   val FIXED = "fixed"
   149   val CASE = "case"
   150   val CONSTANT = "constant"
   151   val DYNAMIC_FACT = "dynamic_fact"
   152 
   153 
   154   /* inner syntax */
   155 
   156   val TFREE = "tfree"
   157   val TVAR = "tvar"
   158   val FREE = "free"
   159   val SKOLEM = "skolem"
   160   val BOUND = "bound"
   161   val VAR = "var"
   162   val NUMERAL = "numeral"
   163   val LITERAL = "literal"
   164   val DELIMITER = "delimiter"
   165   val INNER_STRING = "inner_string"
   166   val INNER_CARTOUCHE = "inner_cartouche"
   167   val INNER_COMMENT = "inner_comment"
   168 
   169   val TOKEN_RANGE = "token_range"
   170 
   171   val SORTING = "sorting"
   172   val TYPING = "typing"
   173 
   174   val ATTRIBUTE = "attribute"
   175   val METHOD = "method"
   176 
   177 
   178   /* antiquotations */
   179 
   180   val ANTIQUOTED = "antiquoted"
   181   val ANTIQUOTE = "antiquote"
   182 
   183   val ML_ANTIQUOTATION = "ML_antiquotation"
   184   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   185   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   186 
   187 
   188   /* text structure */
   189 
   190   val PARAGRAPH = "paragraph"
   191   val TEXT_FOLD = "text_fold"
   192 
   193 
   194   /* ML syntax */
   195 
   196   val ML_KEYWORD1 = "ML_keyword1"
   197   val ML_KEYWORD2 = "ML_keyword2"
   198   val ML_KEYWORD3 = "ML_keyword3"
   199   val ML_DELIMITER = "ML_delimiter"
   200   val ML_TVAR = "ML_tvar"
   201   val ML_NUMERAL = "ML_numeral"
   202   val ML_CHAR = "ML_char"
   203   val ML_STRING = "ML_string"
   204   val ML_COMMENT = "ML_comment"
   205 
   206   val ML_DEF = "ML_def"
   207   val ML_OPEN = "ML_open"
   208   val ML_STRUCTURE = "ML_structure"
   209   val ML_TYPING = "ML_typing"
   210 
   211 
   212   /* outer syntax */
   213 
   214   val COMMAND = "command"
   215   val KEYWORD1 = "keyword1"
   216   val KEYWORD2 = "keyword2"
   217   val KEYWORD3 = "keyword3"
   218   val QUASI_KEYWORD = "quasi_keyword"
   219   val IMPROPER = "improper"
   220   val OPERATOR = "operator"
   221   val STRING = "string"
   222   val ALTSTRING = "altstring"
   223   val VERBATIM = "verbatim"
   224   val CARTOUCHE = "cartouche"
   225   val COMMENT = "comment"
   226   val CONTROL = "control"
   227 
   228 
   229   /* timing */
   230 
   231   val Elapsed = new Properties.Double("elapsed")
   232   val CPU = new Properties.Double("cpu")
   233   val GC = new Properties.Double("gc")
   234 
   235   object Timing_Properties
   236   {
   237     def apply(timing: isabelle.Timing): Properties.T =
   238       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   239 
   240     def unapply(props: Properties.T): Option[isabelle.Timing] =
   241       (props, props, props) match {
   242         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   243           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   244         case _ => None
   245       }
   246   }
   247 
   248   val TIMING = "timing"
   249 
   250   object Timing
   251   {
   252     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   253 
   254     def unapply(markup: Markup): Option[isabelle.Timing] =
   255       markup match {
   256         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   257         case _ => None
   258       }
   259   }
   260 
   261 
   262   /* command timing */
   263 
   264   val COMMAND_TIMING = "command_timing"
   265 
   266 
   267   /* toplevel */
   268 
   269   val SUBGOALS = "subgoals"
   270   val PROOF_STATE = "proof_state"
   271 
   272   val STATE = "state"
   273   val GOAL = "goal"
   274   val SUBGOAL = "subgoal"
   275 
   276 
   277   /* command status */
   278 
   279   val TASK = "task"
   280 
   281   val ACCEPTED = "accepted"
   282   val FORKED = "forked"
   283   val JOINED = "joined"
   284   val RUNNING = "running"
   285   val FINISHED = "finished"
   286   val FAILED = "failed"
   287 
   288 
   289   /* interactive documents */
   290 
   291   val VERSION = "version"
   292   val ASSIGN = "assign"
   293 
   294 
   295   /* prover process */
   296 
   297   val PROVER_COMMAND = "prover_command"
   298   val PROVER_ARG = "prover_arg"
   299 
   300 
   301   /* messages */
   302 
   303   val SERIAL = "serial"
   304   val Serial = new Properties.Long(SERIAL)
   305 
   306   val MESSAGE = "message"
   307 
   308   val INIT = "init"
   309   val STATUS = "status"
   310   val REPORT = "report"
   311   val RESULT = "result"
   312   val WRITELN = "writeln"
   313   val TRACING = "tracing"
   314   val WARNING = "warning"
   315   val ERROR = "error"
   316   val PROTOCOL = "protocol"
   317   val SYSTEM = "system"
   318   val STDOUT = "stdout"
   319   val STDERR = "stderr"
   320   val EXIT = "exit"
   321 
   322   val WRITELN_MESSAGE = "writeln_message"
   323   val TRACING_MESSAGE = "tracing_message"
   324   val WARNING_MESSAGE = "warning_message"
   325   val ERROR_MESSAGE = "error_message"
   326 
   327   val messages =
   328     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   329         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   330   val message: String => String = messages.withDefault((s: String) => s)
   331 
   332   val Return_Code = new Properties.Int("return_code")
   333 
   334   val LEGACY = "legacy"
   335 
   336   val NO_REPORT = "no_report"
   337 
   338   val BAD = "bad"
   339 
   340   val INTENSIFY = "intensify"
   341   val INFORMATION = "information"
   342 
   343 
   344   /* active areas */
   345 
   346   val BROWSER = "browser"
   347   val GRAPHVIEW = "graphview"
   348 
   349   val SENDBACK = "sendback"
   350   val PADDING = "padding"
   351   val PADDING_LINE = (PADDING, "line")
   352   val PADDING_COMMAND = (PADDING, "command")
   353 
   354   val DIALOG = "dialog"
   355   val Result = new Properties.String(RESULT)
   356 
   357 
   358   /* protocol message functions */
   359 
   360   val FUNCTION = "function"
   361   val Function = new Properties.String(FUNCTION)
   362 
   363   val Flush: Properties.T = List((FUNCTION, "flush"))
   364 
   365   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   366   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   367 
   368   object Protocol_Handler
   369   {
   370     def unapply(props: Properties.T): Option[(String)] =
   371       props match {
   372         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   373         case _ => None
   374       }
   375   }
   376 
   377   val INVOKE_SCALA = "invoke_scala"
   378   object Invoke_Scala
   379   {
   380     def unapply(props: Properties.T): Option[(String, String)] =
   381       props match {
   382         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   383         case _ => None
   384       }
   385   }
   386 
   387   val CANCEL_SCALA = "cancel_scala"
   388   object Cancel_Scala
   389   {
   390     def unapply(props: Properties.T): Option[String] =
   391       props match {
   392         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   393         case _ => None
   394       }
   395   }
   396 
   397   val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
   398   val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
   399 
   400   object ML_Statistics
   401   {
   402     def unapply(props: Properties.T): Option[Properties.T] =
   403       props match {
   404         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   405         case _ => None
   406       }
   407   }
   408 
   409   object Task_Statistics
   410   {
   411     def unapply(props: Properties.T): Option[Properties.T] =
   412       props match {
   413         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   414         case _ => None
   415       }
   416   }
   417 
   418 
   419   /* simplifier trace */
   420 
   421   val SIMP_TRACE = "simp_trace"
   422 
   423   val SIMP_TRACE_LOG = "simp_trace_log"
   424   val SIMP_TRACE_STEP = "simp_trace_step"
   425   val SIMP_TRACE_RECURSE = "simp_trace_recurse"
   426   val SIMP_TRACE_HINT = "simp_trace_hint"
   427   val SIMP_TRACE_IGNORE = "simp_trace_ignore"
   428 
   429   val SIMP_TRACE_CANCEL = "simp_trace_cancel"
   430   object Simp_Trace_Cancel
   431   {
   432     def unapply(props: Properties.T): Option[Long] =
   433       props match {
   434         case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
   435         case _ => None
   436       }
   437   }
   438 }
   439 
   440 
   441 sealed case class Markup(name: String, properties: Properties.T)
   442