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