src/Pure/General/markup.scala
author wenzelm
Sun Mar 27 21:19:23 2011 +0200 (2011-03-27 ago)
changeset 42136 826168ae0213
parent 41483 4a8431c73cf2
child 42202 f6483ed40529
permissions -rw-r--r--
added Markup.Name and Markup.Kind convenience;
token_style for entity kind markup;
wenzelm@27958
     1
/*  Title:      Pure/General/markup.scala
wenzelm@27958
     2
    Author:     Makarius
wenzelm@27958
     3
wenzelm@27958
     4
Common markup elements.
wenzelm@27958
     5
*/
wenzelm@27958
     6
wenzelm@27958
     7
package isabelle
wenzelm@27958
     8
wenzelm@27970
     9
wenzelm@32450
    10
object Markup
wenzelm@32450
    11
{
wenzelm@38722
    12
  /* plain values */
wenzelm@38414
    13
wenzelm@40392
    14
  object Int
wenzelm@40392
    15
  {
wenzelm@40392
    16
    def apply(x: scala.Int): String = x.toString
wenzelm@38414
    17
    def unapply(s: String): Option[scala.Int] =
wenzelm@38414
    18
      try { Some(Integer.parseInt(s)) }
wenzelm@38414
    19
      catch { case _: NumberFormatException => None }
wenzelm@38414
    20
  }
wenzelm@38414
    21
wenzelm@40392
    22
  object Long
wenzelm@40392
    23
  {
wenzelm@40392
    24
    def apply(x: scala.Long): String = x.toString
wenzelm@38414
    25
    def unapply(s: String): Option[scala.Long] =
wenzelm@38414
    26
      try { Some(java.lang.Long.parseLong(s)) }
wenzelm@38414
    27
      catch { case _: NumberFormatException => None }
wenzelm@38414
    28
  }
wenzelm@38414
    29
wenzelm@40392
    30
  object Double
wenzelm@40392
    31
  {
wenzelm@40392
    32
    def apply(x: scala.Double): String = x.toString
wenzelm@40392
    33
    def unapply(s: String): Option[scala.Double] =
wenzelm@40392
    34
      try { Some(java.lang.Double.parseDouble(s)) }
wenzelm@40392
    35
      catch { case _: NumberFormatException => None }
wenzelm@40392
    36
  }
wenzelm@40392
    37
wenzelm@38414
    38
wenzelm@38722
    39
  /* named properties */
wenzelm@36683
    40
wenzelm@38722
    41
  class Property(val name: String)
wenzelm@38355
    42
  {
wenzelm@38722
    43
    def apply(value: String): List[(String, String)] = List((name, value))
wenzelm@38722
    44
    def unapply(props: List[(String, String)]): Option[String] =
wenzelm@38722
    45
      props.find(_._1 == name).map(_._2)
wenzelm@38355
    46
  }
wenzelm@38355
    47
wenzelm@38722
    48
  class Int_Property(name: String)
wenzelm@36683
    49
  {
wenzelm@38722
    50
    def apply(value: scala.Int): List[(String, String)] = List((name, Int(value)))
wenzelm@38722
    51
    def unapply(props: List[(String, String)]): Option[Int] =
wenzelm@38722
    52
      props.find(_._1 == name) match {
wenzelm@38722
    53
        case None => None
wenzelm@38722
    54
        case Some((_, value)) => Int.unapply(value)
wenzelm@38722
    55
      }
wenzelm@38722
    56
  }
wenzelm@38722
    57
wenzelm@38722
    58
  class Long_Property(name: String)
wenzelm@38722
    59
  {
wenzelm@38722
    60
    def apply(value: scala.Long): List[(String, String)] = List((name, Long(value)))
wenzelm@38722
    61
    def unapply(props: List[(String, String)]): Option[Long] =
wenzelm@38722
    62
      props.find(_._1 == name) match {
wenzelm@38722
    63
        case None => None
wenzelm@38722
    64
        case Some((_, value)) => Long.unapply(value)
wenzelm@38722
    65
      }
wenzelm@36683
    66
  }
wenzelm@36683
    67
wenzelm@40392
    68
  class Double_Property(name: String)
wenzelm@40392
    69
  {
wenzelm@40392
    70
    def apply(value: scala.Double): List[(String, String)] = List((name, Double(value)))
wenzelm@40392
    71
    def unapply(props: List[(String, String)]): Option[Double] =
wenzelm@40392
    72
      props.find(_._1 == name) match {
wenzelm@40392
    73
        case None => None
wenzelm@40392
    74
        case Some((_, value)) => Double.unapply(value)
wenzelm@40392
    75
      }
wenzelm@40392
    76
  }
wenzelm@40392
    77
wenzelm@36683
    78
wenzelm@38474
    79
  /* empty */
wenzelm@38474
    80
wenzelm@38474
    81
  val Empty = Markup("", Nil)
wenzelm@38474
    82
wenzelm@38474
    83
wenzelm@38721
    84
  /* misc properties */
wenzelm@29184
    85
wenzelm@29184
    86
  val NAME = "name"
wenzelm@42136
    87
  val Name = new Property(NAME)
wenzelm@42136
    88
wenzelm@29184
    89
  val KIND = "kind"
wenzelm@42136
    90
  val Kind = new Property(KIND)
wenzelm@29184
    91
wenzelm@29184
    92
wenzelm@33088
    93
  /* formal entities */
wenzelm@33088
    94
wenzelm@38887
    95
  val BINDING = "binding"
wenzelm@33088
    96
  val ENTITY = "entity"
wenzelm@33088
    97
  val DEF = "def"
wenzelm@33088
    98
  val REF = "ref"
wenzelm@33088
    99
wenzelm@33088
   100
wenzelm@27970
   101
  /* position */
wenzelm@27970
   102
wenzelm@27970
   103
  val LINE = "line"
wenzelm@27970
   104
  val COLUMN = "column"
wenzelm@27970
   105
  val OFFSET = "offset"
wenzelm@27970
   106
  val END_OFFSET = "end_offset"
wenzelm@27970
   107
  val FILE = "file"
wenzelm@27970
   108
  val ID = "id"
wenzelm@27970
   109
wenzelm@41483
   110
  val POSITION_PROPERTIES = Set(LINE, COLUMN, OFFSET, END_OFFSET, FILE, ID)
wenzelm@29205
   111
wenzelm@29184
   112
  val POSITION = "position"
wenzelm@29184
   113
wenzelm@29184
   114
wenzelm@36683
   115
  /* pretty printing */
wenzelm@36683
   116
wenzelm@38724
   117
  val Indent = new Int_Property("indent")
wenzelm@36683
   118
  val BLOCK = "block"
wenzelm@38724
   119
  val Width = new Int_Property("width")
wenzelm@36683
   120
  val BREAK = "break"
wenzelm@36683
   121
wenzelm@36683
   122
wenzelm@33985
   123
  /* hidden text */
wenzelm@33985
   124
wenzelm@33985
   125
  val HIDDEN = "hidden"
wenzelm@33985
   126
wenzelm@33985
   127
wenzelm@29184
   128
  /* logical entities */
wenzelm@29184
   129
wenzelm@29184
   130
  val TCLASS = "tclass"
wenzelm@29184
   131
  val TYCON = "tycon"
wenzelm@29184
   132
  val FIXED_DECL = "fixed_decl"
wenzelm@29184
   133
  val FIXED = "fixed"
wenzelm@29184
   134
  val CONST_DECL = "const_decl"
wenzelm@42136
   135
  val CONST = "constant"
wenzelm@29184
   136
  val FACT_DECL = "fact_decl"
wenzelm@29184
   137
  val FACT = "fact"
wenzelm@29184
   138
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@29184
   139
  val LOCAL_FACT_DECL = "local_fact_decl"
wenzelm@29184
   140
  val LOCAL_FACT = "local_fact"
wenzelm@29184
   141
wenzelm@29184
   142
wenzelm@29184
   143
  /* inner syntax */
wenzelm@29184
   144
wenzelm@29184
   145
  val TFREE = "tfree"
wenzelm@29184
   146
  val TVAR = "tvar"
wenzelm@29184
   147
  val FREE = "free"
wenzelm@29184
   148
  val SKOLEM = "skolem"
wenzelm@29184
   149
  val BOUND = "bound"
wenzelm@29184
   150
  val VAR = "var"
wenzelm@29184
   151
  val NUM = "num"
wenzelm@29184
   152
  val FLOAT = "float"
wenzelm@29184
   153
  val XNUM = "xnum"
wenzelm@29184
   154
  val XSTR = "xstr"
wenzelm@29184
   155
  val LITERAL = "literal"
wenzelm@29184
   156
  val INNER_COMMENT = "inner_comment"
wenzelm@29184
   157
wenzelm@39168
   158
  val TOKEN_RANGE = "token_range"
wenzelm@39168
   159
wenzelm@29184
   160
  val SORT = "sort"
wenzelm@29184
   161
  val TYP = "typ"
wenzelm@29184
   162
  val TERM = "term"
wenzelm@29184
   163
  val PROP = "prop"
wenzelm@29184
   164
wenzelm@29184
   165
  val ATTRIBUTE = "attribute"
wenzelm@29184
   166
  val METHOD = "method"
wenzelm@29184
   167
wenzelm@29184
   168
wenzelm@29184
   169
  /* embedded source text */
wenzelm@29184
   170
wenzelm@29184
   171
  val ML_SOURCE = "ML_source"
wenzelm@29184
   172
  val DOC_SOURCE = "doc_source"
wenzelm@29184
   173
wenzelm@29184
   174
  val ANTIQ = "antiq"
wenzelm@29184
   175
  val ML_ANTIQ = "ML_antiq"
wenzelm@29184
   176
  val DOC_ANTIQ = "doc_antiq"
wenzelm@29184
   177
wenzelm@29184
   178
wenzelm@30615
   179
  /* ML syntax */
wenzelm@30615
   180
wenzelm@30615
   181
  val ML_KEYWORD = "ML_keyword"
wenzelm@37195
   182
  val ML_DELIMITER = "ML_delimiter"
wenzelm@30615
   183
  val ML_IDENT = "ML_ident"
wenzelm@30615
   184
  val ML_TVAR = "ML_tvar"
wenzelm@30615
   185
  val ML_NUMERAL = "ML_numeral"
wenzelm@30615
   186
  val ML_CHAR = "ML_char"
wenzelm@30615
   187
  val ML_STRING = "ML_string"
wenzelm@30615
   188
  val ML_COMMENT = "ML_comment"
wenzelm@30615
   189
  val ML_MALFORMED = "ML_malformed"
wenzelm@30615
   190
wenzelm@30702
   191
  val ML_DEF = "ML_def"
wenzelm@31472
   192
  val ML_OPEN = "ML_open"
wenzelm@31472
   193
  val ML_STRUCT = "ML_struct"
wenzelm@30702
   194
  val ML_REF = "ML_ref"
wenzelm@30702
   195
  val ML_TYPING = "ML_typing"
wenzelm@30702
   196
wenzelm@30615
   197
wenzelm@29184
   198
  /* outer syntax */
wenzelm@29184
   199
wenzelm@29184
   200
  val KEYWORD_DECL = "keyword_decl"
wenzelm@29184
   201
  val COMMAND_DECL = "command_decl"
wenzelm@29184
   202
wenzelm@29184
   203
  val KEYWORD = "keyword"
wenzelm@37194
   204
  val OPERATOR = "operator"
wenzelm@29184
   205
  val COMMAND = "command"
wenzelm@29184
   206
  val IDENT = "ident"
wenzelm@29184
   207
  val STRING = "string"
wenzelm@29184
   208
  val ALTSTRING = "altstring"
wenzelm@29184
   209
  val VERBATIM = "verbatim"
wenzelm@29184
   210
  val COMMENT = "comment"
wenzelm@29184
   211
  val CONTROL = "control"
wenzelm@29184
   212
  val MALFORMED = "malformed"
wenzelm@29184
   213
wenzelm@29185
   214
  val COMMAND_SPAN = "command_span"
wenzelm@29185
   215
  val IGNORED_SPAN = "ignored_span"
wenzelm@29185
   216
  val MALFORMED_SPAN = "malformed_span"
wenzelm@29185
   217
wenzelm@29184
   218
wenzelm@40394
   219
  /* timing */
wenzelm@40394
   220
wenzelm@40394
   221
  val TIMING = "timing"
wenzelm@40394
   222
  val ELAPSED = "elapsed"
wenzelm@40394
   223
  val CPU = "cpu"
wenzelm@40394
   224
  val GC = "gc"
wenzelm@40394
   225
wenzelm@40394
   226
  object Timing
wenzelm@40394
   227
  {
wenzelm@40394
   228
    def apply(timing: isabelle.Timing): Markup =
wenzelm@40394
   229
      Markup(TIMING, List(
wenzelm@40848
   230
        (ELAPSED, Double(timing.elapsed.seconds)),
wenzelm@40848
   231
        (CPU, Double(timing.cpu.seconds)),
wenzelm@40848
   232
        (GC, Double(timing.gc.seconds))))
wenzelm@40394
   233
    def unapply(markup: Markup): Option[isabelle.Timing] =
wenzelm@40394
   234
      markup match {
wenzelm@40394
   235
        case Markup(TIMING, List(
wenzelm@40848
   236
          (ELAPSED, Double(elapsed)), (CPU, Double(cpu)), (GC, Double(gc)))) =>
wenzelm@40848
   237
            Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
wenzelm@40394
   238
        case _ => None
wenzelm@40394
   239
      }
wenzelm@40394
   240
  }
wenzelm@40394
   241
wenzelm@40394
   242
wenzelm@29184
   243
  /* toplevel */
wenzelm@29184
   244
wenzelm@38721
   245
  val SUBGOALS = "subgoals"
wenzelm@38721
   246
  val PROOF_STATE = "proof_state"
wenzelm@38721
   247
wenzelm@29184
   248
  val STATE = "state"
wenzelm@29184
   249
  val SUBGOAL = "subgoal"
wenzelm@29184
   250
  val SENDBACK = "sendback"
wenzelm@29184
   251
  val HILITE = "hilite"
wenzelm@29184
   252
wenzelm@29184
   253
wenzelm@29184
   254
  /* command status */
wenzelm@29184
   255
wenzelm@29417
   256
  val TASK = "task"
wenzelm@29417
   257
wenzelm@37186
   258
  val FORKED = "forked"
wenzelm@37186
   259
  val JOINED = "joined"
wenzelm@29184
   260
  val FAILED = "failed"
wenzelm@29184
   261
  val FINISHED = "finished"
wenzelm@29488
   262
wenzelm@29488
   263
wenzelm@29488
   264
  /* interactive documents */
wenzelm@29488
   265
wenzelm@38414
   266
  val VERSION = "version"
wenzelm@38414
   267
  val EXEC = "exec"
wenzelm@38414
   268
  val ASSIGN = "assign"
wenzelm@29488
   269
  val EDIT = "edit"
wenzelm@29184
   270
wenzelm@27970
   271
wenzelm@27970
   272
  /* messages */
wenzelm@27970
   273
wenzelm@38872
   274
  val Serial = new Long_Property("serial")
wenzelm@27970
   275
wenzelm@29195
   276
  val MESSAGE = "message"
wenzelm@29522
   277
  val CLASS = "class"
wenzelm@29522
   278
wenzelm@29522
   279
  val INIT = "init"
wenzelm@29522
   280
  val STATUS = "status"
wenzelm@39525
   281
  val REPORT = "report"
wenzelm@29522
   282
  val WRITELN = "writeln"
wenzelm@29522
   283
  val TRACING = "tracing"
wenzelm@29522
   284
  val WARNING = "warning"
wenzelm@29522
   285
  val ERROR = "error"
wenzelm@29522
   286
  val SYSTEM = "system"
wenzelm@29522
   287
  val STDOUT = "stdout"
wenzelm@29522
   288
  val EXIT = "exit"
wenzelm@29195
   289
wenzelm@39439
   290
  val NO_REPORT = "no_report"
wenzelm@39439
   291
wenzelm@39171
   292
  val BAD = "bad"
wenzelm@39171
   293
wenzelm@39591
   294
  val READY = "ready"
wenzelm@31384
   295
wenzelm@27970
   296
wenzelm@34119
   297
  /* system data */
wenzelm@27970
   298
wenzelm@38231
   299
  val Data = Markup("data", Nil)
wenzelm@27958
   300
}
wenzelm@38230
   301
wenzelm@38230
   302
sealed case class Markup(name: String, properties: List[(String, String)])