src/Pure/PIDE/markup.scala
author wenzelm
Sun Oct 05 16:05:17 2014 +0200 (2014-10-05 ago)
changeset 58544 340f130b3d38
parent 58464 5e7fc9974aba
child 58545 30b75b7958d6
permissions -rw-r--r--
bibtex support in ML: document antiquotation @{cite} with 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   /* citation */
   124 
   125   val CITATION = "citation"
   126 
   127 
   128   /* embedded languages */
   129 
   130   val Symbols = new Properties.Boolean("symbols")
   131   val Antiquotes = new Properties.Boolean("antiquotes")
   132   val Delimited = new Properties.Boolean("delimited")
   133 
   134   val LANGUAGE = "language"
   135   object Language
   136   {
   137     val ML = "ML"
   138     val SML = "SML"
   139     val PATH = "path"
   140     val UNKNOWN = "unknown"
   141 
   142     def unapply(markup: Markup): Option[(String, Boolean, Boolean, Boolean)] =
   143       markup match {
   144         case Markup(LANGUAGE, props) =>
   145           (props, props, props, props) match {
   146             case (Name(name), Symbols(symbols), Antiquotes(antiquotes), Delimited(delimited)) =>
   147               Some((name, symbols, antiquotes, delimited))
   148             case _ => None
   149           }
   150         case _ => None
   151       }
   152   }
   153 
   154 
   155   /* external resources */
   156 
   157   val PATH = "path"
   158   val Path = new Markup_String(PATH, NAME)
   159 
   160   val URL = "url"
   161   val Url = new Markup_String(URL, NAME)
   162 
   163 
   164   /* pretty printing */
   165 
   166   val Block = new Markup_Int("block", "indent")
   167   val Break = new Markup_Int("break", "width")
   168 
   169   val ITEM = "item"
   170   val BULLET = "bullet"
   171 
   172   val SEPARATOR = "separator"
   173 
   174 
   175   /* text properties */
   176 
   177   val WORDS = "words"
   178 
   179   val HIDDEN = "hidden"
   180 
   181 
   182   /* misc entities */
   183 
   184   val CLASS = "class"
   185   val TYPE_NAME = "type_name"
   186   val FIXED = "fixed"
   187   val CASE = "case"
   188   val CONSTANT = "constant"
   189   val DYNAMIC_FACT = "dynamic_fact"
   190 
   191 
   192   /* inner syntax */
   193 
   194   val TFREE = "tfree"
   195   val TVAR = "tvar"
   196   val FREE = "free"
   197   val SKOLEM = "skolem"
   198   val BOUND = "bound"
   199   val VAR = "var"
   200   val NUMERAL = "numeral"
   201   val LITERAL = "literal"
   202   val DELIMITER = "delimiter"
   203   val INNER_STRING = "inner_string"
   204   val INNER_CARTOUCHE = "inner_cartouche"
   205   val INNER_COMMENT = "inner_comment"
   206 
   207   val TOKEN_RANGE = "token_range"
   208 
   209   val SORTING = "sorting"
   210   val TYPING = "typing"
   211 
   212   val ATTRIBUTE = "attribute"
   213   val METHOD = "method"
   214 
   215 
   216   /* antiquotations */
   217 
   218   val ANTIQUOTED = "antiquoted"
   219   val ANTIQUOTE = "antiquote"
   220 
   221   val ML_ANTIQUOTATION = "ML_antiquotation"
   222   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   223   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   224 
   225 
   226   /* text structure */
   227 
   228   val PARAGRAPH = "paragraph"
   229   val TEXT_FOLD = "text_fold"
   230 
   231 
   232   /* ML syntax */
   233 
   234   val ML_KEYWORD1 = "ML_keyword1"
   235   val ML_KEYWORD2 = "ML_keyword2"
   236   val ML_KEYWORD3 = "ML_keyword3"
   237   val ML_DELIMITER = "ML_delimiter"
   238   val ML_TVAR = "ML_tvar"
   239   val ML_NUMERAL = "ML_numeral"
   240   val ML_CHAR = "ML_char"
   241   val ML_STRING = "ML_string"
   242   val ML_COMMENT = "ML_comment"
   243   val SML_STRING = "SML_string"
   244   val SML_COMMENT = "SML_comment"
   245 
   246   val ML_DEF = "ML_def"
   247   val ML_OPEN = "ML_open"
   248   val ML_STRUCTURE = "ML_structure"
   249   val ML_TYPING = "ML_typing"
   250 
   251 
   252   /* outer syntax */
   253 
   254   val COMMAND = "command"
   255   val KEYWORD1 = "keyword1"
   256   val KEYWORD2 = "keyword2"
   257   val KEYWORD3 = "keyword3"
   258   val QUASI_KEYWORD = "quasi_keyword"
   259   val IMPROPER = "improper"
   260   val OPERATOR = "operator"
   261   val STRING = "string"
   262   val ALTSTRING = "altstring"
   263   val VERBATIM = "verbatim"
   264   val CARTOUCHE = "cartouche"
   265   val COMMENT = "comment"
   266   val CONTROL = "control"
   267 
   268 
   269   /* timing */
   270 
   271   val Elapsed = new Properties.Double("elapsed")
   272   val CPU = new Properties.Double("cpu")
   273   val GC = new Properties.Double("gc")
   274 
   275   object Timing_Properties
   276   {
   277     def apply(timing: isabelle.Timing): Properties.T =
   278       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   279 
   280     def unapply(props: Properties.T): Option[isabelle.Timing] =
   281       (props, props, props) match {
   282         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   283           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   284         case _ => None
   285       }
   286   }
   287 
   288   val TIMING = "timing"
   289 
   290   object Timing
   291   {
   292     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   293 
   294     def unapply(markup: Markup): Option[isabelle.Timing] =
   295       markup match {
   296         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   297         case _ => None
   298       }
   299   }
   300 
   301 
   302   /* command timing */
   303 
   304   val COMMAND_TIMING = "command_timing"
   305 
   306 
   307   /* toplevel */
   308 
   309   val SUBGOALS = "subgoals"
   310   val PROOF_STATE = "proof_state"
   311 
   312   val STATE = "state"
   313   val GOAL = "goal"
   314   val SUBGOAL = "subgoal"
   315 
   316 
   317   /* command status */
   318 
   319   val TASK = "task"
   320 
   321   val ACCEPTED = "accepted"
   322   val FORKED = "forked"
   323   val JOINED = "joined"
   324   val RUNNING = "running"
   325   val FINISHED = "finished"
   326   val FAILED = "failed"
   327 
   328 
   329   /* interactive documents */
   330 
   331   val VERSION = "version"
   332   val ASSIGN = "assign"
   333 
   334 
   335   /* prover process */
   336 
   337   val PROVER_COMMAND = "prover_command"
   338   val PROVER_ARG = "prover_arg"
   339 
   340 
   341   /* messages */
   342 
   343   val SERIAL = "serial"
   344   val Serial = new Properties.Long(SERIAL)
   345 
   346   val MESSAGE = "message"
   347 
   348   val INIT = "init"
   349   val STATUS = "status"
   350   val REPORT = "report"
   351   val RESULT = "result"
   352   val WRITELN = "writeln"
   353   val TRACING = "tracing"
   354   val WARNING = "warning"
   355   val ERROR = "error"
   356   val PROTOCOL = "protocol"
   357   val SYSTEM = "system"
   358   val STDOUT = "stdout"
   359   val STDERR = "stderr"
   360   val EXIT = "exit"
   361 
   362   val WRITELN_MESSAGE = "writeln_message"
   363   val TRACING_MESSAGE = "tracing_message"
   364   val WARNING_MESSAGE = "warning_message"
   365   val ERROR_MESSAGE = "error_message"
   366 
   367   val messages =
   368     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   369         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   370   val message: String => String = messages.withDefault((s: String) => s)
   371 
   372   val Return_Code = new Properties.Int("return_code")
   373 
   374   val LEGACY = "legacy"
   375 
   376   val NO_REPORT = "no_report"
   377 
   378   val BAD = "bad"
   379 
   380   val INTENSIFY = "intensify"
   381   val INFORMATION = "information"
   382 
   383 
   384   /* active areas */
   385 
   386   val BROWSER = "browser"
   387   val GRAPHVIEW = "graphview"
   388 
   389   val SENDBACK = "sendback"
   390   val PADDING = "padding"
   391   val PADDING_LINE = (PADDING, "line")
   392   val PADDING_COMMAND = (PADDING, "command")
   393 
   394   val DIALOG = "dialog"
   395   val Result = new Properties.String(RESULT)
   396 
   397 
   398   /* protocol message functions */
   399 
   400   val FUNCTION = "function"
   401   val Function = new Properties.String(FUNCTION)
   402 
   403   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   404   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   405 
   406   object Protocol_Handler
   407   {
   408     def unapply(props: Properties.T): Option[(String)] =
   409       props match {
   410         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   411         case _ => None
   412       }
   413   }
   414 
   415   val INVOKE_SCALA = "invoke_scala"
   416   object Invoke_Scala
   417   {
   418     def unapply(props: Properties.T): Option[(String, String)] =
   419       props match {
   420         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   421         case _ => None
   422       }
   423   }
   424 
   425   val CANCEL_SCALA = "cancel_scala"
   426   object Cancel_Scala
   427   {
   428     def unapply(props: Properties.T): Option[String] =
   429       props match {
   430         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   431         case _ => None
   432       }
   433   }
   434 
   435   object ML_Statistics
   436   {
   437     def unapply(props: Properties.T): Option[Properties.T] =
   438       props match {
   439         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   440         case _ => None
   441       }
   442   }
   443 
   444   object Task_Statistics
   445   {
   446     def unapply(props: Properties.T): Option[Properties.T] =
   447       props match {
   448         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   449         case _ => None
   450       }
   451   }
   452 
   453   object Loading_Theory
   454   {
   455     def unapply(props: Properties.T): Option[String] =
   456       props match {
   457         case List((FUNCTION, "loading_theory"), (NAME, name)) => Some(name)
   458         case _ => None
   459       }
   460   }
   461 
   462   object Use_Theories_Result
   463   {
   464     def unapply(props: Properties.T): Option[(String, Boolean)] =
   465       props match {
   466         case List((FUNCTION, "use_theories_result"),
   467           ("id", id), ("ok", Properties.Value.Boolean(ok))) => Some((id, ok))
   468         case _ => None
   469       }
   470   }
   471 
   472   val PRINT_OPERATIONS = "print_operations"
   473 
   474 
   475   /* simplifier trace */
   476 
   477   val SIMP_TRACE_PANEL = "simp_trace_panel"
   478 
   479   val SIMP_TRACE_LOG = "simp_trace_log"
   480   val SIMP_TRACE_STEP = "simp_trace_step"
   481   val SIMP_TRACE_RECURSE = "simp_trace_recurse"
   482   val SIMP_TRACE_HINT = "simp_trace_hint"
   483   val SIMP_TRACE_IGNORE = "simp_trace_ignore"
   484 
   485   val SIMP_TRACE_CANCEL = "simp_trace_cancel"
   486   object Simp_Trace_Cancel
   487   {
   488     def unapply(props: Properties.T): Option[Long] =
   489       props match {
   490         case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
   491         case _ => None
   492       }
   493   }
   494 }
   495 
   496 
   497 sealed case class Markup(name: String, properties: Properties.T)
   498