src/Pure/PIDE/markup.scala
author wenzelm
Tue Aug 08 22:13:05 2017 +0200 (22 months ago)
changeset 66379 6392766f3c25
parent 66044 bd7516709051
child 66872 69afe45a6062
permissions -rw-r--r--
maintain "consolidated" status of theory nodes, which means all evals are finished (but not necessarily prints nor imports);
wenzelm@45670
     1
/*  Title:      Pure/PIDE/markup.scala
wenzelm@27958
     2
    Author:     Makarius
wenzelm@27958
     3
wenzelm@56743
     4
Quasi-abstract 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@56743
    12
  /* elements */
wenzelm@56743
    13
wenzelm@56743
    14
  object Elements
wenzelm@56743
    15
  {
wenzelm@56743
    16
    def apply(elems: Set[String]): Elements = new Elements(elems)
wenzelm@56743
    17
    def apply(elems: String*): Elements = apply(Set(elems: _*))
wenzelm@56743
    18
    val empty: Elements = apply()
wenzelm@56743
    19
    val full: Elements =
wenzelm@56743
    20
      new Elements(Set.empty)
wenzelm@56743
    21
      {
wenzelm@56743
    22
        override def apply(elem: String): Boolean = true
wenzelm@56743
    23
        override def toString: String = "Elements.full"
wenzelm@56743
    24
      }
wenzelm@56743
    25
  }
wenzelm@56743
    26
wenzelm@56743
    27
  sealed class Elements private[Markup](private val rep: Set[String])
wenzelm@56743
    28
  {
wenzelm@56743
    29
    def apply(elem: String): Boolean = rep.contains(elem)
wenzelm@56743
    30
    def + (elem: String): Elements = new Elements(rep + elem)
wenzelm@56743
    31
    def ++ (elems: Elements): Elements = new Elements(rep ++ elems.rep)
wenzelm@65176
    32
    def - (elem: String): Elements = new Elements(rep - elem)
wenzelm@65176
    33
    def -- (elems: Elements): Elements = new Elements(rep -- elems.rep)
wenzelm@56743
    34
    override def toString: String = rep.mkString("Elements(", ",", ")")
wenzelm@56743
    35
  }
wenzelm@56743
    36
wenzelm@56743
    37
wenzelm@45666
    38
  /* properties */
wenzelm@29184
    39
wenzelm@29184
    40
  val NAME = "name"
wenzelm@43780
    41
  val Name = new Properties.String(NAME)
wenzelm@42136
    42
wenzelm@29184
    43
  val KIND = "kind"
wenzelm@43780
    44
  val Kind = new Properties.String(KIND)
wenzelm@29184
    45
wenzelm@65937
    46
  val CONTENT = "content"
wenzelm@65937
    47
  val Content = new Properties.String(CONTENT)
wenzelm@65937
    48
wenzelm@60744
    49
  val SERIAL = "serial"
wenzelm@60744
    50
  val Serial = new Properties.Long(SERIAL)
wenzelm@60744
    51
wenzelm@52854
    52
  val INSTANCE = "instance"
wenzelm@52854
    53
  val Instance = new Properties.String(INSTANCE)
wenzelm@52854
    54
wenzelm@29184
    55
wenzelm@50201
    56
  /* basic markup */
wenzelm@29184
    57
wenzelm@45666
    58
  val Empty = Markup("", Nil)
wenzelm@45666
    59
  val Broken = Markup("broken", Nil)
wenzelm@50201
    60
wenzelm@55551
    61
  class Markup_String(val name: String, prop: String)
wenzelm@55551
    62
  {
wenzelm@55551
    63
    private val Prop = new Properties.String(prop)
wenzelm@55551
    64
wenzelm@55551
    65
    def apply(s: String): Markup = Markup(name, Prop(s))
wenzelm@55551
    66
    def unapply(markup: Markup): Option[String] =
wenzelm@55551
    67
      if (markup.name == name) Prop.unapply(markup.properties) else None
wenzelm@55551
    68
  }
wenzelm@55551
    69
wenzelm@55551
    70
  class Markup_Int(val name: String, prop: String)
wenzelm@55551
    71
  {
wenzelm@55551
    72
    private val Prop = new Properties.Int(prop)
wenzelm@55551
    73
wenzelm@55551
    74
    def apply(i: Int): Markup = Markup(name, Prop(i))
wenzelm@55551
    75
    def unapply(markup: Markup): Option[Int] =
wenzelm@55551
    76
      if (markup.name == name) Prop.unapply(markup.properties) else None
wenzelm@55551
    77
  }
wenzelm@55551
    78
wenzelm@60744
    79
  class Markup_Long(val name: String, prop: String)
wenzelm@60744
    80
  {
wenzelm@60744
    81
    private val Prop = new Properties.Long(prop)
wenzelm@60744
    82
wenzelm@60744
    83
    def apply(i: Long): Markup = Markup(name, Prop(i))
wenzelm@60744
    84
    def unapply(markup: Markup): Option[Long] =
wenzelm@60744
    85
      if (markup.name == name) Prop.unapply(markup.properties) else None
wenzelm@60744
    86
  }
wenzelm@60744
    87
wenzelm@50201
    88
wenzelm@50201
    89
  /* formal entities */
wenzelm@50201
    90
wenzelm@50201
    91
  val BINDING = "binding"
wenzelm@50201
    92
  val ENTITY = "entity"
wenzelm@50201
    93
wenzelm@50201
    94
  object Entity
wenzelm@50201
    95
  {
wenzelm@62986
    96
    val Def = new Properties.Long("def")
wenzelm@62986
    97
    val Ref = new Properties.Long("ref")
wenzelm@62986
    98
wenzelm@50201
    99
    def unapply(markup: Markup): Option[(String, String)] =
wenzelm@50201
   100
      markup match {
wenzelm@55551
   101
        case Markup(ENTITY, props) =>
wenzelm@63337
   102
          val kind = Kind.unapply(props).getOrElse("")
wenzelm@63337
   103
          val name = Name.unapply(props).getOrElse("")
wenzelm@63337
   104
          Some((kind, name))
wenzelm@50201
   105
        case _ => None
wenzelm@50201
   106
      }
wenzelm@50201
   107
  }
wenzelm@50201
   108
wenzelm@50201
   109
wenzelm@55672
   110
  /* completion */
wenzelm@55672
   111
wenzelm@55672
   112
  val COMPLETION = "completion"
wenzelm@55914
   113
  val NO_COMPLETION = "no_completion"
wenzelm@55672
   114
wenzelm@55672
   115
wenzelm@50201
   116
  /* position */
wenzelm@50201
   117
wenzelm@50201
   118
  val LINE = "line"
wenzelm@58978
   119
  val END_LINE = "line"
wenzelm@50201
   120
  val OFFSET = "offset"
wenzelm@50201
   121
  val END_OFFSET = "end_offset"
wenzelm@50201
   122
  val FILE = "file"
wenzelm@50201
   123
  val ID = "id"
wenzelm@50201
   124
wenzelm@50201
   125
  val DEF_LINE = "def_line"
wenzelm@50201
   126
  val DEF_OFFSET = "def_offset"
wenzelm@50201
   127
  val DEF_END_OFFSET = "def_end_offset"
wenzelm@50201
   128
  val DEF_FILE = "def_file"
wenzelm@50201
   129
  val DEF_ID = "def_id"
wenzelm@50201
   130
wenzelm@50201
   131
  val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
wenzelm@50201
   132
  val POSITION = "position"
wenzelm@50201
   133
wenzelm@50201
   134
wenzelm@58464
   135
  /* expression */
wenzelm@58464
   136
wenzelm@58464
   137
  val EXPRESSION = "expression"
wenzelm@62806
   138
  object Expression
wenzelm@62806
   139
  {
wenzelm@62806
   140
    def unapply(markup: Markup): Option[String] =
wenzelm@62806
   141
      markup match {
wenzelm@62806
   142
        case Markup(EXPRESSION, Kind(kind)) => Some(kind)
wenzelm@62806
   143
        case Markup(EXPRESSION, _) => Some("")
wenzelm@62806
   144
        case _ => None
wenzelm@62806
   145
      }
wenzelm@62806
   146
  }
wenzelm@58464
   147
wenzelm@58464
   148
wenzelm@58544
   149
  /* citation */
wenzelm@58544
   150
wenzelm@58544
   151
  val CITATION = "citation"
wenzelm@58545
   152
  val Citation = new Markup_String(CITATION, NAME)
wenzelm@58544
   153
wenzelm@58544
   154
wenzelm@55550
   155
  /* embedded languages */
wenzelm@55550
   156
wenzelm@55666
   157
  val Symbols = new Properties.Boolean("symbols")
wenzelm@55666
   158
  val Antiquotes = new Properties.Boolean("antiquotes")
wenzelm@55828
   159
  val Delimited = new Properties.Boolean("delimited")
wenzelm@55615
   160
wenzelm@55550
   161
  val LANGUAGE = "language"
wenzelm@55615
   162
  object Language
wenzelm@55615
   163
  {
wenzelm@55616
   164
    val ML = "ML"
wenzelm@56278
   165
    val SML = "SML"
wenzelm@56843
   166
    val PATH = "path"
wenzelm@55616
   167
    val UNKNOWN = "unknown"
wenzelm@55616
   168
wenzelm@55828
   169
    def unapply(markup: Markup): Option[(String, Boolean, Boolean, Boolean)] =
wenzelm@55615
   170
      markup match {
wenzelm@55615
   171
        case Markup(LANGUAGE, props) =>
wenzelm@55828
   172
          (props, props, props, props) match {
wenzelm@55828
   173
            case (Name(name), Symbols(symbols), Antiquotes(antiquotes), Delimited(delimited)) =>
wenzelm@55828
   174
              Some((name, symbols, antiquotes, delimited))
wenzelm@55615
   175
            case _ => None
wenzelm@55615
   176
          }
wenzelm@55615
   177
        case _ => None
wenzelm@55615
   178
      }
wenzelm@55615
   179
  }
wenzelm@55550
   180
wenzelm@55550
   181
wenzelm@54702
   182
  /* external resources */
wenzelm@50201
   183
wenzelm@50201
   184
  val PATH = "path"
wenzelm@55551
   185
  val Path = new Markup_String(PATH, NAME)
wenzelm@50201
   186
wenzelm@54702
   187
  val URL = "url"
wenzelm@55551
   188
  val Url = new Markup_String(URL, NAME)
wenzelm@54702
   189
wenzelm@61660
   190
  val DOC = "doc"
wenzelm@61660
   191
  val Doc = new Markup_String(DOC, NAME)
wenzelm@61660
   192
wenzelm@50201
   193
wenzelm@50201
   194
  /* pretty printing */
wenzelm@50201
   195
wenzelm@61864
   196
  val Consistent = new Properties.Boolean("consistent")
wenzelm@61862
   197
  val Indent = new Properties.Int("indent")
wenzelm@61864
   198
  val Width = new Properties.Int("width")
wenzelm@61862
   199
wenzelm@61864
   200
  object Block
wenzelm@61864
   201
  {
wenzelm@61864
   202
    val name = "block"
wenzelm@61864
   203
    def apply(c: Boolean, i: Int): Markup =
wenzelm@61864
   204
      Markup(name,
wenzelm@61864
   205
        (if (c) Consistent(c) else Nil) :::
wenzelm@61864
   206
        (if (i != 0) Indent(i) else Nil))
wenzelm@61864
   207
    def unapply(markup: Markup): Option[(Boolean, Int)] =
wenzelm@61864
   208
      if (markup.name == name) {
wenzelm@61864
   209
        val c = Consistent.unapply(markup.properties).getOrElse(false)
wenzelm@61864
   210
        val i = Indent.unapply(markup.properties).getOrElse(0)
wenzelm@61864
   211
        Some((c, i))
wenzelm@61864
   212
      }
wenzelm@61864
   213
      else None
wenzelm@61864
   214
  }
wenzelm@61864
   215
wenzelm@61862
   216
  object Break
wenzelm@61862
   217
  {
wenzelm@61862
   218
    val name = "break"
wenzelm@61864
   219
    def apply(w: Int, i: Int): Markup =
wenzelm@61864
   220
      Markup(name,
wenzelm@61864
   221
        (if (w != 0) Width(w) else Nil) :::
wenzelm@61864
   222
        (if (i != 0) Indent(i) else Nil))
wenzelm@61862
   223
    def unapply(markup: Markup): Option[(Int, Int)] =
wenzelm@61862
   224
      if (markup.name == name) {
wenzelm@61864
   225
        val w = Width.unapply(markup.properties).getOrElse(0)
wenzelm@61864
   226
        val i = Indent.unapply(markup.properties).getOrElse(0)
wenzelm@61864
   227
        Some((w, i))
wenzelm@61862
   228
      }
wenzelm@61862
   229
      else None
wenzelm@61862
   230
  }
wenzelm@50201
   231
wenzelm@51570
   232
  val ITEM = "item"
wenzelm@51574
   233
  val BULLET = "bullet"
wenzelm@51570
   234
wenzelm@50201
   235
  val SEPARATOR = "separator"
wenzelm@50201
   236
wenzelm@50201
   237
wenzelm@56548
   238
  /* text properties */
wenzelm@56548
   239
wenzelm@56548
   240
  val WORDS = "words"
wenzelm@50201
   241
wenzelm@50201
   242
  val HIDDEN = "hidden"
wenzelm@50201
   243
wenzelm@50201
   244
wenzelm@58048
   245
  /* misc entities */
wenzelm@50201
   246
wenzelm@50201
   247
  val CLASS = "class"
wenzelm@50201
   248
  val TYPE_NAME = "type_name"
wenzelm@50201
   249
  val FIXED = "fixed"
wenzelm@53378
   250
  val CASE = "case"
wenzelm@50201
   251
  val CONSTANT = "constant"
wenzelm@50201
   252
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@50201
   253
wenzelm@50201
   254
wenzelm@50201
   255
  /* inner syntax */
wenzelm@50201
   256
wenzelm@50201
   257
  val TFREE = "tfree"
wenzelm@50201
   258
  val TVAR = "tvar"
wenzelm@50201
   259
  val FREE = "free"
wenzelm@50201
   260
  val SKOLEM = "skolem"
wenzelm@50201
   261
  val BOUND = "bound"
wenzelm@50201
   262
  val VAR = "var"
wenzelm@50201
   263
  val NUMERAL = "numeral"
wenzelm@50201
   264
  val LITERAL = "literal"
wenzelm@50201
   265
  val DELIMITER = "delimiter"
wenzelm@50201
   266
  val INNER_STRING = "inner_string"
wenzelm@55033
   267
  val INNER_CARTOUCHE = "inner_cartouche"
wenzelm@50201
   268
  val INNER_COMMENT = "inner_comment"
wenzelm@50201
   269
wenzelm@50201
   270
  val TOKEN_RANGE = "token_range"
wenzelm@50201
   271
wenzelm@50201
   272
  val SORTING = "sorting"
wenzelm@50201
   273
  val TYPING = "typing"
wenzelm@63347
   274
  val CLASS_PARAMETER = "class_parameter"
wenzelm@50201
   275
wenzelm@50201
   276
  val ATTRIBUTE = "attribute"
wenzelm@50201
   277
  val METHOD = "method"
wenzelm@50201
   278
wenzelm@50201
   279
wenzelm@55550
   280
  /* antiquotations */
wenzelm@50201
   281
wenzelm@55526
   282
  val ANTIQUOTED = "antiquoted"
wenzelm@55526
   283
  val ANTIQUOTE = "antiquote"
wenzelm@55526
   284
wenzelm@50201
   285
  val ML_ANTIQUOTATION = "ML_antiquotation"
wenzelm@50201
   286
  val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
wenzelm@50201
   287
  val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
wenzelm@50201
   288
wenzelm@50201
   289
wenzelm@50201
   290
  /* text structure */
wenzelm@50201
   291
wenzelm@50201
   292
  val PARAGRAPH = "paragraph"
wenzelm@50545
   293
  val TEXT_FOLD = "text_fold"
wenzelm@50201
   294
wenzelm@50201
   295
wenzelm@61449
   296
  /* Markdown document structure */
wenzelm@61449
   297
wenzelm@61449
   298
  val MARKDOWN_PARAGRAPH = "markdown_paragraph"
wenzelm@61449
   299
  val Markdown_List = new Markup_String("markdown_list", "kind")
wenzelm@61449
   300
  val Markdown_Item = new Markup_Int("markdown_item", "depth")
wenzelm@61449
   301
wenzelm@61449
   302
wenzelm@60744
   303
  /* ML */
wenzelm@50201
   304
wenzelm@55505
   305
  val ML_KEYWORD1 = "ML_keyword1"
wenzelm@55505
   306
  val ML_KEYWORD2 = "ML_keyword2"
wenzelm@55505
   307
  val ML_KEYWORD3 = "ML_keyword3"
wenzelm@50201
   308
  val ML_DELIMITER = "ML_delimiter"
wenzelm@50201
   309
  val ML_TVAR = "ML_tvar"
wenzelm@50201
   310
  val ML_NUMERAL = "ML_numeral"
wenzelm@50201
   311
  val ML_CHAR = "ML_char"
wenzelm@50201
   312
  val ML_STRING = "ML_string"
wenzelm@50201
   313
  val ML_COMMENT = "ML_comment"
wenzelm@56278
   314
  val SML_STRING = "SML_string"
wenzelm@56278
   315
  val SML_COMMENT = "SML_comment"
wenzelm@50201
   316
wenzelm@50201
   317
  val ML_DEF = "ML_def"
wenzelm@50201
   318
  val ML_OPEN = "ML_open"
wenzelm@55837
   319
  val ML_STRUCTURE = "ML_structure"
wenzelm@50201
   320
  val ML_TYPING = "ML_typing"
wenzelm@50201
   321
wenzelm@60744
   322
  val ML_BREAKPOINT = "ML_breakpoint"
wenzelm@60744
   323
wenzelm@50201
   324
wenzelm@50201
   325
  /* outer syntax */
wenzelm@50201
   326
wenzelm@55744
   327
  val COMMAND = "command"
wenzelm@66044
   328
  val KEYWORD = "keyword"
wenzelm@55744
   329
  val KEYWORD1 = "keyword1"
wenzelm@55744
   330
  val KEYWORD2 = "keyword2"
wenzelm@55765
   331
  val KEYWORD3 = "keyword3"
wenzelm@55919
   332
  val QUASI_KEYWORD = "quasi_keyword"
wenzelm@56202
   333
  val IMPROPER = "improper"
wenzelm@50201
   334
  val OPERATOR = "operator"
wenzelm@50201
   335
  val STRING = "string"
wenzelm@59081
   336
  val ALT_STRING = "alt_string"
wenzelm@50201
   337
  val VERBATIM = "verbatim"
wenzelm@55033
   338
  val CARTOUCHE = "cartouche"
wenzelm@50201
   339
  val COMMENT = "comment"
wenzelm@50201
   340
wenzelm@50201
   341
wenzelm@50201
   342
  /* timing */
wenzelm@50201
   343
wenzelm@50781
   344
  val Elapsed = new Properties.Double("elapsed")
wenzelm@50781
   345
  val CPU = new Properties.Double("cpu")
wenzelm@50781
   346
  val GC = new Properties.Double("gc")
wenzelm@50781
   347
wenzelm@50781
   348
  object Timing_Properties
wenzelm@50781
   349
  {
wenzelm@50781
   350
    def apply(timing: isabelle.Timing): Properties.T =
wenzelm@50781
   351
      Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
wenzelm@51662
   352
wenzelm@50781
   353
    def unapply(props: Properties.T): Option[isabelle.Timing] =
wenzelm@50781
   354
      (props, props, props) match {
wenzelm@50781
   355
        case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
wenzelm@50781
   356
          Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
wenzelm@50781
   357
        case _ => None
wenzelm@50781
   358
      }
wenzelm@50781
   359
  }
wenzelm@50781
   360
wenzelm@50201
   361
  val TIMING = "timing"
wenzelm@50201
   362
wenzelm@50201
   363
  object Timing
wenzelm@50201
   364
  {
wenzelm@50781
   365
    def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
wenzelm@51662
   366
wenzelm@50201
   367
    def unapply(markup: Markup): Option[isabelle.Timing] =
wenzelm@50201
   368
      markup match {
wenzelm@50781
   369
        case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
wenzelm@50201
   370
        case _ => None
wenzelm@50201
   371
      }
wenzelm@50201
   372
  }
wenzelm@50201
   373
wenzelm@50201
   374
wenzelm@65317
   375
  /* process result */
wenzelm@65317
   376
wenzelm@65317
   377
  val Return_Code = new Properties.Int("return_code")
wenzelm@65317
   378
wenzelm@65317
   379
  object Process_Result
wenzelm@65317
   380
  {
wenzelm@65317
   381
    def apply(result: Process_Result): Properties.T =
wenzelm@65317
   382
      Return_Code(result.rc) :::
wenzelm@65317
   383
        (if (result.timing.is_zero) Nil else Timing_Properties(result.timing))
wenzelm@65317
   384
wenzelm@65317
   385
    def unapply(props: Properties.T): Option[Process_Result] =
wenzelm@65317
   386
      props match {
wenzelm@65317
   387
        case Return_Code(rc) =>
wenzelm@65317
   388
          val timing = Timing_Properties.unapply(props).getOrElse(isabelle.Timing.zero)
wenzelm@65317
   389
          Some(isabelle.Process_Result(rc, timing = timing))
wenzelm@65317
   390
        case _ => None
wenzelm@65317
   391
      }
wenzelm@65317
   392
  }
wenzelm@65317
   393
wenzelm@65317
   394
wenzelm@51662
   395
  /* command timing */
wenzelm@51662
   396
wenzelm@51818
   397
  val COMMAND_TIMING = "command_timing"
wenzelm@51662
   398
wenzelm@51662
   399
wenzelm@63474
   400
  /* command indentation */
wenzelm@63474
   401
wenzelm@63474
   402
  object Command_Indent
wenzelm@63474
   403
  {
wenzelm@63474
   404
    val name = "command_indent"
wenzelm@63474
   405
    def unapply(markup: Markup): Option[Int] =
wenzelm@63474
   406
      if (markup.name == name) Indent.unapply(markup.properties) else None
wenzelm@63474
   407
  }
wenzelm@63474
   408
wenzelm@63474
   409
wenzelm@63474
   410
  /* goals */
wenzelm@50201
   411
wenzelm@50543
   412
  val GOAL = "goal"
wenzelm@50201
   413
  val SUBGOAL = "subgoal"
wenzelm@50215
   414
wenzelm@50450
   415
wenzelm@50201
   416
  /* command status */
wenzelm@50201
   417
wenzelm@50201
   418
  val TASK = "task"
wenzelm@50201
   419
wenzelm@50201
   420
  val ACCEPTED = "accepted"
wenzelm@50201
   421
  val FORKED = "forked"
wenzelm@50201
   422
  val JOINED = "joined"
wenzelm@50201
   423
  val RUNNING = "running"
wenzelm@50201
   424
  val FINISHED = "finished"
wenzelm@50201
   425
  val FAILED = "failed"
wenzelm@66379
   426
  val CONSOLIDATED = "consolidated"
wenzelm@50201
   427
wenzelm@50201
   428
wenzelm@50201
   429
  /* interactive documents */
wenzelm@50201
   430
wenzelm@50201
   431
  val VERSION = "version"
wenzelm@50201
   432
  val ASSIGN = "assign"
wenzelm@50201
   433
wenzelm@50201
   434
wenzelm@50201
   435
  /* prover process */
wenzelm@50201
   436
wenzelm@50201
   437
  val PROVER_COMMAND = "prover_command"
wenzelm@50201
   438
  val PROVER_ARG = "prover_arg"
wenzelm@50201
   439
wenzelm@50201
   440
wenzelm@50201
   441
  /* messages */
wenzelm@50201
   442
wenzelm@50201
   443
  val INIT = "init"
wenzelm@50201
   444
  val STATUS = "status"
wenzelm@50201
   445
  val REPORT = "report"
wenzelm@50500
   446
  val RESULT = "result"
wenzelm@50201
   447
  val WRITELN = "writeln"
wenzelm@59184
   448
  val STATE = "state"
wenzelm@59184
   449
  val INFORMATION = "information"
wenzelm@50201
   450
  val TRACING = "tracing"
wenzelm@50201
   451
  val WARNING = "warning"
wenzelm@59203
   452
  val LEGACY = "legacy"
wenzelm@50201
   453
  val ERROR = "error"
wenzelm@50201
   454
  val PROTOCOL = "protocol"
wenzelm@50201
   455
  val SYSTEM = "system"
wenzelm@50201
   456
  val STDOUT = "stdout"
wenzelm@50201
   457
  val STDERR = "stderr"
wenzelm@50201
   458
  val EXIT = "exit"
wenzelm@50201
   459
wenzelm@50201
   460
  val WRITELN_MESSAGE = "writeln_message"
wenzelm@59184
   461
  val STATE_MESSAGE = "state_message"
wenzelm@59184
   462
  val INFORMATION_MESSAGE = "information_message"
wenzelm@50201
   463
  val TRACING_MESSAGE = "tracing_message"
wenzelm@50201
   464
  val WARNING_MESSAGE = "warning_message"
wenzelm@59203
   465
  val LEGACY_MESSAGE = "legacy_message"
wenzelm@50201
   466
  val ERROR_MESSAGE = "error_message"
wenzelm@50201
   467
wenzelm@59184
   468
  val messages = Map(
wenzelm@59184
   469
    WRITELN -> WRITELN_MESSAGE,
wenzelm@59184
   470
    STATE -> STATE_MESSAGE,
wenzelm@59184
   471
    INFORMATION -> INFORMATION_MESSAGE,
wenzelm@59184
   472
    TRACING -> TRACING_MESSAGE,
wenzelm@59184
   473
    WARNING -> WARNING_MESSAGE,
wenzelm@59203
   474
    LEGACY -> LEGACY_MESSAGE,
wenzelm@59184
   475
    ERROR -> ERROR_MESSAGE)
wenzelm@59184
   476
wenzelm@52876
   477
  val message: String => String = messages.withDefault((s: String) => s)
wenzelm@50201
   478
wenzelm@50201
   479
  val NO_REPORT = "no_report"
wenzelm@50201
   480
wenzelm@50201
   481
  val BAD = "bad"
wenzelm@50201
   482
wenzelm@50500
   483
  val INTENSIFY = "intensify"
wenzelm@50500
   484
wenzelm@50500
   485
wenzelm@50500
   486
  /* active areas */
wenzelm@50500
   487
wenzelm@50715
   488
  val BROWSER = "browser"
wenzelm@50500
   489
  val GRAPHVIEW = "graphview"
wenzelm@50500
   490
wenzelm@50500
   491
  val SENDBACK = "sendback"
wenzelm@50500
   492
  val PADDING = "padding"
wenzelm@52697
   493
  val PADDING_LINE = (PADDING, "line")
wenzelm@52697
   494
  val PADDING_COMMAND = (PADDING, "command")
wenzelm@50500
   495
wenzelm@50500
   496
  val DIALOG = "dialog"
wenzelm@50503
   497
  val Result = new Properties.String(RESULT)
wenzelm@50500
   498
wenzelm@63681
   499
  val JEDIT_ACTION = "jedit_action"
wenzelm@63681
   500
wenzelm@50201
   501
wenzelm@50201
   502
  /* protocol message functions */
wenzelm@50201
   503
wenzelm@50201
   504
  val FUNCTION = "function"
wenzelm@50201
   505
  val Function = new Properties.String(FUNCTION)
wenzelm@50201
   506
wenzelm@52563
   507
  val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
wenzelm@50201
   508
  val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
wenzelm@50201
   509
wenzelm@52111
   510
  object Protocol_Handler
wenzelm@52111
   511
  {
wenzelm@52111
   512
    def unapply(props: Properties.T): Option[(String)] =
wenzelm@52111
   513
      props match {
wenzelm@52111
   514
        case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
wenzelm@52111
   515
        case _ => None
wenzelm@52111
   516
      }
wenzelm@52111
   517
  }
wenzelm@52111
   518
wenzelm@52111
   519
  val INVOKE_SCALA = "invoke_scala"
wenzelm@50201
   520
  object Invoke_Scala
wenzelm@50201
   521
  {
wenzelm@50201
   522
    def unapply(props: Properties.T): Option[(String, String)] =
wenzelm@50201
   523
      props match {
wenzelm@52111
   524
        case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
wenzelm@50201
   525
        case _ => None
wenzelm@50201
   526
      }
wenzelm@50201
   527
  }
wenzelm@52111
   528
wenzelm@52111
   529
  val CANCEL_SCALA = "cancel_scala"
wenzelm@50201
   530
  object Cancel_Scala
wenzelm@50201
   531
  {
wenzelm@50201
   532
    def unapply(props: Properties.T): Option[String] =
wenzelm@50201
   533
      props match {
wenzelm@52111
   534
        case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
wenzelm@50201
   535
        case _ => None
wenzelm@50201
   536
      }
wenzelm@50201
   537
  }
wenzelm@50255
   538
wenzelm@50255
   539
  object ML_Statistics
wenzelm@50255
   540
  {
wenzelm@50255
   541
    def unapply(props: Properties.T): Option[Properties.T] =
wenzelm@50255
   542
      props match {
wenzelm@50255
   543
        case (FUNCTION, "ML_statistics") :: stats => Some(stats)
wenzelm@50255
   544
        case _ => None
wenzelm@50255
   545
      }
wenzelm@50255
   546
  }
wenzelm@50975
   547
wenzelm@50975
   548
  object Task_Statistics
wenzelm@50975
   549
  {
wenzelm@50975
   550
    def unapply(props: Properties.T): Option[Properties.T] =
wenzelm@50975
   551
      props match {
wenzelm@50975
   552
        case (FUNCTION, "task_statistics") :: stats => Some(stats)
wenzelm@50975
   553
        case _ => None
wenzelm@50975
   554
      }
wenzelm@50975
   555
  }
lars@55316
   556
wenzelm@59367
   557
  val LOADING_THEORY = "loading_theory"
wenzelm@56616
   558
  object Loading_Theory
wenzelm@56616
   559
  {
wenzelm@56616
   560
    def unapply(props: Properties.T): Option[String] =
wenzelm@56616
   561
      props match {
wenzelm@59367
   562
        case List((FUNCTION, LOADING_THEORY), (NAME, name)) => Some(name)
wenzelm@56616
   563
        case _ => None
wenzelm@56616
   564
      }
wenzelm@56616
   565
  }
wenzelm@56616
   566
wenzelm@65313
   567
  val BUILD_SESSION_FINISHED = "build_session_finished"
wenzelm@65313
   568
  val Build_Session_Finished: Properties.T = List((FUNCTION, BUILD_SESSION_FINISHED))
wenzelm@56616
   569
wenzelm@56864
   570
  val PRINT_OPERATIONS = "print_operations"
wenzelm@56864
   571
wenzelm@55553
   572
wenzelm@60830
   573
  /* debugger output */
wenzelm@60830
   574
wenzelm@60842
   575
  val DEBUGGER_STATE = "debugger_state"
wenzelm@60842
   576
  object Debugger_State
wenzelm@60842
   577
  {
wenzelm@60842
   578
    def unapply(props: Properties.T): Option[String] =
wenzelm@60842
   579
      props match {
wenzelm@60842
   580
        case List((FUNCTION, DEBUGGER_STATE), (NAME, name)) => Some(name)
wenzelm@60842
   581
        case _ => None
wenzelm@60842
   582
      }
wenzelm@60842
   583
  }
wenzelm@60842
   584
wenzelm@60830
   585
  val DEBUGGER_OUTPUT = "debugger_output"
wenzelm@60830
   586
  object Debugger_Output
wenzelm@60830
   587
  {
wenzelm@60834
   588
    def unapply(props: Properties.T): Option[String] =
wenzelm@60830
   589
      props match {
wenzelm@60834
   590
        case List((FUNCTION, DEBUGGER_OUTPUT), (NAME, name)) => Some(name)
wenzelm@60830
   591
        case _ => None
wenzelm@60830
   592
      }
wenzelm@60830
   593
  }
wenzelm@60830
   594
wenzelm@60830
   595
lars@55316
   596
  /* simplifier trace */
lars@55316
   597
wenzelm@57594
   598
  val SIMP_TRACE_PANEL = "simp_trace_panel"
lars@55316
   599
wenzelm@55553
   600
  val SIMP_TRACE_LOG = "simp_trace_log"
wenzelm@55553
   601
  val SIMP_TRACE_STEP = "simp_trace_step"
wenzelm@55553
   602
  val SIMP_TRACE_RECURSE = "simp_trace_recurse"
wenzelm@55553
   603
  val SIMP_TRACE_HINT = "simp_trace_hint"
wenzelm@55553
   604
  val SIMP_TRACE_IGNORE = "simp_trace_ignore"
lars@55316
   605
wenzelm@55553
   606
  val SIMP_TRACE_CANCEL = "simp_trace_cancel"
wenzelm@55553
   607
  object Simp_Trace_Cancel
lars@55316
   608
  {
lars@55316
   609
    def unapply(props: Properties.T): Option[Long] =
lars@55316
   610
      props match {
wenzelm@55553
   611
        case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
lars@55316
   612
        case _ => None
lars@55316
   613
      }
lars@55316
   614
  }
wenzelm@65335
   615
wenzelm@65335
   616
wenzelm@65335
   617
  /* XML data representation */
wenzelm@65335
   618
wenzelm@65335
   619
  def encode: XML.Encode.T[Markup] = (markup: Markup) =>
wenzelm@65335
   620
  {
wenzelm@65335
   621
    import XML.Encode._
wenzelm@65335
   622
    pair(string, properties)((markup.name, markup.properties))
wenzelm@65335
   623
  }
wenzelm@65335
   624
wenzelm@65335
   625
  def decode: XML.Decode.T[Markup] = (body: XML.Body) =>
wenzelm@65335
   626
  {
wenzelm@65335
   627
    import XML.Decode._
wenzelm@65335
   628
    val (name, props) = pair(string, properties)(body)
wenzelm@65335
   629
    Markup(name, props)
wenzelm@65335
   630
  }
wenzelm@45666
   631
}
wenzelm@43721
   632
wenzelm@43721
   633
wenzelm@45666
   634
sealed case class Markup(name: String, properties: Properties.T)
wenzelm@59707
   635
{
wenzelm@59707
   636
  def markup(s: String): String =
wenzelm@59707
   637
    YXML.string_of_tree(XML.Elem(this, List(XML.Text(s))))
wenzelm@64358
   638
wenzelm@64358
   639
  def update_properties(more_props: Properties.T): Markup =
wenzelm@64358
   640
    if (more_props.isEmpty) this
wenzelm@64358
   641
    else Markup(name, (more_props :\ properties) { case (p, ps) => Properties.put(ps, p) })
wenzelm@65753
   642
wenzelm@65753
   643
  def + (entry: Properties.Entry): Markup =
wenzelm@65753
   644
    Markup(name, Properties.put(properties, entry))
wenzelm@59707
   645
}