src/Pure/PIDE/markup.scala
author wenzelm
Wed Dec 03 14:04:38 2014 +0100 (2014-12-03 ago)
changeset 59083 88b0b1f28adc
parent 59081 2ceb05ee0331
child 59112 e670969f34df
permissions -rw-r--r--
tuned signature;
     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_COMMENT = "ML_comment"
   245   val SML_STRING = "SML_string"
   246   val SML_COMMENT = "SML_comment"
   247 
   248   val ML_DEF = "ML_def"
   249   val ML_OPEN = "ML_open"
   250   val ML_STRUCTURE = "ML_structure"
   251   val ML_TYPING = "ML_typing"
   252 
   253 
   254   /* outer syntax */
   255 
   256   val COMMAND = "command"
   257   val KEYWORD1 = "keyword1"
   258   val KEYWORD2 = "keyword2"
   259   val KEYWORD3 = "keyword3"
   260   val QUASI_KEYWORD = "quasi_keyword"
   261   val IMPROPER = "improper"
   262   val OPERATOR = "operator"
   263   val STRING = "string"
   264   val ALT_STRING = "alt_string"
   265   val VERBATIM = "verbatim"
   266   val CARTOUCHE = "cartouche"
   267   val COMMENT = "comment"
   268 
   269 
   270   /* timing */
   271 
   272   val Elapsed = new Properties.Double("elapsed")
   273   val CPU = new Properties.Double("cpu")
   274   val GC = new Properties.Double("gc")
   275 
   276   object Timing_Properties
   277   {
   278     def apply(timing: isabelle.Timing): Properties.T =
   279       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   280 
   281     def unapply(props: Properties.T): Option[isabelle.Timing] =
   282       (props, props, props) match {
   283         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   284           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   285         case _ => None
   286       }
   287   }
   288 
   289   val TIMING = "timing"
   290 
   291   object Timing
   292   {
   293     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   294 
   295     def unapply(markup: Markup): Option[isabelle.Timing] =
   296       markup match {
   297         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   298         case _ => None
   299       }
   300   }
   301 
   302 
   303   /* command timing */
   304 
   305   val COMMAND_TIMING = "command_timing"
   306 
   307 
   308   /* toplevel */
   309 
   310   val SUBGOALS = "subgoals"
   311   val PROOF_STATE = "proof_state"
   312 
   313   val STATE = "state"
   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 MESSAGE = "message"
   348 
   349   val INIT = "init"
   350   val STATUS = "status"
   351   val REPORT = "report"
   352   val RESULT = "result"
   353   val WRITELN = "writeln"
   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 TRACING_MESSAGE = "tracing_message"
   365   val WARNING_MESSAGE = "warning_message"
   366   val ERROR_MESSAGE = "error_message"
   367 
   368   val messages =
   369     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   370         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   371   val message: String => String = messages.withDefault((s: String) => s)
   372 
   373   val Return_Code = new Properties.Int("return_code")
   374 
   375   val LEGACY = "legacy"
   376 
   377   val NO_REPORT = "no_report"
   378 
   379   val BAD = "bad"
   380 
   381   val INTENSIFY = "intensify"
   382   val INFORMATION = "information"
   383 
   384 
   385   /* active areas */
   386 
   387   val BROWSER = "browser"
   388   val GRAPHVIEW = "graphview"
   389 
   390   val SENDBACK = "sendback"
   391   val PADDING = "padding"
   392   val PADDING_LINE = (PADDING, "line")
   393   val PADDING_COMMAND = (PADDING, "command")
   394 
   395   val DIALOG = "dialog"
   396   val Result = new Properties.String(RESULT)
   397 
   398 
   399   /* protocol message functions */
   400 
   401   val FUNCTION = "function"
   402   val Function = new Properties.String(FUNCTION)
   403 
   404   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   405   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   406 
   407   object Protocol_Handler
   408   {
   409     def unapply(props: Properties.T): Option[(String)] =
   410       props match {
   411         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   412         case _ => None
   413       }
   414   }
   415 
   416   val INVOKE_SCALA = "invoke_scala"
   417   object Invoke_Scala
   418   {
   419     def unapply(props: Properties.T): Option[(String, String)] =
   420       props match {
   421         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   422         case _ => None
   423       }
   424   }
   425 
   426   val CANCEL_SCALA = "cancel_scala"
   427   object Cancel_Scala
   428   {
   429     def unapply(props: Properties.T): Option[String] =
   430       props match {
   431         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   432         case _ => None
   433       }
   434   }
   435 
   436   object ML_Statistics
   437   {
   438     def unapply(props: Properties.T): Option[Properties.T] =
   439       props match {
   440         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   441         case _ => None
   442       }
   443   }
   444 
   445   object Task_Statistics
   446   {
   447     def unapply(props: Properties.T): Option[Properties.T] =
   448       props match {
   449         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   450         case _ => None
   451       }
   452   }
   453 
   454   object Loading_Theory
   455   {
   456     def unapply(props: Properties.T): Option[String] =
   457       props match {
   458         case List((FUNCTION, "loading_theory"), (NAME, name)) => Some(name)
   459         case _ => None
   460       }
   461   }
   462 
   463   object Use_Theories_Result
   464   {
   465     def unapply(props: Properties.T): Option[(String, Boolean)] =
   466       props match {
   467         case List((FUNCTION, "use_theories_result"),
   468           ("id", id), ("ok", Properties.Value.Boolean(ok))) => Some((id, ok))
   469         case _ => None
   470       }
   471   }
   472 
   473   val PRINT_OPERATIONS = "print_operations"
   474 
   475 
   476   /* simplifier trace */
   477 
   478   val SIMP_TRACE_PANEL = "simp_trace_panel"
   479 
   480   val SIMP_TRACE_LOG = "simp_trace_log"
   481   val SIMP_TRACE_STEP = "simp_trace_step"
   482   val SIMP_TRACE_RECURSE = "simp_trace_recurse"
   483   val SIMP_TRACE_HINT = "simp_trace_hint"
   484   val SIMP_TRACE_IGNORE = "simp_trace_ignore"
   485 
   486   val SIMP_TRACE_CANCEL = "simp_trace_cancel"
   487   object Simp_Trace_Cancel
   488   {
   489     def unapply(props: Properties.T): Option[Long] =
   490       props match {
   491         case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
   492         case _ => None
   493       }
   494   }
   495 }
   496 
   497 
   498 sealed case class Markup(name: String, properties: Properties.T)
   499