src/Pure/PIDE/markup.scala
author Lars Hupel <lars.hupel@mytum.de>
Tue Feb 04 09:04:59 2014 +0000 (2014-02-04 ago)
changeset 55316 885500f4aa6a
parent 55033 8e8243975860
child 55390 36550a4eac5e
permissions -rw-r--r--
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
     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_KEYWORD = "ML_keyword"
   173   val ML_DELIMITER = "ML_delimiter"
   174   val ML_TVAR = "ML_tvar"
   175   val ML_NUMERAL = "ML_numeral"
   176   val ML_CHAR = "ML_char"
   177   val ML_STRING = "ML_string"
   178   val ML_COMMENT = "ML_comment"
   179 
   180   val ML_DEF = "ML_def"
   181   val ML_OPEN = "ML_open"
   182   val ML_STRUCT = "ML_struct"
   183   val ML_TYPING = "ML_typing"
   184 
   185 
   186   /* outer syntax */
   187 
   188   val KEYWORD = "keyword"
   189   val OPERATOR = "operator"
   190   val COMMAND = "command"
   191   val STRING = "string"
   192   val ALTSTRING = "altstring"
   193   val VERBATIM = "verbatim"
   194   val CARTOUCHE = "cartouche"
   195   val COMMENT = "comment"
   196   val CONTROL = "control"
   197 
   198   val KEYWORD1 = "keyword1"
   199   val KEYWORD2 = "keyword2"
   200 
   201 
   202   /* timing */
   203 
   204   val Elapsed = new Properties.Double("elapsed")
   205   val CPU = new Properties.Double("cpu")
   206   val GC = new Properties.Double("gc")
   207 
   208   object Timing_Properties
   209   {
   210     def apply(timing: isabelle.Timing): Properties.T =
   211       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   212 
   213     def unapply(props: Properties.T): Option[isabelle.Timing] =
   214       (props, props, props) match {
   215         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   216           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   217         case _ => None
   218       }
   219   }
   220 
   221   val TIMING = "timing"
   222 
   223   object Timing
   224   {
   225     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   226 
   227     def unapply(markup: Markup): Option[isabelle.Timing] =
   228       markup match {
   229         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   230         case _ => None
   231       }
   232   }
   233 
   234 
   235   /* command timing */
   236 
   237   val COMMAND_TIMING = "command_timing"
   238 
   239 
   240   /* toplevel */
   241 
   242   val SUBGOALS = "subgoals"
   243   val PROOF_STATE = "proof_state"
   244 
   245   val STATE = "state"
   246   val GOAL = "goal"
   247   val SUBGOAL = "subgoal"
   248 
   249 
   250   /* command status */
   251 
   252   val TASK = "task"
   253 
   254   val ACCEPTED = "accepted"
   255   val FORKED = "forked"
   256   val JOINED = "joined"
   257   val RUNNING = "running"
   258   val FINISHED = "finished"
   259   val FAILED = "failed"
   260 
   261 
   262   /* interactive documents */
   263 
   264   val VERSION = "version"
   265   val ASSIGN = "assign"
   266 
   267 
   268   /* prover process */
   269 
   270   val PROVER_COMMAND = "prover_command"
   271   val PROVER_ARG = "prover_arg"
   272 
   273 
   274   /* messages */
   275 
   276   val SERIAL = "serial"
   277   val Serial = new Properties.Long(SERIAL)
   278 
   279   val MESSAGE = "message"
   280 
   281   val INIT = "init"
   282   val STATUS = "status"
   283   val REPORT = "report"
   284   val RESULT = "result"
   285   val WRITELN = "writeln"
   286   val TRACING = "tracing"
   287   val WARNING = "warning"
   288   val ERROR = "error"
   289   val PROTOCOL = "protocol"
   290   val SYSTEM = "system"
   291   val STDOUT = "stdout"
   292   val STDERR = "stderr"
   293   val EXIT = "exit"
   294 
   295   val WRITELN_MESSAGE = "writeln_message"
   296   val TRACING_MESSAGE = "tracing_message"
   297   val WARNING_MESSAGE = "warning_message"
   298   val ERROR_MESSAGE = "error_message"
   299 
   300   val messages =
   301     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   302         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   303   val message: String => String = messages.withDefault((s: String) => s)
   304 
   305   val Return_Code = new Properties.Int("return_code")
   306 
   307   val LEGACY = "legacy"
   308 
   309   val NO_REPORT = "no_report"
   310 
   311   val BAD = "bad"
   312 
   313   val INTENSIFY = "intensify"
   314   val INFORMATION = "information"
   315 
   316 
   317   /* active areas */
   318 
   319   val BROWSER = "browser"
   320   val GRAPHVIEW = "graphview"
   321 
   322   val SENDBACK = "sendback"
   323   val PADDING = "padding"
   324   val PADDING_LINE = (PADDING, "line")
   325   val PADDING_COMMAND = (PADDING, "command")
   326 
   327   val DIALOG = "dialog"
   328   val Result = new Properties.String(RESULT)
   329 
   330 
   331   /* protocol message functions */
   332 
   333   val FUNCTION = "function"
   334   val Function = new Properties.String(FUNCTION)
   335 
   336   val Flush: Properties.T = List((FUNCTION, "flush"))
   337 
   338   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   339   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   340 
   341   object Protocol_Handler
   342   {
   343     def unapply(props: Properties.T): Option[(String)] =
   344       props match {
   345         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   346         case _ => None
   347       }
   348   }
   349 
   350   val INVOKE_SCALA = "invoke_scala"
   351   object Invoke_Scala
   352   {
   353     def unapply(props: Properties.T): Option[(String, String)] =
   354       props match {
   355         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   356         case _ => None
   357       }
   358   }
   359 
   360   val CANCEL_SCALA = "cancel_scala"
   361   object Cancel_Scala
   362   {
   363     def unapply(props: Properties.T): Option[String] =
   364       props match {
   365         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   366         case _ => None
   367       }
   368   }
   369 
   370   val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
   371   val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
   372 
   373   object ML_Statistics
   374   {
   375     def unapply(props: Properties.T): Option[Properties.T] =
   376       props match {
   377         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   378         case _ => None
   379       }
   380   }
   381 
   382   object Task_Statistics
   383   {
   384     def unapply(props: Properties.T): Option[Properties.T] =
   385       props match {
   386         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   387         case _ => None
   388       }
   389   }
   390 
   391   /* simplifier trace */
   392 
   393   val TEXT = "text"
   394   val Text = new Properties.String(TEXT)
   395 
   396   val PARENT = "parent"
   397   val Parent = new Properties.Long(PARENT)
   398 
   399   val SUCCESS = "success"
   400   val Success = new Properties.Boolean(SUCCESS)
   401 
   402   val CANCEL_SIMP_TRACE = "simp_trace_cancel"
   403   object Cancel_Simp_Trace
   404   {
   405     def unapply(props: Properties.T): Option[Long] =
   406       props match {
   407         case (FUNCTION, CANCEL_SIMP_TRACE) :: Serial(id) => Some(id)
   408         case _ => None
   409       }
   410   }
   411 
   412   val SIMP_TRACE = "simp_trace"
   413   object Simp_Trace
   414   {
   415     def unapply(tree: XML.Tree): Option[(Long, Simplifier_Trace.Answer)] =
   416       tree match {
   417         case XML.Elem(Markup(SIMP_TRACE, props), _) =>
   418           (props, props) match {
   419             case (Serial(serial), Name(name)) =>
   420               Simplifier_Trace.all_answers.find(_.name == name).map((serial, _))
   421             case _ =>
   422               None
   423           }
   424         case _ =>
   425           None
   426       }
   427   }
   428 
   429   /* trace items from the prover */
   430 
   431   object Simp_Trace_Item
   432   {
   433 
   434     def unapply(tree: XML.Tree): Option[(String, Data)] =
   435       tree match {
   436         case XML.Elem(Markup(RESULT, Serial(serial)), List(
   437           XML.Elem(Markup(markup, props), content)
   438         )) if markup.startsWith("simp_trace_") =>
   439           (props, props) match {
   440             case (Text(text), Parent(parent)) =>
   441               Some((markup, Data(serial, markup, text, parent, props, content)))
   442             case _ =>
   443               None
   444           }
   445         case _ =>
   446           None
   447       }
   448 
   449     val LOG = "simp_trace_log"
   450     val STEP = "simp_trace_step"
   451     val RECURSE = "simp_trace_recurse"
   452     val HINT = "simp_trace_hint"
   453     val IGNORE = "simp_trace_ignore"
   454 
   455     case class Data(serial: Long, markup: String, text: String,
   456                     parent: Long, props: Properties.T, content: XML.Body)
   457 
   458   }
   459 
   460 }
   461 
   462 
   463 sealed case class Markup(name: String, properties: Properties.T)
   464