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