src/Tools/jEdit/src/jedit/isabelle_markup.scala
author wenzelm
Tue Sep 07 23:23:19 2010 +0200 (2010-09-07 ago)
changeset 39179 591bbab9ef59
parent 39178 83e9f3ccea9f
child 39181 2257eded8323
permissions -rw-r--r--
moved token markup tables to isabelle_markup.scala;
wenzelm@39178
     1
/*  Title:      Tools/jEdit/src/jedit/isabelle_markup.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@39178
    13
wenzelm@39178
    14
import org.gjt.sp.jedit.GUIUtilities
wenzelm@39179
    15
import org.gjt.sp.jedit.syntax.Token
wenzelm@39178
    16
wenzelm@39178
    17
wenzelm@39178
    18
object Isabelle_Markup
wenzelm@39178
    19
{
wenzelm@39178
    20
  /* physical rendering */
wenzelm@39178
    21
wenzelm@39178
    22
  val outdated_color = new Color(240, 240, 240)
wenzelm@39178
    23
  val unfinished_color = new Color(255, 228, 225)
wenzelm@39178
    24
wenzelm@39178
    25
  val regular_color = new Color(192, 192, 192)
wenzelm@39178
    26
  val warning_color = new Color(255, 168, 0)
wenzelm@39178
    27
  val error_color = new Color(255, 80, 80)
wenzelm@39178
    28
  val bad_color = new Color(255, 204, 153, 100)
wenzelm@39178
    29
wenzelm@39178
    30
  val warning_icon = GUIUtilities.loadIcon("16x16/status/dialog-warning.png")
wenzelm@39178
    31
  val error_icon = GUIUtilities.loadIcon("16x16/status/dialog-error.png")
wenzelm@39178
    32
wenzelm@39178
    33
wenzelm@39178
    34
  /* command status */
wenzelm@39178
    35
wenzelm@39178
    36
  def status_color(snapshot: Document.Snapshot, command: Command): Option[Color] =
wenzelm@39178
    37
  {
wenzelm@39178
    38
    val state = snapshot.state(command)
wenzelm@39178
    39
    if (snapshot.is_outdated) Some(outdated_color)
wenzelm@39178
    40
    else
wenzelm@39178
    41
      Isar_Document.command_status(state.status) match {
wenzelm@39178
    42
        case Isar_Document.Forked(i) if i > 0 => Some(unfinished_color)
wenzelm@39178
    43
        case Isar_Document.Unprocessed => Some(unfinished_color)
wenzelm@39178
    44
        case _ => None
wenzelm@39178
    45
      }
wenzelm@39178
    46
  }
wenzelm@39178
    47
wenzelm@39178
    48
  def overview_color(snapshot: Document.Snapshot, command: Command): Option[Color] =
wenzelm@39178
    49
  {
wenzelm@39178
    50
    val state = snapshot.state(command)
wenzelm@39178
    51
    if (snapshot.is_outdated) None
wenzelm@39178
    52
    else
wenzelm@39178
    53
      Isar_Document.command_status(state.status) match {
wenzelm@39178
    54
        case Isar_Document.Forked(i) if i > 0 => Some(unfinished_color)
wenzelm@39178
    55
        case Isar_Document.Unprocessed => Some(unfinished_color)
wenzelm@39178
    56
        case Isar_Document.Failed => Some(error_color)
wenzelm@39178
    57
        case _ => None
wenzelm@39178
    58
      }
wenzelm@39178
    59
  }
wenzelm@39178
    60
wenzelm@39178
    61
wenzelm@39178
    62
  /* markup selectors */
wenzelm@39178
    63
wenzelm@39178
    64
  private val subexp_include =
wenzelm@39178
    65
    Set(Markup.SORT, Markup.TYP, Markup.TERM, Markup.PROP, Markup.ML_TYPING)
wenzelm@39178
    66
wenzelm@39178
    67
  val subexp: Markup_Tree.Select[(Text.Range, Color)] =
wenzelm@39178
    68
  {
wenzelm@39178
    69
    case Text.Info(range, XML.Elem(Markup(name, _), _)) if subexp_include(name) =>
wenzelm@39178
    70
      (range, Color.black)
wenzelm@39178
    71
  }
wenzelm@39178
    72
wenzelm@39178
    73
  val message: Markup_Tree.Select[Color] =
wenzelm@39178
    74
  {
wenzelm@39178
    75
    case Text.Info(_, XML.Elem(Markup(Markup.WRITELN, _), _)) => regular_color
wenzelm@39178
    76
    case Text.Info(_, XML.Elem(Markup(Markup.WARNING, _), _)) => warning_color
wenzelm@39178
    77
    case Text.Info(_, XML.Elem(Markup(Markup.ERROR, _), _)) => error_color
wenzelm@39178
    78
  }
wenzelm@39178
    79
wenzelm@39178
    80
  val background: Markup_Tree.Select[Color] =
wenzelm@39178
    81
  {
wenzelm@39178
    82
    case Text.Info(_, XML.Elem(Markup(Markup.BAD, _), _)) => bad_color
wenzelm@39178
    83
  }
wenzelm@39178
    84
wenzelm@39178
    85
  val box: Markup_Tree.Select[Color] =
wenzelm@39178
    86
  {
wenzelm@39178
    87
    case Text.Info(_, XML.Elem(Markup(Markup.TOKEN_RANGE, _), _)) => regular_color
wenzelm@39178
    88
  }
wenzelm@39178
    89
wenzelm@39178
    90
  val tooltip: Markup_Tree.Select[String] =
wenzelm@39178
    91
  {
wenzelm@39178
    92
    case Text.Info(_, XML.Elem(Markup(Markup.ML_TYPING, _), body)) =>
wenzelm@39178
    93
      Pretty.string_of(List(Pretty.block(body)), margin = 40)
wenzelm@39178
    94
    case Text.Info(_, XML.Elem(Markup(Markup.SORT, _), _)) => "sort"
wenzelm@39178
    95
    case Text.Info(_, XML.Elem(Markup(Markup.TYP, _), _)) => "type"
wenzelm@39178
    96
    case Text.Info(_, XML.Elem(Markup(Markup.TERM, _), _)) => "term"
wenzelm@39178
    97
    case Text.Info(_, XML.Elem(Markup(Markup.PROP, _), _)) => "proposition"
wenzelm@39178
    98
  }
wenzelm@39179
    99
wenzelm@39179
   100
wenzelm@39179
   101
  /* token markup -- text styles */
wenzelm@39179
   102
wenzelm@39179
   103
  private val command_style: Map[String, Byte] =
wenzelm@39179
   104
  {
wenzelm@39179
   105
    import Token._
wenzelm@39179
   106
    Map[String, Byte](
wenzelm@39179
   107
      Keyword.THY_END -> KEYWORD2,
wenzelm@39179
   108
      Keyword.THY_SCRIPT -> LABEL,
wenzelm@39179
   109
      Keyword.PRF_SCRIPT -> LABEL,
wenzelm@39179
   110
      Keyword.PRF_ASM -> KEYWORD3,
wenzelm@39179
   111
      Keyword.PRF_ASM_GOAL -> KEYWORD3
wenzelm@39179
   112
    ).withDefaultValue(KEYWORD1)
wenzelm@39179
   113
  }
wenzelm@39179
   114
wenzelm@39179
   115
  private val token_style: Map[String, Byte] =
wenzelm@39179
   116
  {
wenzelm@39179
   117
    import Token._
wenzelm@39179
   118
    Map[String, Byte](
wenzelm@39179
   119
      // logical entities
wenzelm@39179
   120
      Markup.TCLASS -> NULL,
wenzelm@39179
   121
      Markup.TYCON -> NULL,
wenzelm@39179
   122
      Markup.FIXED_DECL -> FUNCTION,
wenzelm@39179
   123
      Markup.FIXED -> NULL,
wenzelm@39179
   124
      Markup.CONST_DECL -> FUNCTION,
wenzelm@39179
   125
      Markup.CONST -> NULL,
wenzelm@39179
   126
      Markup.FACT_DECL -> FUNCTION,
wenzelm@39179
   127
      Markup.FACT -> NULL,
wenzelm@39179
   128
      Markup.DYNAMIC_FACT -> LABEL,
wenzelm@39179
   129
      Markup.LOCAL_FACT_DECL -> FUNCTION,
wenzelm@39179
   130
      Markup.LOCAL_FACT -> NULL,
wenzelm@39179
   131
      // inner syntax
wenzelm@39179
   132
      Markup.TFREE -> NULL,
wenzelm@39179
   133
      Markup.FREE -> NULL,
wenzelm@39179
   134
      Markup.TVAR -> NULL,
wenzelm@39179
   135
      Markup.SKOLEM -> NULL,
wenzelm@39179
   136
      Markup.BOUND -> NULL,
wenzelm@39179
   137
      Markup.VAR -> NULL,
wenzelm@39179
   138
      Markup.NUM -> DIGIT,
wenzelm@39179
   139
      Markup.FLOAT -> DIGIT,
wenzelm@39179
   140
      Markup.XNUM -> DIGIT,
wenzelm@39179
   141
      Markup.XSTR -> LITERAL4,
wenzelm@39179
   142
      Markup.LITERAL -> OPERATOR,
wenzelm@39179
   143
      Markup.INNER_COMMENT -> COMMENT1,
wenzelm@39179
   144
      Markup.SORT -> NULL,
wenzelm@39179
   145
      Markup.TYP -> NULL,
wenzelm@39179
   146
      Markup.TERM -> NULL,
wenzelm@39179
   147
      Markup.PROP -> NULL,
wenzelm@39179
   148
      Markup.ATTRIBUTE -> NULL,
wenzelm@39179
   149
      Markup.METHOD -> NULL,
wenzelm@39179
   150
      // ML syntax
wenzelm@39179
   151
      Markup.ML_KEYWORD -> KEYWORD1,
wenzelm@39179
   152
      Markup.ML_DELIMITER -> OPERATOR,
wenzelm@39179
   153
      Markup.ML_IDENT -> NULL,
wenzelm@39179
   154
      Markup.ML_TVAR -> NULL,
wenzelm@39179
   155
      Markup.ML_NUMERAL -> DIGIT,
wenzelm@39179
   156
      Markup.ML_CHAR -> LITERAL1,
wenzelm@39179
   157
      Markup.ML_STRING -> LITERAL1,
wenzelm@39179
   158
      Markup.ML_COMMENT -> COMMENT1,
wenzelm@39179
   159
      Markup.ML_MALFORMED -> INVALID,
wenzelm@39179
   160
      // embedded source text
wenzelm@39179
   161
      Markup.ML_SOURCE -> COMMENT3,
wenzelm@39179
   162
      Markup.DOC_SOURCE -> COMMENT3,
wenzelm@39179
   163
      Markup.ANTIQ -> COMMENT4,
wenzelm@39179
   164
      Markup.ML_ANTIQ -> COMMENT4,
wenzelm@39179
   165
      Markup.DOC_ANTIQ -> COMMENT4,
wenzelm@39179
   166
      // outer syntax
wenzelm@39179
   167
      Markup.KEYWORD -> KEYWORD2,
wenzelm@39179
   168
      Markup.OPERATOR -> OPERATOR,
wenzelm@39179
   169
      Markup.COMMAND -> KEYWORD1,
wenzelm@39179
   170
      Markup.IDENT -> NULL,
wenzelm@39179
   171
      Markup.VERBATIM -> COMMENT3,
wenzelm@39179
   172
      Markup.COMMENT -> COMMENT1,
wenzelm@39179
   173
      Markup.CONTROL -> COMMENT3,
wenzelm@39179
   174
      Markup.MALFORMED -> INVALID,
wenzelm@39179
   175
      Markup.STRING -> LITERAL3,
wenzelm@39179
   176
      Markup.ALTSTRING -> LITERAL1
wenzelm@39179
   177
    ).withDefaultValue(NULL)
wenzelm@39179
   178
  }
wenzelm@39179
   179
wenzelm@39179
   180
  def tokens(syntax: Outer_Syntax): Markup_Tree.Select[Byte] =
wenzelm@39179
   181
  {
wenzelm@39179
   182
    case Text.Info(_, XML.Elem(Markup(Markup.COMMAND, List((Markup.NAME, name))), _))
wenzelm@39179
   183
    if syntax.keyword_kind(name).isDefined => command_style(syntax.keyword_kind(name).get)
wenzelm@39179
   184
wenzelm@39179
   185
    case Text.Info(_, XML.Elem(Markup(name, _), _))
wenzelm@39179
   186
    if token_style(name) != Token.NULL => token_style(name)
wenzelm@39179
   187
  }
wenzelm@39178
   188
}