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