src/Pure/PIDE/isabelle_markup.scala
author wenzelm
Tue Sep 18 17:20:40 2012 +0200 (2012-09-18 ago)
changeset 49418 c451856129cd
parent 49358 0fa351b1bd14
child 49473 ca7e2c21b104
permissions -rw-r--r--
more explicit message markup and rendering;
     1 /*  Title:      Pure/PIDE/isabelle_markup.scala
     2     Author:     Makarius
     3 
     4 Isabelle markup elements.
     5 */
     6 
     7 package isabelle
     8 
     9 
    10 object Isabelle_Markup
    11 {
    12   /* formal entities */
    13 
    14   val BINDING = "binding"
    15   val ENTITY = "entity"
    16   val DEF = "def"
    17   val REF = "ref"
    18 
    19   object Entity
    20   {
    21     def unapply(markup: Markup): Option[(String, String)] =
    22       markup match {
    23         case Markup(ENTITY, props @ Markup.Kind(kind)) =>
    24           props match {
    25             case Markup.Name(name) => Some(kind, name)
    26             case _ => None
    27           }
    28         case _ => None
    29       }
    30   }
    31 
    32 
    33   /* position */
    34 
    35   val LINE = "line"
    36   val OFFSET = "offset"
    37   val END_OFFSET = "end_offset"
    38   val FILE = "file"
    39   val ID = "id"
    40 
    41   val DEF_LINE = "def_line"
    42   val DEF_OFFSET = "def_offset"
    43   val DEF_END_OFFSET = "def_end_offset"
    44   val DEF_FILE = "def_file"
    45   val DEF_ID = "def_id"
    46 
    47   val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
    48   val POSITION = "position"
    49 
    50 
    51   /* path */
    52 
    53   val PATH = "path"
    54 
    55   object Path
    56   {
    57     def unapply(markup: Markup): Option[String] =
    58       markup match {
    59         case Markup(PATH, Markup.Name(name)) => Some(name)
    60         case _ => None
    61       }
    62   }
    63 
    64 
    65   /* pretty printing */
    66 
    67   val Indent = new Properties.Int("indent")
    68   val BLOCK = "block"
    69   val Width = new Properties.Int("width")
    70   val BREAK = "break"
    71 
    72 
    73   /* hidden text */
    74 
    75   val HIDDEN = "hidden"
    76 
    77 
    78   /* logical entities */
    79 
    80   val CLASS = "class"
    81   val TYPE_NAME = "type_name"
    82   val FIXED = "fixed"
    83   val CONSTANT = "constant"
    84 
    85   val DYNAMIC_FACT = "dynamic_fact"
    86 
    87 
    88   /* inner syntax */
    89 
    90   val TFREE = "tfree"
    91   val TVAR = "tvar"
    92   val FREE = "free"
    93   val SKOLEM = "skolem"
    94   val BOUND = "bound"
    95   val VAR = "var"
    96   val NUMERAL = "numeral"
    97   val LITERAL = "literal"
    98   val DELIMITER = "delimiter"
    99   val INNER_STRING = "inner_string"
   100   val INNER_COMMENT = "inner_comment"
   101 
   102   val TOKEN_RANGE = "token_range"
   103 
   104   val SORT = "sort"
   105   val TYP = "typ"
   106   val TERM = "term"
   107   val PROP = "prop"
   108 
   109   val TYPING = "typing"
   110 
   111   val ATTRIBUTE = "attribute"
   112   val METHOD = "method"
   113 
   114 
   115   /* embedded source text */
   116 
   117   val ML_SOURCE = "ML_source"
   118   val DOCUMENT_SOURCE = "document_source"
   119 
   120   val ANTIQ = "antiq"
   121   val ML_ANTIQUOTATION = "ML_antiquotation"
   122   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   123   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   124 
   125 
   126   /* ML syntax */
   127 
   128   val ML_KEYWORD = "ML_keyword"
   129   val ML_DELIMITER = "ML_delimiter"
   130   val ML_TVAR = "ML_tvar"
   131   val ML_NUMERAL = "ML_numeral"
   132   val ML_CHAR = "ML_char"
   133   val ML_STRING = "ML_string"
   134   val ML_COMMENT = "ML_comment"
   135 
   136   val ML_DEF = "ML_def"
   137   val ML_OPEN = "ML_open"
   138   val ML_STRUCT = "ML_struct"
   139   val ML_TYPING = "ML_typing"
   140 
   141 
   142   /* outer syntax */
   143 
   144   val KEYWORD = "keyword"
   145   val OPERATOR = "operator"
   146   val COMMAND = "command"
   147   val STRING = "string"
   148   val ALTSTRING = "altstring"
   149   val VERBATIM = "verbatim"
   150   val COMMENT = "comment"
   151   val CONTROL = "control"
   152 
   153 
   154   /* timing */
   155 
   156   val TIMING = "timing"
   157   val ELAPSED = "elapsed"
   158   val CPU = "cpu"
   159   val GC = "gc"
   160 
   161   object Timing
   162   {
   163     def apply(timing: isabelle.Timing): Markup =
   164       Markup(TIMING, List(
   165         (ELAPSED, Properties.Value.Double(timing.elapsed.seconds)),
   166         (CPU, Properties.Value.Double(timing.cpu.seconds)),
   167         (GC, Properties.Value.Double(timing.gc.seconds))))
   168     def unapply(markup: Markup): Option[isabelle.Timing] =
   169       markup match {
   170         case Markup(TIMING, List(
   171           (ELAPSED, Properties.Value.Double(elapsed)),
   172           (CPU, Properties.Value.Double(cpu)),
   173           (GC, Properties.Value.Double(gc)))) =>
   174             Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   175         case _ => None
   176       }
   177   }
   178 
   179 
   180   /* toplevel */
   181 
   182   val SUBGOALS = "subgoals"
   183   val PROOF_STATE = "proof_state"
   184 
   185   val STATE = "state"
   186   val SUBGOAL = "subgoal"
   187   val SENDBACK = "sendback"
   188   val INTENSIFY = "intensify"
   189 
   190 
   191   /* command status */
   192 
   193   val TASK = "task"
   194 
   195   val ACCEPTED = "accepted"
   196   val FORKED = "forked"
   197   val JOINED = "joined"
   198   val RUNNING = "running"
   199   val FINISHED = "finished"
   200   val FAILED = "failed"
   201 
   202 
   203   /* interactive documents */
   204 
   205   val VERSION = "version"
   206   val ASSIGN = "assign"
   207 
   208 
   209   /* prover process */
   210 
   211   val PROVER_COMMAND = "prover_command"
   212   val PROVER_ARG = "prover_arg"
   213 
   214 
   215   /* messages */
   216 
   217   val Serial = new Properties.Long("serial")
   218 
   219   val MESSAGE = "message"
   220 
   221   val INIT = "init"
   222   val STATUS = "status"
   223   val REPORT = "report"
   224   val WRITELN = "writeln"
   225   val TRACING = "tracing"
   226   val WARNING = "warning"
   227   val ERROR = "error"
   228   val PROTOCOL = "protocol"
   229   val SYSTEM = "system"
   230   val STDOUT = "stdout"
   231   val STDERR = "stderr"
   232   val EXIT = "exit"
   233 
   234   val WRITELN_MESSAGE = "writeln_message"
   235   val TRACING_MESSAGE = "tracing_message"
   236   val WARNING_MESSAGE = "warning_message"
   237   val ERROR_MESSAGE = "error_message"
   238 
   239   val message: String => String =
   240     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   241         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   242       .withDefault((name: String) => name + "_message")
   243 
   244   val Return_Code = new Properties.Int("return_code")
   245 
   246   val LEGACY = "legacy"
   247 
   248   val NO_REPORT = "no_report"
   249 
   250   val BAD = "bad"
   251 
   252 
   253   /* protocol message functions */
   254 
   255   val FUNCTION = "function"
   256   val Function = new Properties.String(FUNCTION)
   257 
   258   val Assign_Execs: Properties.T = List((FUNCTION, "assign_execs"))
   259   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   260 
   261   object Invoke_Scala
   262   {
   263     def unapply(props: Properties.T): Option[(String, String)] =
   264       props match {
   265         case List((FUNCTION, "invoke_scala"), (Markup.NAME, name), (ID, id)) => Some((name, id))
   266         case _ => None
   267       }
   268   }
   269   object Cancel_Scala
   270   {
   271     def unapply(props: Properties.T): Option[String] =
   272       props match {
   273         case List((FUNCTION, "cancel_scala"), (ID, id)) => Some(id)
   274         case _ => None
   275       }
   276   }
   277 }
   278