src/Pure/PIDE/markup.scala
author wenzelm
Sat Feb 22 20:52:43 2014 +0100 (2014-02-22 ago)
changeset 55672 5e25cc741ab9
parent 55666 cc350eb1087e
child 55687 78c83cd477c1
permissions -rw-r--r--
support for completion within the formal context;
tuned signature;
wenzelm@45670
     1
/*  Title:      Pure/PIDE/markup.scala
wenzelm@45673
     2
    Module:     PIDE
wenzelm@27958
     3
    Author:     Makarius
wenzelm@27958
     4
wenzelm@50201
     5
Isabelle-specific implementation of quasi-abstract markup elements.
wenzelm@27958
     6
*/
wenzelm@27958
     7
wenzelm@27958
     8
package isabelle
wenzelm@27958
     9
wenzelm@27970
    10
wenzelm@32450
    11
object Markup
wenzelm@32450
    12
{
wenzelm@45666
    13
  /* properties */
wenzelm@29184
    14
wenzelm@29184
    15
  val NAME = "name"
wenzelm@43780
    16
  val Name = new Properties.String(NAME)
wenzelm@42136
    17
wenzelm@29184
    18
  val KIND = "kind"
wenzelm@43780
    19
  val Kind = new Properties.String(KIND)
wenzelm@29184
    20
wenzelm@52854
    21
  val INSTANCE = "instance"
wenzelm@52854
    22
  val Instance = new Properties.String(INSTANCE)
wenzelm@52854
    23
wenzelm@29184
    24
wenzelm@50201
    25
  /* basic markup */
wenzelm@29184
    26
wenzelm@45666
    27
  val Empty = Markup("", Nil)
wenzelm@45666
    28
  val Broken = Markup("broken", Nil)
wenzelm@50201
    29
wenzelm@55553
    30
  class Markup_String(val name: String, prop: String)
wenzelm@55553
    31
  {
wenzelm@55553
    32
    private val Prop = new Properties.String(prop)
wenzelm@55553
    33
wenzelm@55553
    34
    def apply(s: String): Markup = Markup(name, Prop(s))
wenzelm@55553
    35
    def unapply(markup: Markup): Option[String] =
wenzelm@55553
    36
      if (markup.name == name) Prop.unapply(markup.properties) else None
wenzelm@55553
    37
  }
wenzelm@55553
    38
wenzelm@55553
    39
  class Markup_Int(val name: String, prop: String)
wenzelm@55553
    40
  {
wenzelm@55553
    41
    private val Prop = new Properties.Int(prop)
wenzelm@55553
    42
wenzelm@55553
    43
    def apply(i: Int): Markup = Markup(name, Prop(i))
wenzelm@55553
    44
    def unapply(markup: Markup): Option[Int] =
wenzelm@55553
    45
      if (markup.name == name) Prop.unapply(markup.properties) else None
wenzelm@55553
    46
  }
wenzelm@55553
    47
wenzelm@50201
    48
wenzelm@50201
    49
  /* formal entities */
wenzelm@50201
    50
wenzelm@50201
    51
  val BINDING = "binding"
wenzelm@50201
    52
  val ENTITY = "entity"
wenzelm@50201
    53
  val DEF = "def"
wenzelm@50201
    54
  val REF = "ref"
wenzelm@50201
    55
wenzelm@50201
    56
  object Entity
wenzelm@50201
    57
  {
wenzelm@50201
    58
    def unapply(markup: Markup): Option[(String, String)] =
wenzelm@50201
    59
      markup match {
wenzelm@55553
    60
        case Markup(ENTITY, props) =>
wenzelm@55553
    61
          (props, props) match {
wenzelm@55615
    62
            case (Kind(kind), Name(name)) => Some((kind, name))
wenzelm@50201
    63
            case _ => None
wenzelm@50201
    64
          }
wenzelm@50201
    65
        case _ => None
wenzelm@50201
    66
      }
wenzelm@50201
    67
  }
wenzelm@50201
    68
wenzelm@50201
    69
wenzelm@55672
    70
  /* completion */
wenzelm@55672
    71
wenzelm@55672
    72
  val COMPLETION = "completion"
wenzelm@55672
    73
wenzelm@55672
    74
wenzelm@50201
    75
  /* position */
wenzelm@50201
    76
wenzelm@50201
    77
  val LINE = "line"
wenzelm@50201
    78
  val OFFSET = "offset"
wenzelm@50201
    79
  val END_OFFSET = "end_offset"
wenzelm@50201
    80
  val FILE = "file"
wenzelm@50201
    81
  val ID = "id"
wenzelm@50201
    82
wenzelm@50201
    83
  val DEF_LINE = "def_line"
wenzelm@50201
    84
  val DEF_OFFSET = "def_offset"
wenzelm@50201
    85
  val DEF_END_OFFSET = "def_end_offset"
wenzelm@50201
    86
  val DEF_FILE = "def_file"
wenzelm@50201
    87
  val DEF_ID = "def_id"
wenzelm@50201
    88
wenzelm@50201
    89
  val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
wenzelm@50201
    90
  val POSITION = "position"
wenzelm@50201
    91
wenzelm@50201
    92
wenzelm@55552
    93
  /* embedded languages */
wenzelm@55552
    94
wenzelm@55666
    95
  val Symbols = new Properties.Boolean("symbols")
wenzelm@55666
    96
  val Antiquotes = new Properties.Boolean("antiquotes")
wenzelm@55615
    97
wenzelm@55552
    98
  val LANGUAGE = "language"
wenzelm@55615
    99
  object Language
wenzelm@55615
   100
  {
wenzelm@55616
   101
    val ML = "ML"
wenzelm@55616
   102
    val UNKNOWN = "unknown"
wenzelm@55616
   103
wenzelm@55666
   104
    def unapply(markup: Markup): Option[(String, Boolean, Boolean)] =
wenzelm@55615
   105
      markup match {
wenzelm@55615
   106
        case Markup(LANGUAGE, props) =>
wenzelm@55666
   107
          (props, props, props) match {
wenzelm@55666
   108
            case (Name(name), Symbols(symbols), Antiquotes(antiquotes)) =>
wenzelm@55666
   109
              Some((name, symbols, antiquotes))
wenzelm@55615
   110
            case _ => None
wenzelm@55615
   111
          }
wenzelm@55615
   112
        case _ => None
wenzelm@55615
   113
      }
wenzelm@55615
   114
  }
wenzelm@55552
   115
wenzelm@55552
   116
wenzelm@54702
   117
  /* external resources */
wenzelm@50201
   118
wenzelm@50201
   119
  val PATH = "path"
wenzelm@55553
   120
  val Path = new Markup_String(PATH, NAME)
wenzelm@50201
   121
wenzelm@54702
   122
  val URL = "url"
wenzelm@55553
   123
  val Url = new Markup_String(URL, NAME)
wenzelm@54702
   124
wenzelm@50201
   125
wenzelm@50201
   126
  /* pretty printing */
wenzelm@50201
   127
wenzelm@55553
   128
  val Block = new Markup_Int("block", "indent")
wenzelm@55553
   129
  val Break = new Markup_Int("break", "width")
wenzelm@50201
   130
wenzelm@51570
   131
  val ITEM = "item"
wenzelm@51574
   132
  val BULLET = "bullet"
wenzelm@51570
   133
wenzelm@50201
   134
  val SEPARATOR = "separator"
wenzelm@50201
   135
wenzelm@50201
   136
wenzelm@50201
   137
  /* hidden text */
wenzelm@50201
   138
wenzelm@50201
   139
  val HIDDEN = "hidden"
wenzelm@50201
   140
wenzelm@50201
   141
wenzelm@50201
   142
  /* logical entities */
wenzelm@50201
   143
wenzelm@50201
   144
  val CLASS = "class"
wenzelm@50201
   145
  val TYPE_NAME = "type_name"
wenzelm@50201
   146
  val FIXED = "fixed"
wenzelm@53378
   147
  val CASE = "case"
wenzelm@50201
   148
  val CONSTANT = "constant"
wenzelm@50201
   149
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@50201
   150
wenzelm@50201
   151
wenzelm@50201
   152
  /* inner syntax */
wenzelm@50201
   153
wenzelm@50201
   154
  val TFREE = "tfree"
wenzelm@50201
   155
  val TVAR = "tvar"
wenzelm@50201
   156
  val FREE = "free"
wenzelm@50201
   157
  val SKOLEM = "skolem"
wenzelm@50201
   158
  val BOUND = "bound"
wenzelm@50201
   159
  val VAR = "var"
wenzelm@50201
   160
  val NUMERAL = "numeral"
wenzelm@50201
   161
  val LITERAL = "literal"
wenzelm@50201
   162
  val DELIMITER = "delimiter"
wenzelm@50201
   163
  val INNER_STRING = "inner_string"
wenzelm@55033
   164
  val INNER_CARTOUCHE = "inner_cartouche"
wenzelm@50201
   165
  val INNER_COMMENT = "inner_comment"
wenzelm@50201
   166
wenzelm@50201
   167
  val TOKEN_RANGE = "token_range"
wenzelm@50201
   168
wenzelm@50201
   169
  val SORTING = "sorting"
wenzelm@50201
   170
  val TYPING = "typing"
wenzelm@50201
   171
wenzelm@50201
   172
  val ATTRIBUTE = "attribute"
wenzelm@50201
   173
  val METHOD = "method"
wenzelm@50201
   174
wenzelm@50201
   175
wenzelm@55552
   176
  /* antiquotations */
wenzelm@50201
   177
wenzelm@55526
   178
  val ANTIQUOTED = "antiquoted"
wenzelm@55526
   179
  val ANTIQUOTE = "antiquote"
wenzelm@55526
   180
wenzelm@50201
   181
  val ML_ANTIQUOTATION = "ML_antiquotation"
wenzelm@50201
   182
  val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
wenzelm@50201
   183
  val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
wenzelm@50201
   184
wenzelm@50201
   185
wenzelm@50201
   186
  /* text structure */
wenzelm@50201
   187
wenzelm@50201
   188
  val PARAGRAPH = "paragraph"
wenzelm@50545
   189
  val TEXT_FOLD = "text_fold"
wenzelm@50201
   190
wenzelm@50201
   191
wenzelm@50201
   192
  /* ML syntax */
wenzelm@50201
   193
wenzelm@55505
   194
  val ML_KEYWORD1 = "ML_keyword1"
wenzelm@55505
   195
  val ML_KEYWORD2 = "ML_keyword2"
wenzelm@55505
   196
  val ML_KEYWORD3 = "ML_keyword3"
wenzelm@50201
   197
  val ML_DELIMITER = "ML_delimiter"
wenzelm@50201
   198
  val ML_TVAR = "ML_tvar"
wenzelm@50201
   199
  val ML_NUMERAL = "ML_numeral"
wenzelm@50201
   200
  val ML_CHAR = "ML_char"
wenzelm@50201
   201
  val ML_STRING = "ML_string"
wenzelm@50201
   202
  val ML_COMMENT = "ML_comment"
wenzelm@50201
   203
wenzelm@50201
   204
  val ML_DEF = "ML_def"
wenzelm@50201
   205
  val ML_OPEN = "ML_open"
wenzelm@50201
   206
  val ML_STRUCT = "ML_struct"
wenzelm@50201
   207
  val ML_TYPING = "ML_typing"
wenzelm@50201
   208
wenzelm@50201
   209
wenzelm@50201
   210
  /* outer syntax */
wenzelm@50201
   211
wenzelm@50201
   212
  val KEYWORD = "keyword"
wenzelm@50201
   213
  val OPERATOR = "operator"
wenzelm@50201
   214
  val COMMAND = "command"
wenzelm@50201
   215
  val STRING = "string"
wenzelm@50201
   216
  val ALTSTRING = "altstring"
wenzelm@50201
   217
  val VERBATIM = "verbatim"
wenzelm@55033
   218
  val CARTOUCHE = "cartouche"
wenzelm@50201
   219
  val COMMENT = "comment"
wenzelm@50201
   220
  val CONTROL = "control"
wenzelm@50201
   221
wenzelm@50201
   222
  val KEYWORD1 = "keyword1"
wenzelm@50201
   223
  val KEYWORD2 = "keyword2"
wenzelm@50201
   224
wenzelm@50201
   225
wenzelm@50201
   226
  /* timing */
wenzelm@50201
   227
wenzelm@50781
   228
  val Elapsed = new Properties.Double("elapsed")
wenzelm@50781
   229
  val CPU = new Properties.Double("cpu")
wenzelm@50781
   230
  val GC = new Properties.Double("gc")
wenzelm@50781
   231
wenzelm@50781
   232
  object Timing_Properties
wenzelm@50781
   233
  {
wenzelm@50781
   234
    def apply(timing: isabelle.Timing): Properties.T =
wenzelm@50781
   235
      Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
wenzelm@51662
   236
wenzelm@50781
   237
    def unapply(props: Properties.T): Option[isabelle.Timing] =
wenzelm@50781
   238
      (props, props, props) match {
wenzelm@50781
   239
        case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
wenzelm@50781
   240
          Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
wenzelm@50781
   241
        case _ => None
wenzelm@50781
   242
      }
wenzelm@50781
   243
  }
wenzelm@50781
   244
wenzelm@50201
   245
  val TIMING = "timing"
wenzelm@50201
   246
wenzelm@50201
   247
  object Timing
wenzelm@50201
   248
  {
wenzelm@50781
   249
    def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
wenzelm@51662
   250
wenzelm@50201
   251
    def unapply(markup: Markup): Option[isabelle.Timing] =
wenzelm@50201
   252
      markup match {
wenzelm@50781
   253
        case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
wenzelm@50201
   254
        case _ => None
wenzelm@50201
   255
      }
wenzelm@50201
   256
  }
wenzelm@50201
   257
wenzelm@50201
   258
wenzelm@51662
   259
  /* command timing */
wenzelm@51662
   260
wenzelm@51818
   261
  val COMMAND_TIMING = "command_timing"
wenzelm@51662
   262
wenzelm@51662
   263
wenzelm@50201
   264
  /* toplevel */
wenzelm@50201
   265
wenzelm@50201
   266
  val SUBGOALS = "subgoals"
wenzelm@50201
   267
  val PROOF_STATE = "proof_state"
wenzelm@50201
   268
wenzelm@50201
   269
  val STATE = "state"
wenzelm@50543
   270
  val GOAL = "goal"
wenzelm@50201
   271
  val SUBGOAL = "subgoal"
wenzelm@50215
   272
wenzelm@50450
   273
wenzelm@50201
   274
  /* command status */
wenzelm@50201
   275
wenzelm@50201
   276
  val TASK = "task"
wenzelm@50201
   277
wenzelm@50201
   278
  val ACCEPTED = "accepted"
wenzelm@50201
   279
  val FORKED = "forked"
wenzelm@50201
   280
  val JOINED = "joined"
wenzelm@50201
   281
  val RUNNING = "running"
wenzelm@50201
   282
  val FINISHED = "finished"
wenzelm@50201
   283
  val FAILED = "failed"
wenzelm@50201
   284
wenzelm@50201
   285
wenzelm@50201
   286
  /* interactive documents */
wenzelm@50201
   287
wenzelm@50201
   288
  val VERSION = "version"
wenzelm@50201
   289
  val ASSIGN = "assign"
wenzelm@50201
   290
wenzelm@50201
   291
wenzelm@50201
   292
  /* prover process */
wenzelm@50201
   293
wenzelm@50201
   294
  val PROVER_COMMAND = "prover_command"
wenzelm@50201
   295
  val PROVER_ARG = "prover_arg"
wenzelm@50201
   296
wenzelm@50201
   297
wenzelm@50201
   298
  /* messages */
wenzelm@50201
   299
lars@55316
   300
  val SERIAL = "serial"
lars@55316
   301
  val Serial = new Properties.Long(SERIAL)
wenzelm@50201
   302
wenzelm@50201
   303
  val MESSAGE = "message"
wenzelm@50201
   304
wenzelm@50201
   305
  val INIT = "init"
wenzelm@50201
   306
  val STATUS = "status"
wenzelm@50201
   307
  val REPORT = "report"
wenzelm@50500
   308
  val RESULT = "result"
wenzelm@50201
   309
  val WRITELN = "writeln"
wenzelm@50201
   310
  val TRACING = "tracing"
wenzelm@50201
   311
  val WARNING = "warning"
wenzelm@50201
   312
  val ERROR = "error"
wenzelm@50201
   313
  val PROTOCOL = "protocol"
wenzelm@50201
   314
  val SYSTEM = "system"
wenzelm@50201
   315
  val STDOUT = "stdout"
wenzelm@50201
   316
  val STDERR = "stderr"
wenzelm@50201
   317
  val EXIT = "exit"
wenzelm@50201
   318
wenzelm@50201
   319
  val WRITELN_MESSAGE = "writeln_message"
wenzelm@50201
   320
  val TRACING_MESSAGE = "tracing_message"
wenzelm@50201
   321
  val WARNING_MESSAGE = "warning_message"
wenzelm@50201
   322
  val ERROR_MESSAGE = "error_message"
wenzelm@50201
   323
wenzelm@52876
   324
  val messages =
wenzelm@50201
   325
    Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
wenzelm@52876
   326
        WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
wenzelm@52876
   327
  val message: String => String = messages.withDefault((s: String) => s)
wenzelm@50201
   328
wenzelm@50201
   329
  val Return_Code = new Properties.Int("return_code")
wenzelm@50201
   330
wenzelm@50201
   331
  val LEGACY = "legacy"
wenzelm@50201
   332
wenzelm@50201
   333
  val NO_REPORT = "no_report"
wenzelm@50201
   334
wenzelm@50201
   335
  val BAD = "bad"
wenzelm@50201
   336
wenzelm@50500
   337
  val INTENSIFY = "intensify"
wenzelm@52643
   338
  val INFORMATION = "information"
wenzelm@50500
   339
wenzelm@50500
   340
wenzelm@50500
   341
  /* active areas */
wenzelm@50500
   342
wenzelm@50715
   343
  val BROWSER = "browser"
wenzelm@50500
   344
  val GRAPHVIEW = "graphview"
wenzelm@50500
   345
wenzelm@50500
   346
  val SENDBACK = "sendback"
wenzelm@50500
   347
  val PADDING = "padding"
wenzelm@52697
   348
  val PADDING_LINE = (PADDING, "line")
wenzelm@52697
   349
  val PADDING_COMMAND = (PADDING, "command")
wenzelm@50500
   350
wenzelm@50500
   351
  val DIALOG = "dialog"
wenzelm@50503
   352
  val Result = new Properties.String(RESULT)
wenzelm@50500
   353
wenzelm@50201
   354
wenzelm@50201
   355
  /* protocol message functions */
wenzelm@50201
   356
wenzelm@50201
   357
  val FUNCTION = "function"
wenzelm@50201
   358
  val Function = new Properties.String(FUNCTION)
wenzelm@50201
   359
wenzelm@52800
   360
  val Flush: Properties.T = List((FUNCTION, "flush"))
wenzelm@52800
   361
wenzelm@52563
   362
  val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
wenzelm@50201
   363
  val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
wenzelm@50201
   364
wenzelm@52111
   365
  object Protocol_Handler
wenzelm@52111
   366
  {
wenzelm@52111
   367
    def unapply(props: Properties.T): Option[(String)] =
wenzelm@52111
   368
      props match {
wenzelm@52111
   369
        case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
wenzelm@52111
   370
        case _ => None
wenzelm@52111
   371
      }
wenzelm@52111
   372
  }
wenzelm@52111
   373
wenzelm@52111
   374
  val INVOKE_SCALA = "invoke_scala"
wenzelm@50201
   375
  object Invoke_Scala
wenzelm@50201
   376
  {
wenzelm@50201
   377
    def unapply(props: Properties.T): Option[(String, String)] =
wenzelm@50201
   378
      props match {
wenzelm@52111
   379
        case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
wenzelm@50201
   380
        case _ => None
wenzelm@50201
   381
      }
wenzelm@50201
   382
  }
wenzelm@52111
   383
wenzelm@52111
   384
  val CANCEL_SCALA = "cancel_scala"
wenzelm@50201
   385
  object Cancel_Scala
wenzelm@50201
   386
  {
wenzelm@50201
   387
    def unapply(props: Properties.T): Option[String] =
wenzelm@50201
   388
      props match {
wenzelm@52111
   389
        case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
wenzelm@50201
   390
        case _ => None
wenzelm@50201
   391
      }
wenzelm@50201
   392
  }
wenzelm@50255
   393
wenzelm@53055
   394
  val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
wenzelm@53055
   395
  val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
wenzelm@53055
   396
wenzelm@50255
   397
  object ML_Statistics
wenzelm@50255
   398
  {
wenzelm@50255
   399
    def unapply(props: Properties.T): Option[Properties.T] =
wenzelm@50255
   400
      props match {
wenzelm@50255
   401
        case (FUNCTION, "ML_statistics") :: stats => Some(stats)
wenzelm@50255
   402
        case _ => None
wenzelm@50255
   403
      }
wenzelm@50255
   404
  }
wenzelm@50975
   405
wenzelm@50975
   406
  object Task_Statistics
wenzelm@50975
   407
  {
wenzelm@50975
   408
    def unapply(props: Properties.T): Option[Properties.T] =
wenzelm@50975
   409
      props match {
wenzelm@50975
   410
        case (FUNCTION, "task_statistics") :: stats => Some(stats)
wenzelm@50975
   411
        case _ => None
wenzelm@50975
   412
      }
wenzelm@50975
   413
  }
lars@55316
   414
wenzelm@55555
   415
lars@55316
   416
  /* simplifier trace */
lars@55316
   417
wenzelm@55555
   418
  val SIMP_TRACE = "simp_trace"
lars@55316
   419
wenzelm@55555
   420
  val SIMP_TRACE_LOG = "simp_trace_log"
wenzelm@55555
   421
  val SIMP_TRACE_STEP = "simp_trace_step"
wenzelm@55555
   422
  val SIMP_TRACE_RECURSE = "simp_trace_recurse"
wenzelm@55555
   423
  val SIMP_TRACE_HINT = "simp_trace_hint"
wenzelm@55555
   424
  val SIMP_TRACE_IGNORE = "simp_trace_ignore"
lars@55316
   425
wenzelm@55555
   426
  val SIMP_TRACE_CANCEL = "simp_trace_cancel"
wenzelm@55555
   427
  object Simp_Trace_Cancel
lars@55316
   428
  {
lars@55316
   429
    def unapply(props: Properties.T): Option[Long] =
lars@55316
   430
      props match {
wenzelm@55555
   431
        case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
lars@55316
   432
        case _ => None
lars@55316
   433
      }
lars@55316
   434
  }
wenzelm@45666
   435
}
wenzelm@43721
   436
wenzelm@43721
   437
wenzelm@45666
   438
sealed case class Markup(name: String, properties: Properties.T)
wenzelm@43748
   439