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