src/Pure/PIDE/markup.scala
author wenzelm
Fri Aug 02 22:17:53 2013 +0200 (2013-08-02 ago)
changeset 52854 92932931bd82
parent 52800 1baa5d19ac44
child 52876 78989972d5b8
permissions -rw-r--r--
more general Output.result: allow to update arbitrary properties;
clarified kind/instance of overlay GUI component, with separate output (subject to version as main Output);
     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 message: String => String =
   287     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   288         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE).withDefault((s: String) => s)
   289 
   290   val Return_Code = new Properties.Int("return_code")
   291 
   292   val LEGACY = "legacy"
   293 
   294   val NO_REPORT = "no_report"
   295 
   296   val BAD = "bad"
   297 
   298   val INTENSIFY = "intensify"
   299   val INFORMATION = "information"
   300 
   301 
   302   /* active areas */
   303 
   304   val BROWSER = "browser"
   305   val GRAPHVIEW = "graphview"
   306 
   307   val SENDBACK = "sendback"
   308   val PADDING = "padding"
   309   val PADDING_LINE = (PADDING, "line")
   310   val PADDING_COMMAND = (PADDING, "command")
   311 
   312   val DIALOG = "dialog"
   313   val Result = new Properties.String(RESULT)
   314 
   315 
   316   /* protocol message functions */
   317 
   318   val FUNCTION = "function"
   319   val Function = new Properties.String(FUNCTION)
   320 
   321   val Flush: Properties.T = List((FUNCTION, "flush"))
   322 
   323   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   324   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   325 
   326   object Protocol_Handler
   327   {
   328     def unapply(props: Properties.T): Option[(String)] =
   329       props match {
   330         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   331         case _ => None
   332       }
   333   }
   334 
   335   val INVOKE_SCALA = "invoke_scala"
   336   object Invoke_Scala
   337   {
   338     def unapply(props: Properties.T): Option[(String, String)] =
   339       props match {
   340         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   341         case _ => None
   342       }
   343   }
   344 
   345   val CANCEL_SCALA = "cancel_scala"
   346   object Cancel_Scala
   347   {
   348     def unapply(props: Properties.T): Option[String] =
   349       props match {
   350         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   351         case _ => None
   352       }
   353   }
   354 
   355   object ML_Statistics
   356   {
   357     def unapply(props: Properties.T): Option[Properties.T] =
   358       props match {
   359         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   360         case _ => None
   361       }
   362   }
   363 
   364   object Task_Statistics
   365   {
   366     def unapply(props: Properties.T): Option[Properties.T] =
   367       props match {
   368         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   369         case _ => None
   370       }
   371   }
   372 }
   373 
   374 
   375 sealed case class Markup(name: String, properties: Properties.T)
   376