src/Pure/General/markup.scala
author wenzelm
Tue Aug 31 23:28:21 2010 +0200 (2010-08-31 ago)
changeset 38887 1261481ef5e5
parent 38872 26c505765024
child 39168 e3ac771235f7
permissions -rw-r--r--
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
Position.Id_Range convenience;
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@38414
    14
  object Int {
wenzelm@38414
    15
    def apply(i: scala.Int): String = i.toString
wenzelm@38414
    16
    def unapply(s: String): Option[scala.Int] =
wenzelm@38414
    17
      try { Some(Integer.parseInt(s)) }
wenzelm@38414
    18
      catch { case _: NumberFormatException => None }
wenzelm@38414
    19
  }
wenzelm@38414
    20
wenzelm@38414
    21
  object Long {
wenzelm@38414
    22
    def apply(i: scala.Long): String = i.toString
wenzelm@38414
    23
    def unapply(s: String): Option[scala.Long] =
wenzelm@38414
    24
      try { Some(java.lang.Long.parseLong(s)) }
wenzelm@38414
    25
      catch { case _: NumberFormatException => None }
wenzelm@38414
    26
  }
wenzelm@38414
    27
wenzelm@38414
    28
wenzelm@38722
    29
  /* named properties */
wenzelm@36683
    30
wenzelm@38722
    31
  class Property(val name: String)
wenzelm@38355
    32
  {
wenzelm@38722
    33
    def apply(value: String): List[(String, String)] = List((name, value))
wenzelm@38722
    34
    def unapply(props: List[(String, String)]): Option[String] =
wenzelm@38722
    35
      props.find(_._1 == name).map(_._2)
wenzelm@38355
    36
  }
wenzelm@38355
    37
wenzelm@38722
    38
  class Int_Property(name: String)
wenzelm@36683
    39
  {
wenzelm@38722
    40
    def apply(value: scala.Int): List[(String, String)] = List((name, Int(value)))
wenzelm@38722
    41
    def unapply(props: List[(String, String)]): Option[Int] =
wenzelm@38722
    42
      props.find(_._1 == name) match {
wenzelm@38722
    43
        case None => None
wenzelm@38722
    44
        case Some((_, value)) => Int.unapply(value)
wenzelm@38722
    45
      }
wenzelm@38722
    46
  }
wenzelm@38722
    47
wenzelm@38722
    48
  class Long_Property(name: String)
wenzelm@38722
    49
  {
wenzelm@38722
    50
    def apply(value: scala.Long): List[(String, String)] = List((name, Long(value)))
wenzelm@38722
    51
    def unapply(props: List[(String, String)]): Option[Long] =
wenzelm@38722
    52
      props.find(_._1 == name) match {
wenzelm@38722
    53
        case None => None
wenzelm@38722
    54
        case Some((_, value)) => Long.unapply(value)
wenzelm@38722
    55
      }
wenzelm@36683
    56
  }
wenzelm@36683
    57
wenzelm@36683
    58
wenzelm@38474
    59
  /* empty */
wenzelm@38474
    60
wenzelm@38474
    61
  val Empty = Markup("", Nil)
wenzelm@38474
    62
wenzelm@38474
    63
wenzelm@38721
    64
  /* misc properties */
wenzelm@29184
    65
wenzelm@29184
    66
  val NAME = "name"
wenzelm@29184
    67
  val KIND = "kind"
wenzelm@29184
    68
wenzelm@29184
    69
wenzelm@33088
    70
  /* formal entities */
wenzelm@33088
    71
wenzelm@38887
    72
  val BINDING = "binding"
wenzelm@33088
    73
  val ENTITY = "entity"
wenzelm@33088
    74
  val DEF = "def"
wenzelm@33088
    75
  val REF = "ref"
wenzelm@33088
    76
wenzelm@33088
    77
wenzelm@27970
    78
  /* position */
wenzelm@27970
    79
wenzelm@27970
    80
  val LINE = "line"
wenzelm@27970
    81
  val COLUMN = "column"
wenzelm@27970
    82
  val OFFSET = "offset"
wenzelm@27970
    83
  val END_LINE = "end_line"
wenzelm@27970
    84
  val END_COLUMN = "end_column"
wenzelm@27970
    85
  val END_OFFSET = "end_offset"
wenzelm@27970
    86
  val FILE = "file"
wenzelm@27970
    87
  val ID = "id"
wenzelm@27970
    88
wenzelm@32450
    89
  val POSITION_PROPERTIES =
wenzelm@32450
    90
    Set(LINE, COLUMN, OFFSET, END_LINE, END_COLUMN, END_OFFSET, FILE, ID)
wenzelm@29205
    91
wenzelm@29184
    92
  val POSITION = "position"
wenzelm@29184
    93
  val LOCATION = "location"
wenzelm@29184
    94
wenzelm@29184
    95
wenzelm@36683
    96
  /* pretty printing */
wenzelm@36683
    97
wenzelm@38724
    98
  val Indent = new Int_Property("indent")
wenzelm@36683
    99
  val BLOCK = "block"
wenzelm@38724
   100
  val Width = new Int_Property("width")
wenzelm@36683
   101
  val BREAK = "break"
wenzelm@36683
   102
wenzelm@36683
   103
wenzelm@33985
   104
  /* hidden text */
wenzelm@33985
   105
wenzelm@33985
   106
  val HIDDEN = "hidden"
wenzelm@33985
   107
wenzelm@33985
   108
wenzelm@29184
   109
  /* logical entities */
wenzelm@29184
   110
wenzelm@29184
   111
  val TCLASS = "tclass"
wenzelm@29184
   112
  val TYCON = "tycon"
wenzelm@29184
   113
  val FIXED_DECL = "fixed_decl"
wenzelm@29184
   114
  val FIXED = "fixed"
wenzelm@29184
   115
  val CONST_DECL = "const_decl"
wenzelm@29184
   116
  val CONST = "const"
wenzelm@29184
   117
  val FACT_DECL = "fact_decl"
wenzelm@29184
   118
  val FACT = "fact"
wenzelm@29184
   119
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@29184
   120
  val LOCAL_FACT_DECL = "local_fact_decl"
wenzelm@29184
   121
  val LOCAL_FACT = "local_fact"
wenzelm@29184
   122
wenzelm@29184
   123
wenzelm@29184
   124
  /* inner syntax */
wenzelm@29184
   125
wenzelm@29184
   126
  val TFREE = "tfree"
wenzelm@29184
   127
  val TVAR = "tvar"
wenzelm@29184
   128
  val FREE = "free"
wenzelm@29184
   129
  val SKOLEM = "skolem"
wenzelm@29184
   130
  val BOUND = "bound"
wenzelm@29184
   131
  val VAR = "var"
wenzelm@29184
   132
  val NUM = "num"
wenzelm@29184
   133
  val FLOAT = "float"
wenzelm@29184
   134
  val XNUM = "xnum"
wenzelm@29184
   135
  val XSTR = "xstr"
wenzelm@29184
   136
  val LITERAL = "literal"
wenzelm@29184
   137
  val INNER_COMMENT = "inner_comment"
wenzelm@29184
   138
wenzelm@29184
   139
  val SORT = "sort"
wenzelm@29184
   140
  val TYP = "typ"
wenzelm@29184
   141
  val TERM = "term"
wenzelm@29184
   142
  val PROP = "prop"
wenzelm@29184
   143
wenzelm@29184
   144
  val ATTRIBUTE = "attribute"
wenzelm@29184
   145
  val METHOD = "method"
wenzelm@29184
   146
wenzelm@29184
   147
wenzelm@29184
   148
  /* embedded source text */
wenzelm@29184
   149
wenzelm@29184
   150
  val ML_SOURCE = "ML_source"
wenzelm@29184
   151
  val DOC_SOURCE = "doc_source"
wenzelm@29184
   152
wenzelm@29184
   153
  val ANTIQ = "antiq"
wenzelm@29184
   154
  val ML_ANTIQ = "ML_antiq"
wenzelm@29184
   155
  val DOC_ANTIQ = "doc_antiq"
wenzelm@29184
   156
wenzelm@29184
   157
wenzelm@30615
   158
  /* ML syntax */
wenzelm@30615
   159
wenzelm@30615
   160
  val ML_KEYWORD = "ML_keyword"
wenzelm@37195
   161
  val ML_DELIMITER = "ML_delimiter"
wenzelm@30615
   162
  val ML_IDENT = "ML_ident"
wenzelm@30615
   163
  val ML_TVAR = "ML_tvar"
wenzelm@30615
   164
  val ML_NUMERAL = "ML_numeral"
wenzelm@30615
   165
  val ML_CHAR = "ML_char"
wenzelm@30615
   166
  val ML_STRING = "ML_string"
wenzelm@30615
   167
  val ML_COMMENT = "ML_comment"
wenzelm@30615
   168
  val ML_MALFORMED = "ML_malformed"
wenzelm@30615
   169
wenzelm@30702
   170
  val ML_DEF = "ML_def"
wenzelm@31472
   171
  val ML_OPEN = "ML_open"
wenzelm@31472
   172
  val ML_STRUCT = "ML_struct"
wenzelm@30702
   173
  val ML_REF = "ML_ref"
wenzelm@30702
   174
  val ML_TYPING = "ML_typing"
wenzelm@30702
   175
wenzelm@30615
   176
wenzelm@29184
   177
  /* outer syntax */
wenzelm@29184
   178
wenzelm@29184
   179
  val KEYWORD_DECL = "keyword_decl"
wenzelm@29184
   180
  val COMMAND_DECL = "command_decl"
wenzelm@29184
   181
wenzelm@29184
   182
  val KEYWORD = "keyword"
wenzelm@37194
   183
  val OPERATOR = "operator"
wenzelm@29184
   184
  val COMMAND = "command"
wenzelm@29184
   185
  val IDENT = "ident"
wenzelm@29184
   186
  val STRING = "string"
wenzelm@29184
   187
  val ALTSTRING = "altstring"
wenzelm@29184
   188
  val VERBATIM = "verbatim"
wenzelm@29184
   189
  val COMMENT = "comment"
wenzelm@29184
   190
  val CONTROL = "control"
wenzelm@29184
   191
  val MALFORMED = "malformed"
wenzelm@29184
   192
wenzelm@29185
   193
  val COMMAND_SPAN = "command_span"
wenzelm@29185
   194
  val IGNORED_SPAN = "ignored_span"
wenzelm@29185
   195
  val MALFORMED_SPAN = "malformed_span"
wenzelm@29185
   196
wenzelm@29184
   197
wenzelm@29184
   198
  /* toplevel */
wenzelm@29184
   199
wenzelm@38721
   200
  val SUBGOALS = "subgoals"
wenzelm@38721
   201
  val PROOF_STATE = "proof_state"
wenzelm@38721
   202
wenzelm@29184
   203
  val STATE = "state"
wenzelm@29184
   204
  val SUBGOAL = "subgoal"
wenzelm@29184
   205
  val SENDBACK = "sendback"
wenzelm@29184
   206
  val HILITE = "hilite"
wenzelm@29184
   207
wenzelm@29184
   208
wenzelm@29184
   209
  /* command status */
wenzelm@29184
   210
wenzelm@29417
   211
  val TASK = "task"
wenzelm@29417
   212
wenzelm@37186
   213
  val FORKED = "forked"
wenzelm@37186
   214
  val JOINED = "joined"
wenzelm@29184
   215
  val FAILED = "failed"
wenzelm@29184
   216
  val FINISHED = "finished"
wenzelm@29488
   217
wenzelm@29488
   218
wenzelm@29488
   219
  /* interactive documents */
wenzelm@29488
   220
wenzelm@38414
   221
  val VERSION = "version"
wenzelm@38414
   222
  val EXEC = "exec"
wenzelm@38414
   223
  val ASSIGN = "assign"
wenzelm@29488
   224
  val EDIT = "edit"
wenzelm@29184
   225
wenzelm@27970
   226
wenzelm@27970
   227
  /* messages */
wenzelm@27970
   228
wenzelm@27970
   229
  val PID = "pid"
wenzelm@38872
   230
  val Serial = new Long_Property("serial")
wenzelm@27970
   231
wenzelm@29195
   232
  val MESSAGE = "message"
wenzelm@29522
   233
  val CLASS = "class"
wenzelm@29522
   234
wenzelm@29522
   235
  val INIT = "init"
wenzelm@29522
   236
  val STATUS = "status"
wenzelm@38236
   237
  val REPORT = "report"
wenzelm@29522
   238
  val WRITELN = "writeln"
wenzelm@29522
   239
  val TRACING = "tracing"
wenzelm@29522
   240
  val WARNING = "warning"
wenzelm@29522
   241
  val ERROR = "error"
wenzelm@29522
   242
  val DEBUG = "debug"
wenzelm@29522
   243
  val SYSTEM = "system"
wenzelm@38259
   244
  val INPUT = "input"
wenzelm@29522
   245
  val STDIN = "stdin"
wenzelm@29522
   246
  val STDOUT = "stdout"
wenzelm@29522
   247
  val SIGNAL = "signal"
wenzelm@29522
   248
  val EXIT = "exit"
wenzelm@29195
   249
wenzelm@38231
   250
  val Ready = Markup("ready", Nil)
wenzelm@31384
   251
wenzelm@27970
   252
wenzelm@34119
   253
  /* system data */
wenzelm@27970
   254
wenzelm@38231
   255
  val Data = Markup("data", Nil)
wenzelm@27958
   256
}
wenzelm@38230
   257
wenzelm@38230
   258
sealed case class Markup(name: String, properties: List[(String, String)])