src/Pure/PIDE/markup.scala
author wenzelm
Mon Dec 09 12:16:52 2013 +0100 (2013-12-09 ago)
changeset 54702 3daeba5130f0
parent 53378 07990ba8c0ea
child 55033 8e8243975860
permissions -rw-r--r--
added document antiquotation @{url}, which produces formal markup for LaTeX and PIDE;
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@50201
    30
wenzelm@50201
    31
  /* formal entities */
wenzelm@50201
    32
wenzelm@50201
    33
  val BINDING = "binding"
wenzelm@50201
    34
  val ENTITY = "entity"
wenzelm@50201
    35
  val DEF = "def"
wenzelm@50201
    36
  val REF = "ref"
wenzelm@50201
    37
wenzelm@50201
    38
  object Entity
wenzelm@50201
    39
  {
wenzelm@50201
    40
    def unapply(markup: Markup): Option[(String, String)] =
wenzelm@50201
    41
      markup match {
wenzelm@50201
    42
        case Markup(ENTITY, props @ Kind(kind)) =>
wenzelm@50201
    43
          props match {
wenzelm@50201
    44
            case Name(name) => Some(kind, name)
wenzelm@50201
    45
            case _ => None
wenzelm@50201
    46
          }
wenzelm@50201
    47
        case _ => None
wenzelm@50201
    48
      }
wenzelm@50201
    49
  }
wenzelm@50201
    50
wenzelm@50201
    51
wenzelm@50201
    52
  /* position */
wenzelm@50201
    53
wenzelm@50201
    54
  val LINE = "line"
wenzelm@50201
    55
  val OFFSET = "offset"
wenzelm@50201
    56
  val END_OFFSET = "end_offset"
wenzelm@50201
    57
  val FILE = "file"
wenzelm@50201
    58
  val ID = "id"
wenzelm@50201
    59
wenzelm@50201
    60
  val DEF_LINE = "def_line"
wenzelm@50201
    61
  val DEF_OFFSET = "def_offset"
wenzelm@50201
    62
  val DEF_END_OFFSET = "def_end_offset"
wenzelm@50201
    63
  val DEF_FILE = "def_file"
wenzelm@50201
    64
  val DEF_ID = "def_id"
wenzelm@50201
    65
wenzelm@50201
    66
  val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
wenzelm@50201
    67
  val POSITION = "position"
wenzelm@50201
    68
wenzelm@50201
    69
wenzelm@54702
    70
  /* external resources */
wenzelm@50201
    71
wenzelm@50201
    72
  val PATH = "path"
wenzelm@50201
    73
wenzelm@50201
    74
  object Path
wenzelm@50201
    75
  {
wenzelm@50201
    76
    def unapply(markup: Markup): Option[String] =
wenzelm@50201
    77
      markup match {
wenzelm@50201
    78
        case Markup(PATH, Name(name)) => Some(name)
wenzelm@50201
    79
        case _ => None
wenzelm@50201
    80
      }
wenzelm@50201
    81
  }
wenzelm@50201
    82
wenzelm@54702
    83
  val URL = "url"
wenzelm@54702
    84
wenzelm@54702
    85
  object Url
wenzelm@54702
    86
  {
wenzelm@54702
    87
    def unapply(markup: Markup): Option[String] =
wenzelm@54702
    88
      markup match {
wenzelm@54702
    89
        case Markup(URL, Name(name)) => Some(name)
wenzelm@54702
    90
        case _ => None
wenzelm@54702
    91
      }
wenzelm@54702
    92
  }
wenzelm@54702
    93
wenzelm@50201
    94
wenzelm@50201
    95
  /* pretty printing */
wenzelm@50201
    96
wenzelm@50201
    97
  val Indent = new Properties.Int("indent")
wenzelm@50201
    98
  val BLOCK = "block"
wenzelm@51570
    99
wenzelm@50201
   100
  val Width = new Properties.Int("width")
wenzelm@50201
   101
  val BREAK = "break"
wenzelm@50201
   102
wenzelm@51570
   103
  val ITEM = "item"
wenzelm@51574
   104
  val BULLET = "bullet"
wenzelm@51570
   105
wenzelm@50201
   106
  val SEPARATOR = "separator"
wenzelm@50201
   107
wenzelm@50201
   108
wenzelm@50201
   109
  /* hidden text */
wenzelm@50201
   110
wenzelm@50201
   111
  val HIDDEN = "hidden"
wenzelm@50201
   112
wenzelm@50201
   113
wenzelm@50201
   114
  /* logical entities */
wenzelm@50201
   115
wenzelm@50201
   116
  val CLASS = "class"
wenzelm@50201
   117
  val TYPE_NAME = "type_name"
wenzelm@50201
   118
  val FIXED = "fixed"
wenzelm@53378
   119
  val CASE = "case"
wenzelm@50201
   120
  val CONSTANT = "constant"
wenzelm@50201
   121
  val DYNAMIC_FACT = "dynamic_fact"
wenzelm@50201
   122
wenzelm@50201
   123
wenzelm@50201
   124
  /* inner syntax */
wenzelm@50201
   125
wenzelm@50201
   126
  val TFREE = "tfree"
wenzelm@50201
   127
  val TVAR = "tvar"
wenzelm@50201
   128
  val FREE = "free"
wenzelm@50201
   129
  val SKOLEM = "skolem"
wenzelm@50201
   130
  val BOUND = "bound"
wenzelm@50201
   131
  val VAR = "var"
wenzelm@50201
   132
  val NUMERAL = "numeral"
wenzelm@50201
   133
  val LITERAL = "literal"
wenzelm@50201
   134
  val DELIMITER = "delimiter"
wenzelm@50201
   135
  val INNER_STRING = "inner_string"
wenzelm@50201
   136
  val INNER_COMMENT = "inner_comment"
wenzelm@50201
   137
wenzelm@50201
   138
  val TOKEN_RANGE = "token_range"
wenzelm@50201
   139
wenzelm@50201
   140
  val SORT = "sort"
wenzelm@50201
   141
  val TYP = "typ"
wenzelm@50201
   142
  val TERM = "term"
wenzelm@50201
   143
  val PROP = "prop"
wenzelm@50201
   144
wenzelm@50201
   145
  val SORTING = "sorting"
wenzelm@50201
   146
  val TYPING = "typing"
wenzelm@50201
   147
wenzelm@50201
   148
  val ATTRIBUTE = "attribute"
wenzelm@50201
   149
  val METHOD = "method"
wenzelm@50201
   150
wenzelm@50201
   151
wenzelm@50201
   152
  /* embedded source text */
wenzelm@50201
   153
wenzelm@50201
   154
  val ML_SOURCE = "ML_source"
wenzelm@50201
   155
  val DOCUMENT_SOURCE = "document_source"
wenzelm@50201
   156
wenzelm@50201
   157
  val ANTIQ = "antiq"
wenzelm@50201
   158
  val ML_ANTIQUOTATION = "ML_antiquotation"
wenzelm@50201
   159
  val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
wenzelm@50201
   160
  val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
wenzelm@50201
   161
wenzelm@50201
   162
wenzelm@50201
   163
  /* text structure */
wenzelm@50201
   164
wenzelm@50201
   165
  val PARAGRAPH = "paragraph"
wenzelm@50545
   166
  val TEXT_FOLD = "text_fold"
wenzelm@50201
   167
wenzelm@50201
   168
wenzelm@50201
   169
  /* ML syntax */
wenzelm@50201
   170
wenzelm@50201
   171
  val ML_KEYWORD = "ML_keyword"
wenzelm@50201
   172
  val ML_DELIMITER = "ML_delimiter"
wenzelm@50201
   173
  val ML_TVAR = "ML_tvar"
wenzelm@50201
   174
  val ML_NUMERAL = "ML_numeral"
wenzelm@50201
   175
  val ML_CHAR = "ML_char"
wenzelm@50201
   176
  val ML_STRING = "ML_string"
wenzelm@50201
   177
  val ML_COMMENT = "ML_comment"
wenzelm@50201
   178
wenzelm@50201
   179
  val ML_DEF = "ML_def"
wenzelm@50201
   180
  val ML_OPEN = "ML_open"
wenzelm@50201
   181
  val ML_STRUCT = "ML_struct"
wenzelm@50201
   182
  val ML_TYPING = "ML_typing"
wenzelm@50201
   183
wenzelm@50201
   184
wenzelm@50201
   185
  /* outer syntax */
wenzelm@50201
   186
wenzelm@50201
   187
  val KEYWORD = "keyword"
wenzelm@50201
   188
  val OPERATOR = "operator"
wenzelm@50201
   189
  val COMMAND = "command"
wenzelm@50201
   190
  val STRING = "string"
wenzelm@50201
   191
  val ALTSTRING = "altstring"
wenzelm@50201
   192
  val VERBATIM = "verbatim"
wenzelm@50201
   193
  val COMMENT = "comment"
wenzelm@50201
   194
  val CONTROL = "control"
wenzelm@50201
   195
wenzelm@50201
   196
  val KEYWORD1 = "keyword1"
wenzelm@50201
   197
  val KEYWORD2 = "keyword2"
wenzelm@50201
   198
wenzelm@50201
   199
wenzelm@50201
   200
  /* timing */
wenzelm@50201
   201
wenzelm@50781
   202
  val Elapsed = new Properties.Double("elapsed")
wenzelm@50781
   203
  val CPU = new Properties.Double("cpu")
wenzelm@50781
   204
  val GC = new Properties.Double("gc")
wenzelm@50781
   205
wenzelm@50781
   206
  object Timing_Properties
wenzelm@50781
   207
  {
wenzelm@50781
   208
    def apply(timing: isabelle.Timing): Properties.T =
wenzelm@50781
   209
      Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
wenzelm@51662
   210
wenzelm@50781
   211
    def unapply(props: Properties.T): Option[isabelle.Timing] =
wenzelm@50781
   212
      (props, props, props) match {
wenzelm@50781
   213
        case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
wenzelm@50781
   214
          Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
wenzelm@50781
   215
        case _ => None
wenzelm@50781
   216
      }
wenzelm@50781
   217
  }
wenzelm@50781
   218
wenzelm@50201
   219
  val TIMING = "timing"
wenzelm@50201
   220
wenzelm@50201
   221
  object Timing
wenzelm@50201
   222
  {
wenzelm@50781
   223
    def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
wenzelm@51662
   224
wenzelm@50201
   225
    def unapply(markup: Markup): Option[isabelle.Timing] =
wenzelm@50201
   226
      markup match {
wenzelm@50781
   227
        case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
wenzelm@50201
   228
        case _ => None
wenzelm@50201
   229
      }
wenzelm@50201
   230
  }
wenzelm@50201
   231
wenzelm@50201
   232
wenzelm@51662
   233
  /* command timing */
wenzelm@51662
   234
wenzelm@51818
   235
  val COMMAND_TIMING = "command_timing"
wenzelm@51662
   236
wenzelm@51662
   237
wenzelm@50201
   238
  /* toplevel */
wenzelm@50201
   239
wenzelm@50201
   240
  val SUBGOALS = "subgoals"
wenzelm@50201
   241
  val PROOF_STATE = "proof_state"
wenzelm@50201
   242
wenzelm@50201
   243
  val STATE = "state"
wenzelm@50543
   244
  val GOAL = "goal"
wenzelm@50201
   245
  val SUBGOAL = "subgoal"
wenzelm@50215
   246
wenzelm@50450
   247
wenzelm@50201
   248
  /* command status */
wenzelm@50201
   249
wenzelm@50201
   250
  val TASK = "task"
wenzelm@50201
   251
wenzelm@50201
   252
  val ACCEPTED = "accepted"
wenzelm@50201
   253
  val FORKED = "forked"
wenzelm@50201
   254
  val JOINED = "joined"
wenzelm@50201
   255
  val RUNNING = "running"
wenzelm@50201
   256
  val FINISHED = "finished"
wenzelm@50201
   257
  val FAILED = "failed"
wenzelm@50201
   258
wenzelm@50201
   259
wenzelm@50201
   260
  /* interactive documents */
wenzelm@50201
   261
wenzelm@50201
   262
  val VERSION = "version"
wenzelm@50201
   263
  val ASSIGN = "assign"
wenzelm@50201
   264
wenzelm@50201
   265
wenzelm@50201
   266
  /* prover process */
wenzelm@50201
   267
wenzelm@50201
   268
  val PROVER_COMMAND = "prover_command"
wenzelm@50201
   269
  val PROVER_ARG = "prover_arg"
wenzelm@50201
   270
wenzelm@50201
   271
wenzelm@50201
   272
  /* messages */
wenzelm@50201
   273
wenzelm@50201
   274
  val Serial = new Properties.Long("serial")
wenzelm@50201
   275
wenzelm@50201
   276
  val MESSAGE = "message"
wenzelm@50201
   277
wenzelm@50201
   278
  val INIT = "init"
wenzelm@50201
   279
  val STATUS = "status"
wenzelm@50201
   280
  val REPORT = "report"
wenzelm@50500
   281
  val RESULT = "result"
wenzelm@50201
   282
  val WRITELN = "writeln"
wenzelm@50201
   283
  val TRACING = "tracing"
wenzelm@50201
   284
  val WARNING = "warning"
wenzelm@50201
   285
  val ERROR = "error"
wenzelm@50201
   286
  val PROTOCOL = "protocol"
wenzelm@50201
   287
  val SYSTEM = "system"
wenzelm@50201
   288
  val STDOUT = "stdout"
wenzelm@50201
   289
  val STDERR = "stderr"
wenzelm@50201
   290
  val EXIT = "exit"
wenzelm@50201
   291
wenzelm@50201
   292
  val WRITELN_MESSAGE = "writeln_message"
wenzelm@50201
   293
  val TRACING_MESSAGE = "tracing_message"
wenzelm@50201
   294
  val WARNING_MESSAGE = "warning_message"
wenzelm@50201
   295
  val ERROR_MESSAGE = "error_message"
wenzelm@50201
   296
wenzelm@52876
   297
  val messages =
wenzelm@50201
   298
    Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
wenzelm@52876
   299
        WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
wenzelm@52876
   300
  val message: String => String = messages.withDefault((s: String) => s)
wenzelm@50201
   301
wenzelm@50201
   302
  val Return_Code = new Properties.Int("return_code")
wenzelm@50201
   303
wenzelm@50201
   304
  val LEGACY = "legacy"
wenzelm@50201
   305
wenzelm@50201
   306
  val NO_REPORT = "no_report"
wenzelm@50201
   307
wenzelm@50201
   308
  val BAD = "bad"
wenzelm@50201
   309
wenzelm@50500
   310
  val INTENSIFY = "intensify"
wenzelm@52643
   311
  val INFORMATION = "information"
wenzelm@50500
   312
wenzelm@50500
   313
wenzelm@50500
   314
  /* active areas */
wenzelm@50500
   315
wenzelm@50715
   316
  val BROWSER = "browser"
wenzelm@50500
   317
  val GRAPHVIEW = "graphview"
wenzelm@50500
   318
wenzelm@50500
   319
  val SENDBACK = "sendback"
wenzelm@50500
   320
  val PADDING = "padding"
wenzelm@52697
   321
  val PADDING_LINE = (PADDING, "line")
wenzelm@52697
   322
  val PADDING_COMMAND = (PADDING, "command")
wenzelm@50500
   323
wenzelm@50500
   324
  val DIALOG = "dialog"
wenzelm@50503
   325
  val Result = new Properties.String(RESULT)
wenzelm@50500
   326
wenzelm@50201
   327
wenzelm@50201
   328
  /* protocol message functions */
wenzelm@50201
   329
wenzelm@50201
   330
  val FUNCTION = "function"
wenzelm@50201
   331
  val Function = new Properties.String(FUNCTION)
wenzelm@50201
   332
wenzelm@52800
   333
  val Flush: Properties.T = List((FUNCTION, "flush"))
wenzelm@52800
   334
wenzelm@52563
   335
  val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
wenzelm@50201
   336
  val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
wenzelm@50201
   337
wenzelm@52111
   338
  object Protocol_Handler
wenzelm@52111
   339
  {
wenzelm@52111
   340
    def unapply(props: Properties.T): Option[(String)] =
wenzelm@52111
   341
      props match {
wenzelm@52111
   342
        case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
wenzelm@52111
   343
        case _ => None
wenzelm@52111
   344
      }
wenzelm@52111
   345
  }
wenzelm@52111
   346
wenzelm@52111
   347
  val INVOKE_SCALA = "invoke_scala"
wenzelm@50201
   348
  object Invoke_Scala
wenzelm@50201
   349
  {
wenzelm@50201
   350
    def unapply(props: Properties.T): Option[(String, String)] =
wenzelm@50201
   351
      props match {
wenzelm@52111
   352
        case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
wenzelm@50201
   353
        case _ => None
wenzelm@50201
   354
      }
wenzelm@50201
   355
  }
wenzelm@52111
   356
wenzelm@52111
   357
  val CANCEL_SCALA = "cancel_scala"
wenzelm@50201
   358
  object Cancel_Scala
wenzelm@50201
   359
  {
wenzelm@50201
   360
    def unapply(props: Properties.T): Option[String] =
wenzelm@50201
   361
      props match {
wenzelm@52111
   362
        case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
wenzelm@50201
   363
        case _ => None
wenzelm@50201
   364
      }
wenzelm@50201
   365
  }
wenzelm@50255
   366
wenzelm@53055
   367
  val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
wenzelm@53055
   368
  val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
wenzelm@53055
   369
wenzelm@50255
   370
  object ML_Statistics
wenzelm@50255
   371
  {
wenzelm@50255
   372
    def unapply(props: Properties.T): Option[Properties.T] =
wenzelm@50255
   373
      props match {
wenzelm@50255
   374
        case (FUNCTION, "ML_statistics") :: stats => Some(stats)
wenzelm@50255
   375
        case _ => None
wenzelm@50255
   376
      }
wenzelm@50255
   377
  }
wenzelm@50975
   378
wenzelm@50975
   379
  object Task_Statistics
wenzelm@50975
   380
  {
wenzelm@50975
   381
    def unapply(props: Properties.T): Option[Properties.T] =
wenzelm@50975
   382
      props match {
wenzelm@50975
   383
        case (FUNCTION, "task_statistics") :: stats => Some(stats)
wenzelm@50975
   384
        case _ => None
wenzelm@50975
   385
      }
wenzelm@50975
   386
  }
wenzelm@45666
   387
}
wenzelm@43721
   388
wenzelm@43721
   389
wenzelm@45666
   390
sealed case class Markup(name: String, properties: Properties.T)
wenzelm@43748
   391