src/Pure/General/markup.scala
author wenzelm
Wed Aug 25 22:37:53 2010 +0200 (2010-08-25)
changeset 38722 ba31936497c2
parent 38721 ca8b14fa0d0d
child 38724 d1feec02cf02
permissions -rw-r--r--
organized markup properties via apply/unapply patterns;
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@33088
    72
  val ENTITY = "entity"
wenzelm@33088
    73
  val DEF = "def"
wenzelm@33088
    74
  val REF = "ref"
wenzelm@33088
    75
wenzelm@33088
    76
wenzelm@27970
    77
  /* position */
wenzelm@27970
    78
wenzelm@27970
    79
  val LINE = "line"
wenzelm@27970
    80
  val COLUMN = "column"
wenzelm@27970
    81
  val OFFSET = "offset"
wenzelm@27970
    82
  val END_LINE = "end_line"
wenzelm@27970
    83
  val END_COLUMN = "end_column"
wenzelm@27970
    84
  val END_OFFSET = "end_offset"
wenzelm@27970
    85
  val FILE = "file"
wenzelm@27970
    86
  val ID = "id"
wenzelm@27970
    87
wenzelm@32450
    88
  val POSITION_PROPERTIES =
wenzelm@32450
    89
    Set(LINE, COLUMN, OFFSET, END_LINE, END_COLUMN, END_OFFSET, FILE, ID)
wenzelm@29205
    90
wenzelm@29184
    91
  val POSITION = "position"
wenzelm@29184
    92
  val LOCATION = "location"
wenzelm@29184
    93
wenzelm@29184
    94
wenzelm@36683
    95
  /* pretty printing */
wenzelm@36683
    96
wenzelm@36683
    97
  val INDENT = "indent"
wenzelm@36683
    98
  val BLOCK = "block"
wenzelm@36683
    99
  val WIDTH = "width"
wenzelm@36683
   100
  val BREAK = "break"
wenzelm@36683
   101
wenzelm@36683
   102
wenzelm@33985
   103
  /* hidden text */
wenzelm@33985
   104
wenzelm@33985
   105
  val HIDDEN = "hidden"
wenzelm@33985
   106
wenzelm@33985
   107
wenzelm@29184
   108
  /* logical entities */
wenzelm@29184
   109
wenzelm@29184
   110
  val TCLASS = "tclass"
wenzelm@29184
   111
  val TYCON = "tycon"
wenzelm@29184
   112
  val FIXED_DECL = "fixed_decl"
wenzelm@29184
   113
  val FIXED = "fixed"
wenzelm@29184
   114
  val CONST_DECL = "const_decl"
wenzelm@29184
   115
  val CONST = "const"
wenzelm@29184
   116
  val FACT_DECL = "fact_decl"
wenzelm@29184
   117
  val FACT = "fact"
wenzelm@29184
   118
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@29184
   119
  val LOCAL_FACT_DECL = "local_fact_decl"
wenzelm@29184
   120
  val LOCAL_FACT = "local_fact"
wenzelm@29184
   121
wenzelm@29184
   122
wenzelm@29184
   123
  /* inner syntax */
wenzelm@29184
   124
wenzelm@29184
   125
  val TFREE = "tfree"
wenzelm@29184
   126
  val TVAR = "tvar"
wenzelm@29184
   127
  val FREE = "free"
wenzelm@29184
   128
  val SKOLEM = "skolem"
wenzelm@29184
   129
  val BOUND = "bound"
wenzelm@29184
   130
  val VAR = "var"
wenzelm@29184
   131
  val NUM = "num"
wenzelm@29184
   132
  val FLOAT = "float"
wenzelm@29184
   133
  val XNUM = "xnum"
wenzelm@29184
   134
  val XSTR = "xstr"
wenzelm@29184
   135
  val LITERAL = "literal"
wenzelm@29184
   136
  val INNER_COMMENT = "inner_comment"
wenzelm@29184
   137
wenzelm@29184
   138
  val SORT = "sort"
wenzelm@29184
   139
  val TYP = "typ"
wenzelm@29184
   140
  val TERM = "term"
wenzelm@29184
   141
  val PROP = "prop"
wenzelm@29184
   142
wenzelm@29184
   143
  val ATTRIBUTE = "attribute"
wenzelm@29184
   144
  val METHOD = "method"
wenzelm@29184
   145
wenzelm@29184
   146
wenzelm@29184
   147
  /* embedded source text */
wenzelm@29184
   148
wenzelm@29184
   149
  val ML_SOURCE = "ML_source"
wenzelm@29184
   150
  val DOC_SOURCE = "doc_source"
wenzelm@29184
   151
wenzelm@29184
   152
  val ANTIQ = "antiq"
wenzelm@29184
   153
  val ML_ANTIQ = "ML_antiq"
wenzelm@29184
   154
  val DOC_ANTIQ = "doc_antiq"
wenzelm@29184
   155
wenzelm@29184
   156
wenzelm@30615
   157
  /* ML syntax */
wenzelm@30615
   158
wenzelm@30615
   159
  val ML_KEYWORD = "ML_keyword"
wenzelm@37195
   160
  val ML_DELIMITER = "ML_delimiter"
wenzelm@30615
   161
  val ML_IDENT = "ML_ident"
wenzelm@30615
   162
  val ML_TVAR = "ML_tvar"
wenzelm@30615
   163
  val ML_NUMERAL = "ML_numeral"
wenzelm@30615
   164
  val ML_CHAR = "ML_char"
wenzelm@30615
   165
  val ML_STRING = "ML_string"
wenzelm@30615
   166
  val ML_COMMENT = "ML_comment"
wenzelm@30615
   167
  val ML_MALFORMED = "ML_malformed"
wenzelm@30615
   168
wenzelm@30702
   169
  val ML_DEF = "ML_def"
wenzelm@31472
   170
  val ML_OPEN = "ML_open"
wenzelm@31472
   171
  val ML_STRUCT = "ML_struct"
wenzelm@30702
   172
  val ML_REF = "ML_ref"
wenzelm@30702
   173
  val ML_TYPING = "ML_typing"
wenzelm@30702
   174
wenzelm@30615
   175
wenzelm@29184
   176
  /* outer syntax */
wenzelm@29184
   177
wenzelm@29184
   178
  val KEYWORD_DECL = "keyword_decl"
wenzelm@29184
   179
  val COMMAND_DECL = "command_decl"
wenzelm@29184
   180
wenzelm@29184
   181
  val KEYWORD = "keyword"
wenzelm@37194
   182
  val OPERATOR = "operator"
wenzelm@29184
   183
  val COMMAND = "command"
wenzelm@29184
   184
  val IDENT = "ident"
wenzelm@29184
   185
  val STRING = "string"
wenzelm@29184
   186
  val ALTSTRING = "altstring"
wenzelm@29184
   187
  val VERBATIM = "verbatim"
wenzelm@29184
   188
  val COMMENT = "comment"
wenzelm@29184
   189
  val CONTROL = "control"
wenzelm@29184
   190
  val MALFORMED = "malformed"
wenzelm@29184
   191
wenzelm@29185
   192
  val COMMAND_SPAN = "command_span"
wenzelm@29185
   193
  val IGNORED_SPAN = "ignored_span"
wenzelm@29185
   194
  val MALFORMED_SPAN = "malformed_span"
wenzelm@29185
   195
wenzelm@29184
   196
wenzelm@29184
   197
  /* toplevel */
wenzelm@29184
   198
wenzelm@38721
   199
  val SUBGOALS = "subgoals"
wenzelm@38721
   200
  val PROOF_STATE = "proof_state"
wenzelm@38721
   201
wenzelm@29184
   202
  val STATE = "state"
wenzelm@29184
   203
  val SUBGOAL = "subgoal"
wenzelm@29184
   204
  val SENDBACK = "sendback"
wenzelm@29184
   205
  val HILITE = "hilite"
wenzelm@29184
   206
wenzelm@29184
   207
wenzelm@29184
   208
  /* command status */
wenzelm@29184
   209
wenzelm@29417
   210
  val TASK = "task"
wenzelm@29417
   211
wenzelm@37186
   212
  val FORKED = "forked"
wenzelm@37186
   213
  val JOINED = "joined"
wenzelm@29184
   214
  val FAILED = "failed"
wenzelm@29184
   215
  val FINISHED = "finished"
wenzelm@29488
   216
wenzelm@29488
   217
wenzelm@29488
   218
  /* interactive documents */
wenzelm@29488
   219
wenzelm@38414
   220
  val VERSION = "version"
wenzelm@38414
   221
  val EXEC = "exec"
wenzelm@38414
   222
  val ASSIGN = "assign"
wenzelm@29488
   223
  val EDIT = "edit"
wenzelm@29184
   224
wenzelm@27970
   225
wenzelm@27970
   226
  /* messages */
wenzelm@27970
   227
wenzelm@27970
   228
  val PID = "pid"
wenzelm@27970
   229
wenzelm@29195
   230
  val MESSAGE = "message"
wenzelm@29522
   231
  val CLASS = "class"
wenzelm@29522
   232
wenzelm@29522
   233
  val INIT = "init"
wenzelm@29522
   234
  val STATUS = "status"
wenzelm@38236
   235
  val REPORT = "report"
wenzelm@29522
   236
  val WRITELN = "writeln"
wenzelm@29522
   237
  val TRACING = "tracing"
wenzelm@29522
   238
  val WARNING = "warning"
wenzelm@29522
   239
  val ERROR = "error"
wenzelm@29522
   240
  val DEBUG = "debug"
wenzelm@29522
   241
  val SYSTEM = "system"
wenzelm@38259
   242
  val INPUT = "input"
wenzelm@29522
   243
  val STDIN = "stdin"
wenzelm@29522
   244
  val STDOUT = "stdout"
wenzelm@29522
   245
  val SIGNAL = "signal"
wenzelm@29522
   246
  val EXIT = "exit"
wenzelm@29195
   247
wenzelm@38231
   248
  val Ready = Markup("ready", Nil)
wenzelm@31384
   249
wenzelm@27970
   250
wenzelm@34119
   251
  /* system data */
wenzelm@27970
   252
wenzelm@38231
   253
  val Data = Markup("data", Nil)
wenzelm@27958
   254
}
wenzelm@38230
   255
wenzelm@38230
   256
sealed case class Markup(name: String, properties: List[(String, String)])