src/Pure/General/markup.scala
author wenzelm
Sat Jul 09 21:53:27 2011 +0200 (2011-07-09)
changeset 43721 fad8634cee62
parent 43710 7270ae921cf2
child 43746 a41f618c641d
permissions -rw-r--r--
echo prover input via raw_messages, for improved protocol tracing;
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@42202
   100
  object Entity
wenzelm@42202
   101
  {
wenzelm@42202
   102
    def unapply(markup: Markup): Option[(String, String)] =
wenzelm@42202
   103
      markup match {
wenzelm@42202
   104
        case Markup(ENTITY, props @ Kind(kind)) =>
wenzelm@42202
   105
          props match {
wenzelm@42202
   106
            case Name(name) => Some(kind, name)
wenzelm@42202
   107
            case _ => None
wenzelm@42202
   108
          }
wenzelm@42202
   109
        case _ => None
wenzelm@42202
   110
      }
wenzelm@42202
   111
  }
wenzelm@42202
   112
wenzelm@33088
   113
wenzelm@27970
   114
  /* position */
wenzelm@27970
   115
wenzelm@27970
   116
  val LINE = "line"
wenzelm@27970
   117
  val OFFSET = "offset"
wenzelm@27970
   118
  val END_OFFSET = "end_offset"
wenzelm@27970
   119
  val FILE = "file"
wenzelm@27970
   120
  val ID = "id"
wenzelm@27970
   121
wenzelm@42327
   122
  val DEF_LINE = "def_line"
wenzelm@42327
   123
  val DEF_OFFSET = "def_offset"
wenzelm@42327
   124
  val DEF_END_OFFSET = "def_end_offset"
wenzelm@42327
   125
  val DEF_FILE = "def_file"
wenzelm@42327
   126
  val DEF_ID = "def_id"
wenzelm@42327
   127
wenzelm@43710
   128
  val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
wenzelm@43593
   129
  val POSITION = "position"
wenzelm@29205
   130
wenzelm@43593
   131
wenzelm@43593
   132
  /* path */
wenzelm@43593
   133
wenzelm@43593
   134
  val PATH = "path"
wenzelm@43593
   135
wenzelm@43593
   136
  object Path
wenzelm@43593
   137
  {
wenzelm@43593
   138
    def unapply(markup: Markup): Option[String] =
wenzelm@43593
   139
      markup match {
wenzelm@43593
   140
        case Markup(PATH, Name(name)) => Some(name)
wenzelm@43593
   141
        case _ => None
wenzelm@43593
   142
      }
wenzelm@43593
   143
  }
wenzelm@29184
   144
wenzelm@29184
   145
wenzelm@36683
   146
  /* pretty printing */
wenzelm@36683
   147
wenzelm@38724
   148
  val Indent = new Int_Property("indent")
wenzelm@36683
   149
  val BLOCK = "block"
wenzelm@38724
   150
  val Width = new Int_Property("width")
wenzelm@36683
   151
  val BREAK = "break"
wenzelm@36683
   152
wenzelm@36683
   153
wenzelm@33985
   154
  /* hidden text */
wenzelm@33985
   155
wenzelm@33985
   156
  val HIDDEN = "hidden"
wenzelm@33985
   157
wenzelm@33985
   158
wenzelm@29184
   159
  /* logical entities */
wenzelm@29184
   160
wenzelm@43551
   161
  val CLASS = "class"
wenzelm@43552
   162
  val TYPE = "type"
wenzelm@29184
   163
  val FIXED = "fixed"
wenzelm@43552
   164
  val CONSTANT = "constant"
wenzelm@43552
   165
wenzelm@29184
   166
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@29184
   167
wenzelm@29184
   168
wenzelm@29184
   169
  /* inner syntax */
wenzelm@29184
   170
wenzelm@29184
   171
  val TFREE = "tfree"
wenzelm@29184
   172
  val TVAR = "tvar"
wenzelm@29184
   173
  val FREE = "free"
wenzelm@29184
   174
  val SKOLEM = "skolem"
wenzelm@29184
   175
  val BOUND = "bound"
wenzelm@29184
   176
  val VAR = "var"
wenzelm@29184
   177
  val NUM = "num"
wenzelm@29184
   178
  val FLOAT = "float"
wenzelm@29184
   179
  val XNUM = "xnum"
wenzelm@29184
   180
  val XSTR = "xstr"
wenzelm@29184
   181
  val LITERAL = "literal"
wenzelm@43432
   182
  val DELIMITER = "delimiter"
wenzelm@43386
   183
  val INNER_STRING = "inner_string"
wenzelm@29184
   184
  val INNER_COMMENT = "inner_comment"
wenzelm@29184
   185
wenzelm@39168
   186
  val TOKEN_RANGE = "token_range"
wenzelm@39168
   187
wenzelm@29184
   188
  val SORT = "sort"
wenzelm@29184
   189
  val TYP = "typ"
wenzelm@29184
   190
  val TERM = "term"
wenzelm@29184
   191
  val PROP = "prop"
wenzelm@29184
   192
wenzelm@29184
   193
  val ATTRIBUTE = "attribute"
wenzelm@29184
   194
  val METHOD = "method"
wenzelm@29184
   195
wenzelm@29184
   196
wenzelm@29184
   197
  /* embedded source text */
wenzelm@29184
   198
wenzelm@29184
   199
  val ML_SOURCE = "ML_source"
wenzelm@29184
   200
  val DOC_SOURCE = "doc_source"
wenzelm@29184
   201
wenzelm@29184
   202
  val ANTIQ = "antiq"
wenzelm@43560
   203
  val ML_ANTIQUOTATION = "ML antiquotation"
wenzelm@43564
   204
  val DOCUMENT_ANTIQUOTATION = "document antiquotation"
wenzelm@43564
   205
  val DOCUMENT_ANTIQUOTATION_OPTION = "document antiquotation option"
wenzelm@29184
   206
wenzelm@29184
   207
wenzelm@30615
   208
  /* ML syntax */
wenzelm@30615
   209
wenzelm@30615
   210
  val ML_KEYWORD = "ML_keyword"
wenzelm@37195
   211
  val ML_DELIMITER = "ML_delimiter"
wenzelm@30615
   212
  val ML_IDENT = "ML_ident"
wenzelm@30615
   213
  val ML_TVAR = "ML_tvar"
wenzelm@30615
   214
  val ML_NUMERAL = "ML_numeral"
wenzelm@30615
   215
  val ML_CHAR = "ML_char"
wenzelm@30615
   216
  val ML_STRING = "ML_string"
wenzelm@30615
   217
  val ML_COMMENT = "ML_comment"
wenzelm@30615
   218
  val ML_MALFORMED = "ML_malformed"
wenzelm@30615
   219
wenzelm@30702
   220
  val ML_DEF = "ML_def"
wenzelm@31472
   221
  val ML_OPEN = "ML_open"
wenzelm@31472
   222
  val ML_STRUCT = "ML_struct"
wenzelm@30702
   223
  val ML_TYPING = "ML_typing"
wenzelm@30702
   224
wenzelm@30615
   225
wenzelm@29184
   226
  /* outer syntax */
wenzelm@29184
   227
wenzelm@29184
   228
  val KEYWORD_DECL = "keyword_decl"
wenzelm@29184
   229
  val COMMAND_DECL = "command_decl"
wenzelm@29184
   230
wenzelm@29184
   231
  val KEYWORD = "keyword"
wenzelm@37194
   232
  val OPERATOR = "operator"
wenzelm@29184
   233
  val COMMAND = "command"
wenzelm@29184
   234
  val IDENT = "ident"
wenzelm@29184
   235
  val STRING = "string"
wenzelm@29184
   236
  val ALTSTRING = "altstring"
wenzelm@29184
   237
  val VERBATIM = "verbatim"
wenzelm@29184
   238
  val COMMENT = "comment"
wenzelm@29184
   239
  val CONTROL = "control"
wenzelm@29184
   240
  val MALFORMED = "malformed"
wenzelm@29184
   241
wenzelm@29185
   242
  val COMMAND_SPAN = "command_span"
wenzelm@29185
   243
  val IGNORED_SPAN = "ignored_span"
wenzelm@29185
   244
  val MALFORMED_SPAN = "malformed_span"
wenzelm@29185
   245
wenzelm@29184
   246
wenzelm@43673
   247
  /* theory loader */
wenzelm@43673
   248
wenzelm@43673
   249
  val LOADED_THEORY = "loaded_theory"
wenzelm@43673
   250
wenzelm@43673
   251
wenzelm@40394
   252
  /* timing */
wenzelm@40394
   253
wenzelm@40394
   254
  val TIMING = "timing"
wenzelm@40394
   255
  val ELAPSED = "elapsed"
wenzelm@40394
   256
  val CPU = "cpu"
wenzelm@40394
   257
  val GC = "gc"
wenzelm@40394
   258
wenzelm@40394
   259
  object Timing
wenzelm@40394
   260
  {
wenzelm@40394
   261
    def apply(timing: isabelle.Timing): Markup =
wenzelm@40394
   262
      Markup(TIMING, List(
wenzelm@40848
   263
        (ELAPSED, Double(timing.elapsed.seconds)),
wenzelm@40848
   264
        (CPU, Double(timing.cpu.seconds)),
wenzelm@40848
   265
        (GC, Double(timing.gc.seconds))))
wenzelm@40394
   266
    def unapply(markup: Markup): Option[isabelle.Timing] =
wenzelm@40394
   267
      markup match {
wenzelm@40394
   268
        case Markup(TIMING, List(
wenzelm@40848
   269
          (ELAPSED, Double(elapsed)), (CPU, Double(cpu)), (GC, Double(gc)))) =>
wenzelm@40848
   270
            Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
wenzelm@40394
   271
        case _ => None
wenzelm@40394
   272
      }
wenzelm@40394
   273
  }
wenzelm@40394
   274
wenzelm@40394
   275
wenzelm@29184
   276
  /* toplevel */
wenzelm@29184
   277
wenzelm@38721
   278
  val SUBGOALS = "subgoals"
wenzelm@38721
   279
  val PROOF_STATE = "proof_state"
wenzelm@38721
   280
wenzelm@29184
   281
  val STATE = "state"
wenzelm@29184
   282
  val SUBGOAL = "subgoal"
wenzelm@29184
   283
  val SENDBACK = "sendback"
wenzelm@29184
   284
  val HILITE = "hilite"
wenzelm@29184
   285
wenzelm@29184
   286
wenzelm@29184
   287
  /* command status */
wenzelm@29184
   288
wenzelm@29417
   289
  val TASK = "task"
wenzelm@29417
   290
wenzelm@37186
   291
  val FORKED = "forked"
wenzelm@37186
   292
  val JOINED = "joined"
wenzelm@29184
   293
  val FAILED = "failed"
wenzelm@29184
   294
  val FINISHED = "finished"
wenzelm@29488
   295
wenzelm@29488
   296
wenzelm@29488
   297
  /* interactive documents */
wenzelm@29488
   298
wenzelm@38414
   299
  val VERSION = "version"
wenzelm@38414
   300
  val EXEC = "exec"
wenzelm@38414
   301
  val ASSIGN = "assign"
wenzelm@29488
   302
  val EDIT = "edit"
wenzelm@29184
   303
wenzelm@27970
   304
wenzelm@43721
   305
  /* prover process */
wenzelm@43721
   306
wenzelm@43721
   307
  val PROVER_COMMAND = "prover_command"
wenzelm@43721
   308
  val PROVER_ARG = "prover_arg"
wenzelm@43721
   309
wenzelm@43721
   310
wenzelm@27970
   311
  /* messages */
wenzelm@27970
   312
wenzelm@38872
   313
  val Serial = new Long_Property("serial")
wenzelm@27970
   314
wenzelm@29195
   315
  val MESSAGE = "message"
wenzelm@29522
   316
wenzelm@29522
   317
  val INIT = "init"
wenzelm@29522
   318
  val STATUS = "status"
wenzelm@39525
   319
  val REPORT = "report"
wenzelm@29522
   320
  val WRITELN = "writeln"
wenzelm@29522
   321
  val TRACING = "tracing"
wenzelm@29522
   322
  val WARNING = "warning"
wenzelm@29522
   323
  val ERROR = "error"
wenzelm@29522
   324
  val SYSTEM = "system"
wenzelm@29522
   325
  val STDOUT = "stdout"
wenzelm@29522
   326
  val EXIT = "exit"
wenzelm@29195
   327
wenzelm@39439
   328
  val NO_REPORT = "no_report"
wenzelm@39439
   329
wenzelm@39171
   330
  val BAD = "bad"
wenzelm@39171
   331
wenzelm@39591
   332
  val READY = "ready"
wenzelm@31384
   333
wenzelm@27970
   334
wenzelm@34119
   335
  /* system data */
wenzelm@27970
   336
wenzelm@38231
   337
  val Data = Markup("data", Nil)
wenzelm@27958
   338
}
wenzelm@38230
   339
wenzelm@38230
   340
sealed case class Markup(name: String, properties: List[(String, String)])