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