src/Pure/PIDE/markup.scala
author wenzelm
Sat Jan 18 19:15:12 2014 +0100 (2014-01-18 ago)
changeset 55033 8e8243975860
parent 54702 3daeba5130f0
child 55316 885500f4aa6a
permissions -rw-r--r--
support for nested text cartouches;
clarified Symbol.is_symbolic: exclude \<open> and \<close>;
     1 /*  Title:      Pure/PIDE/markup.scala
     2     Module:     PIDE
     3     Author:     Makarius
     4 
     5 Isabelle-specific implementation of quasi-abstract markup elements.
     6 */
     7 
     8 package isabelle
     9 
    10 
    11 object Markup
    12 {
    13   /* properties */
    14 
    15   val NAME = "name"
    16   val Name = new Properties.String(NAME)
    17 
    18   val KIND = "kind"
    19   val Kind = new Properties.String(KIND)
    20 
    21   val INSTANCE = "instance"
    22   val Instance = new Properties.String(INSTANCE)
    23 
    24 
    25   /* basic markup */
    26 
    27   val Empty = Markup("", Nil)
    28   val Broken = Markup("broken", Nil)
    29 
    30 
    31   /* formal entities */
    32 
    33   val BINDING = "binding"
    34   val ENTITY = "entity"
    35   val DEF = "def"
    36   val REF = "ref"
    37 
    38   object Entity
    39   {
    40     def unapply(markup: Markup): Option[(String, String)] =
    41       markup match {
    42         case Markup(ENTITY, props @ Kind(kind)) =>
    43           props match {
    44             case Name(name) => Some(kind, name)
    45             case _ => None
    46           }
    47         case _ => None
    48       }
    49   }
    50 
    51 
    52   /* position */
    53 
    54   val LINE = "line"
    55   val OFFSET = "offset"
    56   val END_OFFSET = "end_offset"
    57   val FILE = "file"
    58   val ID = "id"
    59 
    60   val DEF_LINE = "def_line"
    61   val DEF_OFFSET = "def_offset"
    62   val DEF_END_OFFSET = "def_end_offset"
    63   val DEF_FILE = "def_file"
    64   val DEF_ID = "def_id"
    65 
    66   val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
    67   val POSITION = "position"
    68 
    69 
    70   /* external resources */
    71 
    72   val PATH = "path"
    73 
    74   object Path
    75   {
    76     def unapply(markup: Markup): Option[String] =
    77       markup match {
    78         case Markup(PATH, Name(name)) => Some(name)
    79         case _ => None
    80       }
    81   }
    82 
    83   val URL = "url"
    84 
    85   object Url
    86   {
    87     def unapply(markup: Markup): Option[String] =
    88       markup match {
    89         case Markup(URL, Name(name)) => Some(name)
    90         case _ => None
    91       }
    92   }
    93 
    94 
    95   /* pretty printing */
    96 
    97   val Indent = new Properties.Int("indent")
    98   val BLOCK = "block"
    99 
   100   val Width = new Properties.Int("width")
   101   val BREAK = "break"
   102 
   103   val ITEM = "item"
   104   val BULLET = "bullet"
   105 
   106   val SEPARATOR = "separator"
   107 
   108 
   109   /* hidden text */
   110 
   111   val HIDDEN = "hidden"
   112 
   113 
   114   /* logical entities */
   115 
   116   val CLASS = "class"
   117   val TYPE_NAME = "type_name"
   118   val FIXED = "fixed"
   119   val CASE = "case"
   120   val CONSTANT = "constant"
   121   val DYNAMIC_FACT = "dynamic_fact"
   122 
   123 
   124   /* inner syntax */
   125 
   126   val TFREE = "tfree"
   127   val TVAR = "tvar"
   128   val FREE = "free"
   129   val SKOLEM = "skolem"
   130   val BOUND = "bound"
   131   val VAR = "var"
   132   val NUMERAL = "numeral"
   133   val LITERAL = "literal"
   134   val DELIMITER = "delimiter"
   135   val INNER_STRING = "inner_string"
   136   val INNER_CARTOUCHE = "inner_cartouche"
   137   val INNER_COMMENT = "inner_comment"
   138 
   139   val TOKEN_RANGE = "token_range"
   140 
   141   val SORT = "sort"
   142   val TYP = "typ"
   143   val TERM = "term"
   144   val PROP = "prop"
   145 
   146   val SORTING = "sorting"
   147   val TYPING = "typing"
   148 
   149   val ATTRIBUTE = "attribute"
   150   val METHOD = "method"
   151 
   152 
   153   /* embedded source text */
   154 
   155   val ML_SOURCE = "ML_source"
   156   val DOCUMENT_SOURCE = "document_source"
   157 
   158   val ANTIQ = "antiq"
   159   val ML_ANTIQUOTATION = "ML_antiquotation"
   160   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   161   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   162 
   163 
   164   /* text structure */
   165 
   166   val PARAGRAPH = "paragraph"
   167   val TEXT_FOLD = "text_fold"
   168 
   169 
   170   /* ML syntax */
   171 
   172   val ML_KEYWORD = "ML_keyword"
   173   val ML_DELIMITER = "ML_delimiter"
   174   val ML_TVAR = "ML_tvar"
   175   val ML_NUMERAL = "ML_numeral"
   176   val ML_CHAR = "ML_char"
   177   val ML_STRING = "ML_string"
   178   val ML_COMMENT = "ML_comment"
   179 
   180   val ML_DEF = "ML_def"
   181   val ML_OPEN = "ML_open"
   182   val ML_STRUCT = "ML_struct"
   183   val ML_TYPING = "ML_typing"
   184 
   185 
   186   /* outer syntax */
   187 
   188   val KEYWORD = "keyword"
   189   val OPERATOR = "operator"
   190   val COMMAND = "command"
   191   val STRING = "string"
   192   val ALTSTRING = "altstring"
   193   val VERBATIM = "verbatim"
   194   val CARTOUCHE = "cartouche"
   195   val COMMENT = "comment"
   196   val CONTROL = "control"
   197 
   198   val KEYWORD1 = "keyword1"
   199   val KEYWORD2 = "keyword2"
   200 
   201 
   202   /* timing */
   203 
   204   val Elapsed = new Properties.Double("elapsed")
   205   val CPU = new Properties.Double("cpu")
   206   val GC = new Properties.Double("gc")
   207 
   208   object Timing_Properties
   209   {
   210     def apply(timing: isabelle.Timing): Properties.T =
   211       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   212 
   213     def unapply(props: Properties.T): Option[isabelle.Timing] =
   214       (props, props, props) match {
   215         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   216           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   217         case _ => None
   218       }
   219   }
   220 
   221   val TIMING = "timing"
   222 
   223   object Timing
   224   {
   225     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   226 
   227     def unapply(markup: Markup): Option[isabelle.Timing] =
   228       markup match {
   229         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   230         case _ => None
   231       }
   232   }
   233 
   234 
   235   /* command timing */
   236 
   237   val COMMAND_TIMING = "command_timing"
   238 
   239 
   240   /* toplevel */
   241 
   242   val SUBGOALS = "subgoals"
   243   val PROOF_STATE = "proof_state"
   244 
   245   val STATE = "state"
   246   val GOAL = "goal"
   247   val SUBGOAL = "subgoal"
   248 
   249 
   250   /* command status */
   251 
   252   val TASK = "task"
   253 
   254   val ACCEPTED = "accepted"
   255   val FORKED = "forked"
   256   val JOINED = "joined"
   257   val RUNNING = "running"
   258   val FINISHED = "finished"
   259   val FAILED = "failed"
   260 
   261 
   262   /* interactive documents */
   263 
   264   val VERSION = "version"
   265   val ASSIGN = "assign"
   266 
   267 
   268   /* prover process */
   269 
   270   val PROVER_COMMAND = "prover_command"
   271   val PROVER_ARG = "prover_arg"
   272 
   273 
   274   /* messages */
   275 
   276   val Serial = new Properties.Long("serial")
   277 
   278   val MESSAGE = "message"
   279 
   280   val INIT = "init"
   281   val STATUS = "status"
   282   val REPORT = "report"
   283   val RESULT = "result"
   284   val WRITELN = "writeln"
   285   val TRACING = "tracing"
   286   val WARNING = "warning"
   287   val ERROR = "error"
   288   val PROTOCOL = "protocol"
   289   val SYSTEM = "system"
   290   val STDOUT = "stdout"
   291   val STDERR = "stderr"
   292   val EXIT = "exit"
   293 
   294   val WRITELN_MESSAGE = "writeln_message"
   295   val TRACING_MESSAGE = "tracing_message"
   296   val WARNING_MESSAGE = "warning_message"
   297   val ERROR_MESSAGE = "error_message"
   298 
   299   val messages =
   300     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   301         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   302   val message: String => String = messages.withDefault((s: String) => s)
   303 
   304   val Return_Code = new Properties.Int("return_code")
   305 
   306   val LEGACY = "legacy"
   307 
   308   val NO_REPORT = "no_report"
   309 
   310   val BAD = "bad"
   311 
   312   val INTENSIFY = "intensify"
   313   val INFORMATION = "information"
   314 
   315 
   316   /* active areas */
   317 
   318   val BROWSER = "browser"
   319   val GRAPHVIEW = "graphview"
   320 
   321   val SENDBACK = "sendback"
   322   val PADDING = "padding"
   323   val PADDING_LINE = (PADDING, "line")
   324   val PADDING_COMMAND = (PADDING, "command")
   325 
   326   val DIALOG = "dialog"
   327   val Result = new Properties.String(RESULT)
   328 
   329 
   330   /* protocol message functions */
   331 
   332   val FUNCTION = "function"
   333   val Function = new Properties.String(FUNCTION)
   334 
   335   val Flush: Properties.T = List((FUNCTION, "flush"))
   336 
   337   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   338   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   339 
   340   object Protocol_Handler
   341   {
   342     def unapply(props: Properties.T): Option[(String)] =
   343       props match {
   344         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   345         case _ => None
   346       }
   347   }
   348 
   349   val INVOKE_SCALA = "invoke_scala"
   350   object Invoke_Scala
   351   {
   352     def unapply(props: Properties.T): Option[(String, String)] =
   353       props match {
   354         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   355         case _ => None
   356       }
   357   }
   358 
   359   val CANCEL_SCALA = "cancel_scala"
   360   object Cancel_Scala
   361   {
   362     def unapply(props: Properties.T): Option[String] =
   363       props match {
   364         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   365         case _ => None
   366       }
   367   }
   368 
   369   val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
   370   val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
   371 
   372   object ML_Statistics
   373   {
   374     def unapply(props: Properties.T): Option[Properties.T] =
   375       props match {
   376         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   377         case _ => None
   378       }
   379   }
   380 
   381   object Task_Statistics
   382   {
   383     def unapply(props: Properties.T): Option[Properties.T] =
   384       props match {
   385         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   386         case _ => None
   387       }
   388   }
   389 }
   390 
   391 
   392 sealed case class Markup(name: String, properties: Properties.T)
   393