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