src/Tools/jEdit/src/isabelle_rendering.scala
author wenzelm
Wed Sep 12 13:21:33 2012 +0200 (2012-09-12 ago)
changeset 49321 a48f9bbbe720
parent 49294 a600c017f814
child 49355 7d1af0a6e797
permissions -rw-r--r--
avoid spaces in markup names, which might cause problems in boundary situations (e.g. HTML class);
wenzelm@45665
     1
/*  Title:      Tools/jEdit/src/isabelle_rendering.scala
wenzelm@39178
     2
    Author:     Makarius
wenzelm@39178
     3
wenzelm@39178
     4
Isabelle specific physical rendering and markup selection.
wenzelm@39178
     5
*/
wenzelm@39178
     6
wenzelm@39178
     7
package isabelle.jedit
wenzelm@39178
     8
wenzelm@39178
     9
wenzelm@39178
    10
import isabelle._
wenzelm@39178
    11
wenzelm@39178
    12
import java.awt.Color
wenzelm@46227
    13
import javax.swing.Icon
wenzelm@48921
    14
import java.io.{File => JFile}
wenzelm@39178
    15
wenzelm@43414
    16
import org.gjt.sp.jedit.syntax.{Token => JEditToken}
wenzelm@39178
    17
wenzelm@45460
    18
import scala.collection.immutable.SortedMap
wenzelm@45460
    19
wenzelm@39178
    20
wenzelm@45665
    21
object Isabelle_Rendering
wenzelm@39178
    22
{
wenzelm@39178
    23
  /* physical rendering */
wenzelm@39178
    24
wenzelm@49294
    25
  def color_value(s: String): Color = Color_Value(Isabelle.options.value.string(s))
wenzelm@43388
    26
wenzelm@46227
    27
  private val writeln_pri = 1
wenzelm@46227
    28
  private val warning_pri = 2
wenzelm@46227
    29
  private val legacy_pri = 3
wenzelm@46227
    30
  private val error_pri = 4
wenzelm@39178
    31
wenzelm@39178
    32
wenzelm@46166
    33
  /* command overview */
wenzelm@39178
    34
wenzelm@46227
    35
  def overview_color(snapshot: Document.Snapshot, range: Text.Range): Option[Color] =
wenzelm@39178
    36
  {
wenzelm@39178
    37
    if (snapshot.is_outdated) None
wenzelm@46166
    38
    else {
wenzelm@46227
    39
      val results =
wenzelm@46227
    40
        snapshot.cumulate_markup[(Protocol.Status, Int)](
wenzelm@46227
    41
          range, (Protocol.Status.init, 0),
wenzelm@46227
    42
          Some(Protocol.command_status_markup + Isabelle_Markup.WARNING + Isabelle_Markup.ERROR),
wenzelm@46227
    43
          {
wenzelm@46227
    44
            case ((status, pri), Text.Info(_, XML.Elem(markup, _))) =>
wenzelm@46227
    45
              if (markup.name == Isabelle_Markup.WARNING) (status, pri max warning_pri)
wenzelm@46227
    46
              else if (markup.name == Isabelle_Markup.ERROR) (status, pri max error_pri)
wenzelm@46227
    47
              else (Protocol.command_status(status, markup), pri)
wenzelm@46227
    48
          })
wenzelm@46227
    49
      if (results.isEmpty) None
wenzelm@46227
    50
      else {
wenzelm@46227
    51
        val (status, pri) =
wenzelm@46227
    52
          ((Protocol.Status.init, 0) /: results) {
wenzelm@46227
    53
            case ((s1, p1), Text.Info(_, (s2, p2))) => (s1 + s2, p1 max p2) }
wenzelm@46166
    54
wenzelm@49294
    55
        if (pri == warning_pri) Some(color_value("color_warning"))
wenzelm@49294
    56
        else if (pri == error_pri) Some(color_value("color_error"))
wenzelm@49294
    57
        else if (status.is_unprocessed) Some(color_value("color_unprocessed"))
wenzelm@49294
    58
        else if (status.is_running) Some(color_value("color_running"))
wenzelm@49294
    59
        else if (status.is_failed) Some(color_value("color_error"))
wenzelm@46166
    60
        else None
wenzelm@39178
    61
      }
wenzelm@46166
    62
    }
wenzelm@39178
    63
  }
wenzelm@39178
    64
wenzelm@39178
    65
wenzelm@39178
    66
  /* markup selectors */
wenzelm@39178
    67
wenzelm@46234
    68
  private val subexp_include =
wenzelm@46234
    69
    Set(Isabelle_Markup.SORT, Isabelle_Markup.TYP, Isabelle_Markup.TERM, Isabelle_Markup.PROP,
wenzelm@46234
    70
      Isabelle_Markup.ML_TYPING, Isabelle_Markup.TOKEN_RANGE, Isabelle_Markup.ENTITY,
wenzelm@49164
    71
      Isabelle_Markup.PATH, Isabelle_Markup.TYPING, Isabelle_Markup.FREE, Isabelle_Markup.SKOLEM,
wenzelm@49164
    72
      Isabelle_Markup.BOUND, Isabelle_Markup.VAR, Isabelle_Markup.TFREE, Isabelle_Markup.TVAR,
wenzelm@49321
    73
      Isabelle_Markup.ML_SOURCE, Isabelle_Markup.DOCUMENT_SOURCE)
wenzelm@46234
    74
wenzelm@46234
    75
  def subexp(snapshot: Document.Snapshot, range: Text.Range): Option[Text.Info[Color]] =
wenzelm@46234
    76
  {
wenzelm@46234
    77
    snapshot.select_markup(range, Some(subexp_include),
wenzelm@46234
    78
        {
wenzelm@48921
    79
          case Text.Info(info_range, XML.Elem(Markup(name, _), _)) if subexp_include(name) =>
wenzelm@49294
    80
            Text.Info(snapshot.convert(info_range), color_value("color_subexp"))
wenzelm@46234
    81
        }) match { case Text.Info(_, info) #:: _ => Some(info) case _ => None }
wenzelm@46234
    82
  }
wenzelm@46234
    83
wenzelm@46234
    84
wenzelm@48921
    85
  private val hyperlink_include = Set(Isabelle_Markup.ENTITY, Isabelle_Markup.PATH)
wenzelm@48921
    86
wenzelm@48921
    87
  def hyperlink(snapshot: Document.Snapshot, range: Text.Range): Option[Text.Info[Hyperlink]] =
wenzelm@48921
    88
  {
wenzelm@48921
    89
    snapshot.cumulate_markup[List[Text.Info[Hyperlink]]](range, Nil, Some(hyperlink_include),
wenzelm@48921
    90
        {
wenzelm@48921
    91
          case (links, Text.Info(info_range, XML.Elem(Isabelle_Markup.Path(name), _)))
wenzelm@48921
    92
          if Path.is_ok(name) =>
wenzelm@48923
    93
            val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name))
wenzelm@48923
    94
            Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, 0, 0)) :: links
wenzelm@48921
    95
wenzelm@48921
    96
          case (links, Text.Info(info_range, XML.Elem(Markup(Isabelle_Markup.ENTITY, props), _)))
wenzelm@48921
    97
          if (props.find(
wenzelm@48921
    98
            { case (Markup.KIND, Isabelle_Markup.ML_OPEN) => true
wenzelm@48921
    99
              case (Markup.KIND, Isabelle_Markup.ML_STRUCT) => true
wenzelm@48921
   100
              case _ => false }).isEmpty) =>
wenzelm@48921
   101
wenzelm@48921
   102
            props match {
wenzelm@48921
   103
              case Position.Line_File(line, name) if Path.is_ok(name) =>
wenzelm@48921
   104
                Isabelle_System.source_file(Path.explode(name)) match {
wenzelm@48923
   105
                  case Some(path) =>
wenzelm@48923
   106
                    val jedit_file = Isabelle_System.platform_path(path)
wenzelm@48923
   107
                    Text.Info(snapshot.convert(info_range), Hyperlink(jedit_file, line, 0)) :: links
wenzelm@48921
   108
                  case None => links
wenzelm@48921
   109
                }
wenzelm@48921
   110
wenzelm@48922
   111
              case Position.Id_Offset(id, offset) if !snapshot.is_outdated =>
wenzelm@48922
   112
                snapshot.state.find_command(snapshot.version, id) match {
wenzelm@48922
   113
                  case Some((node, command)) =>
wenzelm@48921
   114
                    val sources =
wenzelm@48922
   115
                      node.commands.iterator.takeWhile(_ != command).map(_.source) ++
wenzelm@48922
   116
                        Iterator.single(command.source(Text.Range(0, command.decode(offset))))
wenzelm@48922
   117
                    val (line, column) = ((1, 1) /: sources)(Symbol.advance_line_column)
wenzelm@48923
   118
                    Text.Info(snapshot.convert(info_range),
wenzelm@48923
   119
                      Hyperlink(command.node_name.node, line, column)) :: links
wenzelm@48921
   120
                  case None => links
wenzelm@48921
   121
                }
wenzelm@48921
   122
wenzelm@48921
   123
              case _ => links
wenzelm@48921
   124
            }
wenzelm@48921
   125
        }) match { case Text.Info(_, info :: _) #:: _ => Some(info) case _ => None }
wenzelm@48921
   126
  }
wenzelm@48921
   127
wenzelm@48921
   128
wenzelm@48768
   129
  private def tooltip_text(msg: XML.Tree): String =
wenzelm@49245
   130
    Pretty.string_of(List(msg), margin = Isabelle.options.int("jedit_tooltip_margin"))
wenzelm@48756
   131
wenzelm@46178
   132
  def tooltip_message(snapshot: Document.Snapshot, range: Text.Range): Option[String] =
wenzelm@46199
   133
  {
wenzelm@46199
   134
    val msgs =
wenzelm@46199
   135
      snapshot.cumulate_markup[SortedMap[Long, String]](range, SortedMap.empty,
wenzelm@48756
   136
        Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR,
wenzelm@48756
   137
          Isabelle_Markup.BAD)),
wenzelm@46199
   138
        {
wenzelm@48756
   139
          case (msgs, Text.Info(_, msg @
wenzelm@48756
   140
              XML.Elem(Markup(markup, Isabelle_Markup.Serial(serial)), _)))
wenzelm@46199
   141
          if markup == Isabelle_Markup.WRITELN ||
wenzelm@46199
   142
              markup == Isabelle_Markup.WARNING ||
wenzelm@46199
   143
              markup == Isabelle_Markup.ERROR =>
wenzelm@48768
   144
            msgs + (serial -> tooltip_text(msg))
wenzelm@49040
   145
          case (msgs, Text.Info(_, msg @ XML.Elem(Markup(Isabelle_Markup.BAD, _), body)))
wenzelm@49040
   146
          if !body.isEmpty => msgs + (Document.new_id() -> tooltip_text(msg))
wenzelm@46199
   147
        }).toList.flatMap(_.info)
wenzelm@46199
   148
    if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2)))
wenzelm@46199
   149
  }
wenzelm@39740
   150
wenzelm@43376
   151
wenzelm@43431
   152
  private val tooltips: Map[String, String] =
wenzelm@43431
   153
    Map(
wenzelm@45666
   154
      Isabelle_Markup.SORT -> "sort",
wenzelm@45666
   155
      Isabelle_Markup.TYP -> "type",
wenzelm@45666
   156
      Isabelle_Markup.TERM -> "term",
wenzelm@45666
   157
      Isabelle_Markup.PROP -> "proposition",
wenzelm@45666
   158
      Isabelle_Markup.TOKEN_RANGE -> "inner syntax token",
wenzelm@45666
   159
      Isabelle_Markup.FREE -> "free variable",
wenzelm@45666
   160
      Isabelle_Markup.SKOLEM -> "skolem variable",
wenzelm@45666
   161
      Isabelle_Markup.BOUND -> "bound variable",
wenzelm@45666
   162
      Isabelle_Markup.VAR -> "schematic variable",
wenzelm@45666
   163
      Isabelle_Markup.TFREE -> "free type variable",
wenzelm@45666
   164
      Isabelle_Markup.TVAR -> "schematic type variable",
wenzelm@45666
   165
      Isabelle_Markup.ML_SOURCE -> "ML source",
wenzelm@49321
   166
      Isabelle_Markup.DOCUMENT_SOURCE -> "document source")
wenzelm@43431
   167
wenzelm@46235
   168
  private val tooltip_elements =
wenzelm@49163
   169
    Set(Isabelle_Markup.ENTITY, Isabelle_Markup.TYPING, Isabelle_Markup.ML_TYPING,
wenzelm@49163
   170
      Isabelle_Markup.PATH) ++ tooltips.keys
wenzelm@46235
   171
wenzelm@45445
   172
  private def string_of_typing(kind: String, body: XML.Body): String =
wenzelm@45445
   173
    Pretty.string_of(List(Pretty.block(XML.Text(kind) :: Pretty.Break(1) :: body)),
wenzelm@49245
   174
      margin = Isabelle.options.int("jedit_tooltip_margin"))
wenzelm@45445
   175
wenzelm@46178
   176
  def tooltip(snapshot: Document.Snapshot, range: Text.Range): Option[String] =
wenzelm@46178
   177
  {
wenzelm@47540
   178
    def add(prev: Text.Info[List[(Boolean, String)]], r: Text.Range, p: (Boolean, String)) =
wenzelm@47540
   179
      if (prev.range == r) Text.Info(r, p :: prev.info) else Text.Info(r, List(p))
wenzelm@42302
   180
wenzelm@46178
   181
    val tips =
wenzelm@47540
   182
      snapshot.cumulate_markup[Text.Info[(List[(Boolean, String)])]](
wenzelm@46235
   183
        range, Text.Info(range, Nil), Some(tooltip_elements),
wenzelm@46235
   184
        {
wenzelm@46235
   185
          case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Entity(kind, name), _))) =>
wenzelm@49321
   186
            val kind1 = space_explode('_', kind).mkString(" ")
wenzelm@49321
   187
            add(prev, r, (true, kind1 + " " + quote(name)))
wenzelm@49163
   188
          case (prev, Text.Info(r, XML.Elem(Isabelle_Markup.Path(name), _)))
wenzelm@49163
   189
          if Path.is_ok(name) =>
wenzelm@49163
   190
            val jedit_file = Isabelle.thy_load.append(snapshot.node_name.dir, Path.explode(name))
wenzelm@49163
   191
            add(prev, r, (true, "file " + quote(jedit_file)))
wenzelm@46235
   192
          case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.TYPING, _), body))) =>
wenzelm@47540
   193
            add(prev, r, (true, string_of_typing("::", body)))
wenzelm@46235
   194
          case (prev, Text.Info(r, XML.Elem(Markup(Isabelle_Markup.ML_TYPING, _), body))) =>
wenzelm@47540
   195
            add(prev, r, (false, string_of_typing("ML:", body)))
wenzelm@46235
   196
          case (prev, Text.Info(r, XML.Elem(Markup(name, _), _)))
wenzelm@47540
   197
          if tooltips.isDefinedAt(name) => add(prev, r, (true, tooltips(name)))
wenzelm@46235
   198
        }).toList.flatMap(_.info.info)
wenzelm@46178
   199
wenzelm@47540
   200
    val all_tips =
wenzelm@47540
   201
      (tips.filter(_._1) ++ tips.filter(!_._1).lastOption.toList).map(_._2)
wenzelm@47540
   202
    if (all_tips.isEmpty) None else Some(cat_lines(all_tips))
wenzelm@46178
   203
  }
wenzelm@45460
   204
wenzelm@46234
   205
wenzelm@46234
   206
  private val gutter_icons = Map(
wenzelm@46234
   207
    warning_pri -> Isabelle.load_icon("16x16/status/dialog-information.png"),
wenzelm@46234
   208
    legacy_pri -> Isabelle.load_icon("16x16/status/dialog-warning.png"),
wenzelm@46234
   209
    error_pri -> Isabelle.load_icon("16x16/status/dialog-error.png"))
wenzelm@46234
   210
wenzelm@46234
   211
  def gutter_message(snapshot: Document.Snapshot, range: Text.Range): Option[Icon] =
wenzelm@46234
   212
  {
wenzelm@46234
   213
    val results =
wenzelm@46234
   214
      snapshot.cumulate_markup[Int](range, 0,
wenzelm@46234
   215
        Some(Set(Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)),
wenzelm@46234
   216
        {
wenzelm@46234
   217
          case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.WARNING, _), body))) =>
wenzelm@46234
   218
            body match {
wenzelm@46234
   219
              case List(XML.Elem(Markup(Isabelle_Markup.LEGACY, _), _)) => pri max legacy_pri
wenzelm@46234
   220
              case _ => pri max warning_pri
wenzelm@46234
   221
            }
wenzelm@46234
   222
          case (pri, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ERROR, _), _))) =>
wenzelm@46234
   223
            pri max error_pri
wenzelm@46234
   224
        })
wenzelm@46234
   225
    val pri = (0 /: results) { case (p1, Text.Info(_, p2)) => p1 max p2 }
wenzelm@46234
   226
    gutter_icons.get(pri)
wenzelm@46234
   227
  }
wenzelm@46234
   228
wenzelm@46234
   229
wenzelm@46234
   230
  def squiggly_underline(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
wenzelm@46234
   231
  {
wenzelm@49294
   232
    val squiggly_colors = Map(
wenzelm@49294
   233
      writeln_pri -> color_value("color_writeln"),
wenzelm@49294
   234
      warning_pri -> color_value("color_warning"),
wenzelm@49294
   235
      error_pri -> color_value("color_error"))
wenzelm@49294
   236
wenzelm@46234
   237
    val results =
wenzelm@46234
   238
      snapshot.cumulate_markup[Int](range, 0,
wenzelm@46234
   239
        Some(Set(Isabelle_Markup.WRITELN, Isabelle_Markup.WARNING, Isabelle_Markup.ERROR)),
wenzelm@46234
   240
        {
wenzelm@46234
   241
          case (pri, Text.Info(_, XML.Elem(Markup(name, _), _))) =>
wenzelm@46234
   242
            name match {
wenzelm@46234
   243
              case Isabelle_Markup.WRITELN => pri max writeln_pri
wenzelm@46234
   244
              case Isabelle_Markup.WARNING => pri max warning_pri
wenzelm@46234
   245
              case Isabelle_Markup.ERROR => pri max error_pri
wenzelm@46234
   246
              case _ => pri
wenzelm@46234
   247
            }
wenzelm@46234
   248
        })
wenzelm@46234
   249
    for {
wenzelm@46234
   250
      Text.Info(r, pri) <- results
wenzelm@46234
   251
      color <- squiggly_colors.get(pri)
wenzelm@46234
   252
    } yield Text.Info(r, color)
wenzelm@46234
   253
  }
wenzelm@46234
   254
wenzelm@42302
   255
wenzelm@46234
   256
  def background1(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
wenzelm@46178
   257
  {
wenzelm@49294
   258
    if (snapshot.is_outdated) Stream(Text.Info(range, color_value("color_outdated")))
wenzelm@46234
   259
    else
wenzelm@46234
   260
      for {
wenzelm@46234
   261
        Text.Info(r, result) <-
wenzelm@46234
   262
          snapshot.cumulate_markup[(Option[Protocol.Status], Option[Color])](
wenzelm@46234
   263
            range, (Some(Protocol.Status.init), None),
wenzelm@46234
   264
            Some(Protocol.command_status_markup + Isabelle_Markup.BAD + Isabelle_Markup.HILITE),
wenzelm@46234
   265
            {
wenzelm@46234
   266
              case (((Some(status), color), Text.Info(_, XML.Elem(markup, _))))
wenzelm@46234
   267
              if (Protocol.command_status_markup(markup.name)) =>
wenzelm@46234
   268
                (Some(Protocol.command_status(status, markup)), color)
wenzelm@46234
   269
              case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.BAD, _), _))) =>
wenzelm@49294
   270
                (None, Some(color_value("color_bad")))
wenzelm@46234
   271
              case (_, Text.Info(_, XML.Elem(Markup(Isabelle_Markup.HILITE, _), _))) =>
wenzelm@49294
   272
                (None, Some(color_value("color_hilite")))
wenzelm@46234
   273
            })
wenzelm@46234
   274
        color <-
wenzelm@46234
   275
          (result match {
wenzelm@49037
   276
            case (Some(status), opt_color) =>
wenzelm@49294
   277
              if (status.is_unprocessed) Some(color_value("color_unprocessed1"))
wenzelm@49294
   278
              else if (status.is_running) Some(color_value("color_running1"))
wenzelm@49037
   279
              else opt_color
wenzelm@46234
   280
            case (_, opt_color) => opt_color
wenzelm@46234
   281
          })
wenzelm@46234
   282
      } yield Text.Info(r, color)
wenzelm@46178
   283
  }
wenzelm@39179
   284
wenzelm@39179
   285
wenzelm@46234
   286
  def background2(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
wenzelm@46234
   287
    snapshot.select_markup(range,
wenzelm@46234
   288
      Some(Set(Isabelle_Markup.TOKEN_RANGE)),
wenzelm@46234
   289
      {
wenzelm@49294
   290
        case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.TOKEN_RANGE, _), _)) =>
wenzelm@49294
   291
          color_value("color_light")
wenzelm@46234
   292
      })
wenzelm@46234
   293
wenzelm@46234
   294
wenzelm@46234
   295
  def foreground(snapshot: Document.Snapshot, range: Text.Range): Stream[Text.Info[Color]] =
wenzelm@46234
   296
    snapshot.select_markup(range,
wenzelm@46234
   297
      Some(Set(Isabelle_Markup.STRING, Isabelle_Markup.ALTSTRING, Isabelle_Markup.VERBATIM)),
wenzelm@46234
   298
      {
wenzelm@49294
   299
        case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.STRING, _), _)) =>
wenzelm@49294
   300
          color_value("color_quoted")
wenzelm@49294
   301
        case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.ALTSTRING, _), _)) =>
wenzelm@49294
   302
          color_value("color_quoted")
wenzelm@49294
   303
        case Text.Info(_, XML.Elem(Markup(Isabelle_Markup.VERBATIM, _), _)) =>
wenzelm@49294
   304
          color_value("color_quoted")
wenzelm@46234
   305
      })
wenzelm@46234
   306
wenzelm@46234
   307
wenzelm@46234
   308
  def text_color(snapshot: Document.Snapshot, range: Text.Range, color: Color)
wenzelm@46234
   309
      : Stream[Text.Info[Color]] =
wenzelm@49294
   310
  {
wenzelm@49294
   311
    val text_colors: Map[String, Color] = Map(
wenzelm@49294
   312
      Isabelle_Markup.STRING -> Color.BLACK,
wenzelm@49294
   313
      Isabelle_Markup.ALTSTRING -> Color.BLACK,
wenzelm@49294
   314
      Isabelle_Markup.VERBATIM -> Color.BLACK,
wenzelm@49294
   315
      Isabelle_Markup.LITERAL -> color_value("color_keyword1"),
wenzelm@49294
   316
      Isabelle_Markup.DELIMITER -> Color.BLACK,
wenzelm@49294
   317
      Isabelle_Markup.TFREE -> color_value("color_variable_type"),
wenzelm@49294
   318
      Isabelle_Markup.TVAR -> color_value("color_variable_type"),
wenzelm@49294
   319
      Isabelle_Markup.FREE -> color_value("color_variable_free"),
wenzelm@49294
   320
      Isabelle_Markup.SKOLEM -> color_value("color_variable_skolem"),
wenzelm@49294
   321
      Isabelle_Markup.BOUND -> color_value("color_variable_bound"),
wenzelm@49294
   322
      Isabelle_Markup.VAR -> color_value("color_variable_schematic"),
wenzelm@49294
   323
      Isabelle_Markup.INNER_STRING -> color_value("color_inner_quoted"),
wenzelm@49294
   324
      Isabelle_Markup.INNER_COMMENT -> color_value("color_inner_comment"),
wenzelm@49294
   325
      Isabelle_Markup.DYNAMIC_FACT -> color_value("color_dynamic"),
wenzelm@49294
   326
      Isabelle_Markup.ML_KEYWORD -> color_value("color_keyword1"),
wenzelm@49294
   327
      Isabelle_Markup.ML_DELIMITER -> Color.BLACK,
wenzelm@49294
   328
      Isabelle_Markup.ML_NUMERAL -> color_value("color_inner_numeral"),
wenzelm@49294
   329
      Isabelle_Markup.ML_CHAR -> color_value("color_inner_quoted"),
wenzelm@49294
   330
      Isabelle_Markup.ML_STRING -> color_value("color_inner_quoted"),
wenzelm@49294
   331
      Isabelle_Markup.ML_COMMENT -> color_value("color_inner_comment"),
wenzelm@49294
   332
      Isabelle_Markup.ANTIQ -> color_value("color_antiquotation"))
wenzelm@49294
   333
wenzelm@49294
   334
    val text_color_elements = Set.empty[String] ++ text_colors.keys
wenzelm@49294
   335
wenzelm@46234
   336
    snapshot.cumulate_markup(range, color, Some(text_color_elements),
wenzelm@46234
   337
      {
wenzelm@46234
   338
        case (_, Text.Info(_, XML.Elem(Markup(m, _), _)))
wenzelm@46234
   339
        if text_colors.isDefinedAt(m) => text_colors(m)
wenzelm@46234
   340
      })
wenzelm@49294
   341
  }
wenzelm@46234
   342
wenzelm@46234
   343
wenzelm@39179
   344
  /* token markup -- text styles */
wenzelm@39179
   345
wenzelm@39179
   346
  private val command_style: Map[String, Byte] =
wenzelm@39179
   347
  {
wenzelm@43414
   348
    import JEditToken._
wenzelm@39179
   349
    Map[String, Byte](
wenzelm@39179
   350
      Keyword.THY_END -> KEYWORD2,
wenzelm@39179
   351
      Keyword.THY_SCRIPT -> LABEL,
wenzelm@39179
   352
      Keyword.PRF_SCRIPT -> LABEL,
wenzelm@39179
   353
      Keyword.PRF_ASM -> KEYWORD3,
wenzelm@39179
   354
      Keyword.PRF_ASM_GOAL -> KEYWORD3
wenzelm@39179
   355
    ).withDefaultValue(KEYWORD1)
wenzelm@39179
   356
  }
wenzelm@39179
   357
wenzelm@43414
   358
  private val token_style: Map[Token.Kind.Value, Byte] =
wenzelm@39179
   359
  {
wenzelm@43414
   360
    import JEditToken._
wenzelm@43414
   361
    Map[Token.Kind.Value, Byte](
wenzelm@43414
   362
      Token.Kind.KEYWORD -> KEYWORD2,
wenzelm@43414
   363
      Token.Kind.IDENT -> NULL,
wenzelm@43414
   364
      Token.Kind.LONG_IDENT -> NULL,
wenzelm@43414
   365
      Token.Kind.SYM_IDENT -> NULL,
wenzelm@43414
   366
      Token.Kind.VAR -> NULL,
wenzelm@43414
   367
      Token.Kind.TYPE_IDENT -> NULL,
wenzelm@43414
   368
      Token.Kind.TYPE_VAR -> NULL,
wenzelm@43414
   369
      Token.Kind.NAT -> NULL,
wenzelm@43414
   370
      Token.Kind.FLOAT -> NULL,
wenzelm@43431
   371
      Token.Kind.STRING -> LITERAL1,
wenzelm@43431
   372
      Token.Kind.ALT_STRING -> LITERAL2,
wenzelm@43414
   373
      Token.Kind.VERBATIM -> COMMENT3,
wenzelm@43414
   374
      Token.Kind.SPACE -> NULL,
wenzelm@43414
   375
      Token.Kind.COMMENT -> COMMENT1,
wenzelm@48754
   376
      Token.Kind.ERROR -> INVALID
wenzelm@39179
   377
    ).withDefaultValue(NULL)
wenzelm@39179
   378
  }
wenzelm@39179
   379
wenzelm@43414
   380
  def token_markup(syntax: Outer_Syntax, token: Token): Byte =
wenzelm@43430
   381
    if (token.is_command) command_style(syntax.keyword_kind(token.content).getOrElse(""))
wenzelm@43430
   382
    else if (token.is_operator) JEditToken.OPERATOR
wenzelm@43414
   383
    else token_style(token.kind)
wenzelm@39178
   384
}