src/Pure/PIDE/markup.scala
author wenzelm
Sat Feb 15 18:28:18 2014 +0100 (2014-02-15 ago)
changeset 55505 2a1ca7f6607b
parent 55390 36550a4eac5e
child 55526 39708e59f4b0
permissions -rw-r--r--
more uniform ML keyword markup;
tuned;
     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 
    31   /* formal entities */
    32 
    33   val BINDING = "binding"
    34   val ENTITY = "entity"
    35   val DEF = "def"
    36   val REF = "ref"
    37 
    38   object Entity
    39   {
    40     def unapply(markup: Markup): Option[(String, String)] =
    41       markup match {
    42         case Markup(ENTITY, props @ Kind(kind)) =>
    43           props match {
    44             case Name(name) => Some(kind, name)
    45             case _ => None
    46           }
    47         case _ => None
    48       }
    49   }
    50 
    51 
    52   /* position */
    53 
    54   val LINE = "line"
    55   val OFFSET = "offset"
    56   val END_OFFSET = "end_offset"
    57   val FILE = "file"
    58   val ID = "id"
    59 
    60   val DEF_LINE = "def_line"
    61   val DEF_OFFSET = "def_offset"
    62   val DEF_END_OFFSET = "def_end_offset"
    63   val DEF_FILE = "def_file"
    64   val DEF_ID = "def_id"
    65 
    66   val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
    67   val POSITION = "position"
    68 
    69 
    70   /* external resources */
    71 
    72   val PATH = "path"
    73 
    74   object Path
    75   {
    76     def unapply(markup: Markup): Option[String] =
    77       markup match {
    78         case Markup(PATH, Name(name)) => Some(name)
    79         case _ => None
    80       }
    81   }
    82 
    83   val URL = "url"
    84 
    85   object Url
    86   {
    87     def unapply(markup: Markup): Option[String] =
    88       markup match {
    89         case Markup(URL, Name(name)) => Some(name)
    90         case _ => None
    91       }
    92   }
    93 
    94 
    95   /* pretty printing */
    96 
    97   val Indent = new Properties.Int("indent")
    98   val BLOCK = "block"
    99 
   100   val Width = new Properties.Int("width")
   101   val BREAK = "break"
   102 
   103   val ITEM = "item"
   104   val BULLET = "bullet"
   105 
   106   val SEPARATOR = "separator"
   107 
   108 
   109   /* hidden text */
   110 
   111   val HIDDEN = "hidden"
   112 
   113 
   114   /* logical entities */
   115 
   116   val CLASS = "class"
   117   val TYPE_NAME = "type_name"
   118   val FIXED = "fixed"
   119   val CASE = "case"
   120   val CONSTANT = "constant"
   121   val DYNAMIC_FACT = "dynamic_fact"
   122 
   123 
   124   /* inner syntax */
   125 
   126   val TFREE = "tfree"
   127   val TVAR = "tvar"
   128   val FREE = "free"
   129   val SKOLEM = "skolem"
   130   val BOUND = "bound"
   131   val VAR = "var"
   132   val NUMERAL = "numeral"
   133   val LITERAL = "literal"
   134   val DELIMITER = "delimiter"
   135   val INNER_STRING = "inner_string"
   136   val INNER_CARTOUCHE = "inner_cartouche"
   137   val INNER_COMMENT = "inner_comment"
   138 
   139   val TOKEN_RANGE = "token_range"
   140 
   141   val SORT = "sort"
   142   val TYP = "typ"
   143   val TERM = "term"
   144   val PROP = "prop"
   145 
   146   val SORTING = "sorting"
   147   val TYPING = "typing"
   148 
   149   val ATTRIBUTE = "attribute"
   150   val METHOD = "method"
   151 
   152 
   153   /* embedded source text */
   154 
   155   val ML_SOURCE = "ML_source"
   156   val DOCUMENT_SOURCE = "document_source"
   157 
   158   val ANTIQ = "antiq"
   159   val ML_ANTIQUOTATION = "ML_antiquotation"
   160   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   161   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   162 
   163 
   164   /* text structure */
   165 
   166   val PARAGRAPH = "paragraph"
   167   val TEXT_FOLD = "text_fold"
   168 
   169 
   170   /* ML syntax */
   171 
   172   val ML_KEYWORD1 = "ML_keyword1"
   173   val ML_KEYWORD2 = "ML_keyword2"
   174   val ML_KEYWORD3 = "ML_keyword3"
   175   val ML_DELIMITER = "ML_delimiter"
   176   val ML_TVAR = "ML_tvar"
   177   val ML_NUMERAL = "ML_numeral"
   178   val ML_CHAR = "ML_char"
   179   val ML_STRING = "ML_string"
   180   val ML_COMMENT = "ML_comment"
   181 
   182   val ML_DEF = "ML_def"
   183   val ML_OPEN = "ML_open"
   184   val ML_STRUCT = "ML_struct"
   185   val ML_TYPING = "ML_typing"
   186 
   187 
   188   /* outer syntax */
   189 
   190   val KEYWORD = "keyword"
   191   val OPERATOR = "operator"
   192   val COMMAND = "command"
   193   val STRING = "string"
   194   val ALTSTRING = "altstring"
   195   val VERBATIM = "verbatim"
   196   val CARTOUCHE = "cartouche"
   197   val COMMENT = "comment"
   198   val CONTROL = "control"
   199 
   200   val KEYWORD1 = "keyword1"
   201   val KEYWORD2 = "keyword2"
   202 
   203 
   204   /* timing */
   205 
   206   val Elapsed = new Properties.Double("elapsed")
   207   val CPU = new Properties.Double("cpu")
   208   val GC = new Properties.Double("gc")
   209 
   210   object Timing_Properties
   211   {
   212     def apply(timing: isabelle.Timing): Properties.T =
   213       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   214 
   215     def unapply(props: Properties.T): Option[isabelle.Timing] =
   216       (props, props, props) match {
   217         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   218           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   219         case _ => None
   220       }
   221   }
   222 
   223   val TIMING = "timing"
   224 
   225   object Timing
   226   {
   227     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   228 
   229     def unapply(markup: Markup): Option[isabelle.Timing] =
   230       markup match {
   231         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   232         case _ => None
   233       }
   234   }
   235 
   236 
   237   /* command timing */
   238 
   239   val COMMAND_TIMING = "command_timing"
   240 
   241 
   242   /* toplevel */
   243 
   244   val SUBGOALS = "subgoals"
   245   val PROOF_STATE = "proof_state"
   246 
   247   val STATE = "state"
   248   val GOAL = "goal"
   249   val SUBGOAL = "subgoal"
   250 
   251 
   252   /* command status */
   253 
   254   val TASK = "task"
   255 
   256   val ACCEPTED = "accepted"
   257   val FORKED = "forked"
   258   val JOINED = "joined"
   259   val RUNNING = "running"
   260   val FINISHED = "finished"
   261   val FAILED = "failed"
   262 
   263 
   264   /* interactive documents */
   265 
   266   val VERSION = "version"
   267   val ASSIGN = "assign"
   268 
   269 
   270   /* prover process */
   271 
   272   val PROVER_COMMAND = "prover_command"
   273   val PROVER_ARG = "prover_arg"
   274 
   275 
   276   /* messages */
   277 
   278   val SERIAL = "serial"
   279   val Serial = new Properties.Long(SERIAL)
   280 
   281   val MESSAGE = "message"
   282 
   283   val INIT = "init"
   284   val STATUS = "status"
   285   val REPORT = "report"
   286   val RESULT = "result"
   287   val WRITELN = "writeln"
   288   val TRACING = "tracing"
   289   val WARNING = "warning"
   290   val ERROR = "error"
   291   val PROTOCOL = "protocol"
   292   val SYSTEM = "system"
   293   val STDOUT = "stdout"
   294   val STDERR = "stderr"
   295   val EXIT = "exit"
   296 
   297   val WRITELN_MESSAGE = "writeln_message"
   298   val TRACING_MESSAGE = "tracing_message"
   299   val WARNING_MESSAGE = "warning_message"
   300   val ERROR_MESSAGE = "error_message"
   301 
   302   val messages =
   303     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   304         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   305   val message: String => String = messages.withDefault((s: String) => s)
   306 
   307   val Return_Code = new Properties.Int("return_code")
   308 
   309   val LEGACY = "legacy"
   310 
   311   val NO_REPORT = "no_report"
   312 
   313   val BAD = "bad"
   314 
   315   val INTENSIFY = "intensify"
   316   val INFORMATION = "information"
   317 
   318 
   319   /* active areas */
   320 
   321   val BROWSER = "browser"
   322   val GRAPHVIEW = "graphview"
   323 
   324   val SENDBACK = "sendback"
   325   val PADDING = "padding"
   326   val PADDING_LINE = (PADDING, "line")
   327   val PADDING_COMMAND = (PADDING, "command")
   328 
   329   val DIALOG = "dialog"
   330   val Result = new Properties.String(RESULT)
   331 
   332 
   333   /* protocol message functions */
   334 
   335   val FUNCTION = "function"
   336   val Function = new Properties.String(FUNCTION)
   337 
   338   val Flush: Properties.T = List((FUNCTION, "flush"))
   339 
   340   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   341   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   342 
   343   object Protocol_Handler
   344   {
   345     def unapply(props: Properties.T): Option[(String)] =
   346       props match {
   347         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   348         case _ => None
   349       }
   350   }
   351 
   352   val INVOKE_SCALA = "invoke_scala"
   353   object Invoke_Scala
   354   {
   355     def unapply(props: Properties.T): Option[(String, String)] =
   356       props match {
   357         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   358         case _ => None
   359       }
   360   }
   361 
   362   val CANCEL_SCALA = "cancel_scala"
   363   object Cancel_Scala
   364   {
   365     def unapply(props: Properties.T): Option[String] =
   366       props match {
   367         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   368         case _ => None
   369       }
   370   }
   371 
   372   val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
   373   val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
   374 
   375   object ML_Statistics
   376   {
   377     def unapply(props: Properties.T): Option[Properties.T] =
   378       props match {
   379         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   380         case _ => None
   381       }
   382   }
   383 
   384   object Task_Statistics
   385   {
   386     def unapply(props: Properties.T): Option[Properties.T] =
   387       props match {
   388         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   389         case _ => None
   390       }
   391   }
   392 
   393   /* simplifier trace */
   394 
   395   val TEXT = "text"
   396   val Text = new Properties.String(TEXT)
   397 
   398   val PARENT = "parent"
   399   val Parent = new Properties.Long(PARENT)
   400 
   401   val SUCCESS = "success"
   402   val Success = new Properties.Boolean(SUCCESS)
   403 
   404   val MEMORY = "memory"
   405   val Memory = new Properties.Boolean(MEMORY)
   406 
   407   val CANCEL_SIMP_TRACE = "simp_trace_cancel"
   408   object Cancel_Simp_Trace
   409   {
   410     def unapply(props: Properties.T): Option[Long] =
   411       props match {
   412         case (FUNCTION, CANCEL_SIMP_TRACE) :: Serial(id) => Some(id)
   413         case _ => None
   414       }
   415   }
   416 
   417   val SIMP_TRACE = "simp_trace"
   418   object Simp_Trace
   419   {
   420     def unapply(tree: XML.Tree): Option[(Long, Simplifier_Trace.Answer)] =
   421       tree match {
   422         case XML.Elem(Markup(SIMP_TRACE, props), _) =>
   423           (props, props) match {
   424             case (Serial(serial), Name(name)) =>
   425               Simplifier_Trace.all_answers.find(_.name == name).map((serial, _))
   426             case _ =>
   427               None
   428           }
   429         case _ =>
   430           None
   431       }
   432   }
   433 
   434   /* trace items from the prover */
   435 
   436   object Simp_Trace_Item
   437   {
   438 
   439     def unapply(tree: XML.Tree): Option[(String, Data)] =
   440       tree match {
   441         case XML.Elem(Markup(RESULT, Serial(serial)), List(
   442           XML.Elem(Markup(markup, props), content)
   443         )) if markup.startsWith("simp_trace_") =>
   444           (props, props) match {
   445             case (Text(text), Parent(parent)) =>
   446               Some((markup, Data(serial, markup, text, parent, props, content)))
   447             case _ =>
   448               None
   449           }
   450         case _ =>
   451           None
   452       }
   453 
   454     val LOG = "simp_trace_log"
   455     val STEP = "simp_trace_step"
   456     val RECURSE = "simp_trace_recurse"
   457     val HINT = "simp_trace_hint"
   458     val IGNORE = "simp_trace_ignore"
   459 
   460     case class Data(serial: Long, markup: String, text: String,
   461                     parent: Long, props: Properties.T, content: XML.Body)
   462     {
   463       def memory: Boolean =
   464         Memory.unapply(props) getOrElse true
   465     }
   466 
   467   }
   468 
   469 }
   470 
   471 
   472 sealed case class Markup(name: String, properties: Properties.T)
   473