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