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