src/Pure/PIDE/markup.scala
author wenzelm
Thu Dec 13 17:29:23 2012 +0100 (2012-12-13 ago)
changeset 50501 6f41f1646617
parent 50500 c94bba7906d2
child 50503 50f141b34bb7
permissions -rw-r--r--
more careful handling of Dialog_Result, with active area and color feedback;
more formal type Command.Results;
propagate command results to output, which is required to resolve update of dialog state;
clarified Markup.message: retain uninterpreted messages;
     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   val Width = new Properties.Int("width")
    86   val BREAK = "break"
    87 
    88   val SEPARATOR = "separator"
    89 
    90 
    91   /* hidden text */
    92 
    93   val HIDDEN = "hidden"
    94 
    95 
    96   /* logical entities */
    97 
    98   val CLASS = "class"
    99   val TYPE_NAME = "type_name"
   100   val FIXED = "fixed"
   101   val CONSTANT = "constant"
   102 
   103   val DYNAMIC_FACT = "dynamic_fact"
   104 
   105 
   106   /* inner syntax */
   107 
   108   val TFREE = "tfree"
   109   val TVAR = "tvar"
   110   val FREE = "free"
   111   val SKOLEM = "skolem"
   112   val BOUND = "bound"
   113   val VAR = "var"
   114   val NUMERAL = "numeral"
   115   val LITERAL = "literal"
   116   val DELIMITER = "delimiter"
   117   val INNER_STRING = "inner_string"
   118   val INNER_COMMENT = "inner_comment"
   119 
   120   val TOKEN_RANGE = "token_range"
   121 
   122   val SORT = "sort"
   123   val TYP = "typ"
   124   val TERM = "term"
   125   val PROP = "prop"
   126 
   127   val SORTING = "sorting"
   128   val TYPING = "typing"
   129 
   130   val ATTRIBUTE = "attribute"
   131   val METHOD = "method"
   132 
   133 
   134   /* embedded source text */
   135 
   136   val ML_SOURCE = "ML_source"
   137   val DOCUMENT_SOURCE = "document_source"
   138 
   139   val ANTIQ = "antiq"
   140   val ML_ANTIQUOTATION = "ML_antiquotation"
   141   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   142   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   143 
   144 
   145   /* text structure */
   146 
   147   val PARAGRAPH = "paragraph"
   148 
   149 
   150   /* ML syntax */
   151 
   152   val ML_KEYWORD = "ML_keyword"
   153   val ML_DELIMITER = "ML_delimiter"
   154   val ML_TVAR = "ML_tvar"
   155   val ML_NUMERAL = "ML_numeral"
   156   val ML_CHAR = "ML_char"
   157   val ML_STRING = "ML_string"
   158   val ML_COMMENT = "ML_comment"
   159 
   160   val ML_DEF = "ML_def"
   161   val ML_OPEN = "ML_open"
   162   val ML_STRUCT = "ML_struct"
   163   val ML_TYPING = "ML_typing"
   164 
   165 
   166   /* outer syntax */
   167 
   168   val KEYWORD = "keyword"
   169   val OPERATOR = "operator"
   170   val COMMAND = "command"
   171   val STRING = "string"
   172   val ALTSTRING = "altstring"
   173   val VERBATIM = "verbatim"
   174   val COMMENT = "comment"
   175   val CONTROL = "control"
   176 
   177   val KEYWORD1 = "keyword1"
   178   val KEYWORD2 = "keyword2"
   179 
   180 
   181   /* timing */
   182 
   183   val TIMING = "timing"
   184   val ELAPSED = "elapsed"
   185   val CPU = "cpu"
   186   val GC = "gc"
   187 
   188   object Timing
   189   {
   190     def apply(timing: isabelle.Timing): Markup =
   191       Markup(TIMING, List(
   192         (ELAPSED, Properties.Value.Double(timing.elapsed.seconds)),
   193         (CPU, Properties.Value.Double(timing.cpu.seconds)),
   194         (GC, Properties.Value.Double(timing.gc.seconds))))
   195     def unapply(markup: Markup): Option[isabelle.Timing] =
   196       markup match {
   197         case Markup(TIMING, List(
   198           (ELAPSED, Properties.Value.Double(elapsed)),
   199           (CPU, Properties.Value.Double(cpu)),
   200           (GC, Properties.Value.Double(gc)))) =>
   201             Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   202         case _ => None
   203       }
   204   }
   205 
   206 
   207   /* toplevel */
   208 
   209   val SUBGOALS = "subgoals"
   210   val PROOF_STATE = "proof_state"
   211 
   212   val STATE = "state"
   213   val SUBGOAL = "subgoal"
   214 
   215 
   216   /* command status */
   217 
   218   val TASK = "task"
   219 
   220   val ACCEPTED = "accepted"
   221   val FORKED = "forked"
   222   val JOINED = "joined"
   223   val RUNNING = "running"
   224   val FINISHED = "finished"
   225   val FAILED = "failed"
   226 
   227 
   228   /* interactive documents */
   229 
   230   val VERSION = "version"
   231   val ASSIGN = "assign"
   232 
   233 
   234   /* prover process */
   235 
   236   val PROVER_COMMAND = "prover_command"
   237   val PROVER_ARG = "prover_arg"
   238 
   239 
   240   /* messages */
   241 
   242   val Serial = new Properties.Long("serial")
   243 
   244   val MESSAGE = "message"
   245 
   246   val INIT = "init"
   247   val STATUS = "status"
   248   val REPORT = "report"
   249   val RESULT = "result"
   250   val WRITELN = "writeln"
   251   val TRACING = "tracing"
   252   val WARNING = "warning"
   253   val ERROR = "error"
   254   val PROTOCOL = "protocol"
   255   val SYSTEM = "system"
   256   val STDOUT = "stdout"
   257   val STDERR = "stderr"
   258   val EXIT = "exit"
   259 
   260   val WRITELN_MESSAGE = "writeln_message"
   261   val TRACING_MESSAGE = "tracing_message"
   262   val WARNING_MESSAGE = "warning_message"
   263   val ERROR_MESSAGE = "error_message"
   264 
   265   val message: String => String =
   266     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   267         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE).withDefault((s: String) => s)
   268 
   269   val Return_Code = new Properties.Int("return_code")
   270 
   271   val LEGACY = "legacy"
   272 
   273   val NO_REPORT = "no_report"
   274 
   275   val BAD = "bad"
   276 
   277   val INTENSIFY = "intensify"
   278 
   279 
   280   /* active areas */
   281 
   282   val GRAPHVIEW = "graphview"
   283 
   284   val SENDBACK = "sendback"
   285   val PADDING = "padding"
   286   val PADDING_LINE = (PADDING, LINE)
   287 
   288   val DIALOG = "dialog"
   289   val Result = new Properties.String("result")
   290 
   291 
   292   /* protocol message functions */
   293 
   294   val FUNCTION = "function"
   295   val Function = new Properties.String(FUNCTION)
   296 
   297   val Assign_Execs: Properties.T = List((FUNCTION, "assign_execs"))
   298   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   299 
   300   object Invoke_Scala
   301   {
   302     def unapply(props: Properties.T): Option[(String, String)] =
   303       props match {
   304         case List((FUNCTION, "invoke_scala"), (NAME, name), (ID, id)) => Some((name, id))
   305         case _ => None
   306       }
   307   }
   308   object Cancel_Scala
   309   {
   310     def unapply(props: Properties.T): Option[String] =
   311       props match {
   312         case List((FUNCTION, "cancel_scala"), (ID, id)) => Some(id)
   313         case _ => None
   314       }
   315   }
   316 
   317   object ML_Statistics
   318   {
   319     def unapply(props: Properties.T): Option[Properties.T] =
   320       props match {
   321         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   322         case _ => None
   323       }
   324   }
   325 }
   326 
   327 
   328 sealed case class Markup(name: String, properties: Properties.T)
   329