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