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