src/Pure/PIDE/markup.scala
author wenzelm
Tue Aug 06 21:34:58 2013 +0200 (2013-08-06 ago)
changeset 52877 9a26ec5739dd
parent 52876 78989972d5b8
child 53055 0fe8a9972eda
permissions -rw-r--r--
tuned -- more explicit type Status.Value;
     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   /* path */
    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 
    84   /* pretty printing */
    85 
    86   val Indent = new Properties.Int("indent")
    87   val BLOCK = "block"
    88 
    89   val Width = new Properties.Int("width")
    90   val BREAK = "break"
    91 
    92   val ITEM = "item"
    93   val BULLET = "bullet"
    94 
    95   val SEPARATOR = "separator"
    96 
    97 
    98   /* hidden text */
    99 
   100   val HIDDEN = "hidden"
   101 
   102 
   103   /* logical entities */
   104 
   105   val CLASS = "class"
   106   val TYPE_NAME = "type_name"
   107   val FIXED = "fixed"
   108   val CONSTANT = "constant"
   109 
   110   val DYNAMIC_FACT = "dynamic_fact"
   111 
   112 
   113   /* inner syntax */
   114 
   115   val TFREE = "tfree"
   116   val TVAR = "tvar"
   117   val FREE = "free"
   118   val SKOLEM = "skolem"
   119   val BOUND = "bound"
   120   val VAR = "var"
   121   val NUMERAL = "numeral"
   122   val LITERAL = "literal"
   123   val DELIMITER = "delimiter"
   124   val INNER_STRING = "inner_string"
   125   val INNER_COMMENT = "inner_comment"
   126 
   127   val TOKEN_RANGE = "token_range"
   128 
   129   val SORT = "sort"
   130   val TYP = "typ"
   131   val TERM = "term"
   132   val PROP = "prop"
   133 
   134   val SORTING = "sorting"
   135   val TYPING = "typing"
   136 
   137   val ATTRIBUTE = "attribute"
   138   val METHOD = "method"
   139 
   140 
   141   /* embedded source text */
   142 
   143   val ML_SOURCE = "ML_source"
   144   val DOCUMENT_SOURCE = "document_source"
   145 
   146   val ANTIQ = "antiq"
   147   val ML_ANTIQUOTATION = "ML_antiquotation"
   148   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   149   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   150 
   151 
   152   /* text structure */
   153 
   154   val PARAGRAPH = "paragraph"
   155   val TEXT_FOLD = "text_fold"
   156 
   157 
   158   /* ML syntax */
   159 
   160   val ML_KEYWORD = "ML_keyword"
   161   val ML_DELIMITER = "ML_delimiter"
   162   val ML_TVAR = "ML_tvar"
   163   val ML_NUMERAL = "ML_numeral"
   164   val ML_CHAR = "ML_char"
   165   val ML_STRING = "ML_string"
   166   val ML_COMMENT = "ML_comment"
   167 
   168   val ML_DEF = "ML_def"
   169   val ML_OPEN = "ML_open"
   170   val ML_STRUCT = "ML_struct"
   171   val ML_TYPING = "ML_typing"
   172 
   173 
   174   /* outer syntax */
   175 
   176   val KEYWORD = "keyword"
   177   val OPERATOR = "operator"
   178   val COMMAND = "command"
   179   val STRING = "string"
   180   val ALTSTRING = "altstring"
   181   val VERBATIM = "verbatim"
   182   val COMMENT = "comment"
   183   val CONTROL = "control"
   184 
   185   val KEYWORD1 = "keyword1"
   186   val KEYWORD2 = "keyword2"
   187 
   188 
   189   /* timing */
   190 
   191   val Elapsed = new Properties.Double("elapsed")
   192   val CPU = new Properties.Double("cpu")
   193   val GC = new Properties.Double("gc")
   194 
   195   object Timing_Properties
   196   {
   197     def apply(timing: isabelle.Timing): Properties.T =
   198       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   199 
   200     def unapply(props: Properties.T): Option[isabelle.Timing] =
   201       (props, props, props) match {
   202         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   203           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   204         case _ => None
   205       }
   206   }
   207 
   208   val TIMING = "timing"
   209 
   210   object Timing
   211   {
   212     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   213 
   214     def unapply(markup: Markup): Option[isabelle.Timing] =
   215       markup match {
   216         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   217         case _ => None
   218       }
   219   }
   220 
   221 
   222   /* command timing */
   223 
   224   val COMMAND_TIMING = "command_timing"
   225 
   226 
   227   /* toplevel */
   228 
   229   val SUBGOALS = "subgoals"
   230   val PROOF_STATE = "proof_state"
   231 
   232   val STATE = "state"
   233   val GOAL = "goal"
   234   val SUBGOAL = "subgoal"
   235 
   236 
   237   /* command status */
   238 
   239   val TASK = "task"
   240 
   241   val ACCEPTED = "accepted"
   242   val FORKED = "forked"
   243   val JOINED = "joined"
   244   val RUNNING = "running"
   245   val FINISHED = "finished"
   246   val FAILED = "failed"
   247 
   248 
   249   /* interactive documents */
   250 
   251   val VERSION = "version"
   252   val ASSIGN = "assign"
   253 
   254 
   255   /* prover process */
   256 
   257   val PROVER_COMMAND = "prover_command"
   258   val PROVER_ARG = "prover_arg"
   259 
   260 
   261   /* messages */
   262 
   263   val Serial = new Properties.Long("serial")
   264 
   265   val MESSAGE = "message"
   266 
   267   val INIT = "init"
   268   val STATUS = "status"
   269   val REPORT = "report"
   270   val RESULT = "result"
   271   val WRITELN = "writeln"
   272   val TRACING = "tracing"
   273   val WARNING = "warning"
   274   val ERROR = "error"
   275   val PROTOCOL = "protocol"
   276   val SYSTEM = "system"
   277   val STDOUT = "stdout"
   278   val STDERR = "stderr"
   279   val EXIT = "exit"
   280 
   281   val WRITELN_MESSAGE = "writeln_message"
   282   val TRACING_MESSAGE = "tracing_message"
   283   val WARNING_MESSAGE = "warning_message"
   284   val ERROR_MESSAGE = "error_message"
   285 
   286   val messages =
   287     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   288         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   289   val message: String => String = messages.withDefault((s: String) => s)
   290 
   291   val Return_Code = new Properties.Int("return_code")
   292 
   293   val LEGACY = "legacy"
   294 
   295   val NO_REPORT = "no_report"
   296 
   297   val BAD = "bad"
   298 
   299   val INTENSIFY = "intensify"
   300   val INFORMATION = "information"
   301 
   302 
   303   /* active areas */
   304 
   305   val BROWSER = "browser"
   306   val GRAPHVIEW = "graphview"
   307 
   308   val SENDBACK = "sendback"
   309   val PADDING = "padding"
   310   val PADDING_LINE = (PADDING, "line")
   311   val PADDING_COMMAND = (PADDING, "command")
   312 
   313   val DIALOG = "dialog"
   314   val Result = new Properties.String(RESULT)
   315 
   316 
   317   /* protocol message functions */
   318 
   319   val FUNCTION = "function"
   320   val Function = new Properties.String(FUNCTION)
   321 
   322   val Flush: Properties.T = List((FUNCTION, "flush"))
   323 
   324   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   325   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   326 
   327   object Protocol_Handler
   328   {
   329     def unapply(props: Properties.T): Option[(String)] =
   330       props match {
   331         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   332         case _ => None
   333       }
   334   }
   335 
   336   val INVOKE_SCALA = "invoke_scala"
   337   object Invoke_Scala
   338   {
   339     def unapply(props: Properties.T): Option[(String, String)] =
   340       props match {
   341         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   342         case _ => None
   343       }
   344   }
   345 
   346   val CANCEL_SCALA = "cancel_scala"
   347   object Cancel_Scala
   348   {
   349     def unapply(props: Properties.T): Option[String] =
   350       props match {
   351         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   352         case _ => None
   353       }
   354   }
   355 
   356   object ML_Statistics
   357   {
   358     def unapply(props: Properties.T): Option[Properties.T] =
   359       props match {
   360         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   361         case _ => None
   362       }
   363   }
   364 
   365   object Task_Statistics
   366   {
   367     def unapply(props: Properties.T): Option[Properties.T] =
   368       props match {
   369         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   370         case _ => None
   371       }
   372   }
   373 }
   374 
   375 
   376 sealed case class Markup(name: String, properties: Properties.T)
   377