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