src/Pure/PIDE/markup.scala
author wenzelm
Sun Nov 25 19:49:24 2012 +0100 (2012-11-25 ago)
changeset 50201 c26369c9eda6
parent 49613 2f6986e2ef06
child 50215 97959912840a
permissions -rw-r--r--
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
     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   val SENDBACK = "sendback"
   215   val INTENSIFY = "intensify"
   216 
   217 
   218   /* command status */
   219 
   220   val TASK = "task"
   221 
   222   val ACCEPTED = "accepted"
   223   val FORKED = "forked"
   224   val JOINED = "joined"
   225   val RUNNING = "running"
   226   val FINISHED = "finished"
   227   val FAILED = "failed"
   228 
   229 
   230   /* interactive documents */
   231 
   232   val VERSION = "version"
   233   val ASSIGN = "assign"
   234 
   235 
   236   /* prover process */
   237 
   238   val PROVER_COMMAND = "prover_command"
   239   val PROVER_ARG = "prover_arg"
   240 
   241 
   242   /* messages */
   243 
   244   val Serial = new Properties.Long("serial")
   245 
   246   val MESSAGE = "message"
   247 
   248   val INIT = "init"
   249   val STATUS = "status"
   250   val REPORT = "report"
   251   val WRITELN = "writeln"
   252   val TRACING = "tracing"
   253   val WARNING = "warning"
   254   val ERROR = "error"
   255   val PROTOCOL = "protocol"
   256   val SYSTEM = "system"
   257   val STDOUT = "stdout"
   258   val STDERR = "stderr"
   259   val EXIT = "exit"
   260 
   261   val WRITELN_MESSAGE = "writeln_message"
   262   val TRACING_MESSAGE = "tracing_message"
   263   val WARNING_MESSAGE = "warning_message"
   264   val ERROR_MESSAGE = "error_message"
   265 
   266   val message: String => String =
   267     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   268         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   269       .withDefault((name: String) => name + "_message")
   270 
   271   val Return_Code = new Properties.Int("return_code")
   272 
   273   val LEGACY = "legacy"
   274 
   275   val NO_REPORT = "no_report"
   276 
   277   val BAD = "bad"
   278 
   279   val GRAPHVIEW = "graphview"
   280 
   281 
   282   /* protocol message functions */
   283 
   284   val FUNCTION = "function"
   285   val Function = new Properties.String(FUNCTION)
   286 
   287   val Assign_Execs: Properties.T = List((FUNCTION, "assign_execs"))
   288   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   289 
   290   object Invoke_Scala
   291   {
   292     def unapply(props: Properties.T): Option[(String, String)] =
   293       props match {
   294         case List((FUNCTION, "invoke_scala"), (NAME, name), (ID, id)) => Some((name, id))
   295         case _ => None
   296       }
   297   }
   298   object Cancel_Scala
   299   {
   300     def unapply(props: Properties.T): Option[String] =
   301       props match {
   302         case List((FUNCTION, "cancel_scala"), (ID, id)) => Some(id)
   303         case _ => None
   304       }
   305   }
   306 }
   307 
   308 
   309 sealed case class Markup(name: String, properties: Properties.T)
   310