src/Pure/General/symbol.scala
author wenzelm
Sat, 04 Jul 2009 11:46:51 +0200
changeset 31929 ecfc667cac53
parent 31651 7d6a518b5a2b
child 33998 fc56cfc6906e
permissions -rw-r--r--
is_open: surrogate sequence is High..Low; added class Index for decoding offsets; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/General/symbol.scala
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     3
27924
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
     4
Detecting and recoding Isabelle symbols.
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     5
*/
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     6
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     7
package isabelle
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     8
27918
85942d2036a0 reading symbol interpretation tables;
wenzelm
parents: 27905
diff changeset
     9
import scala.io.Source
31929
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    10
import scala.collection.{jcl, mutable}
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    11
import scala.util.matching.Regex
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    12
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    13
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    14
object Symbol
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    15
{
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    16
27924
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
    17
  /** Symbol regexps **/
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    18
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    19
  private val plain = new Regex("""(?xs)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    20
    [^\\ \ud800-\udfff] | [\ud800-\udbff][\udc00-\udfff] """)
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    21
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    22
  private val symbol = new Regex("""(?xs)
31545
5f1f0a20af4d discontinued escaped symbols such as \\<forall> -- only one backslash should be used;
wenzelm
parents: 31523
diff changeset
    23
      \\ < (?:
27924
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
    24
      \^? [A-Za-z][A-Za-z0-9_']* |
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
    25
      \^raw: [\x20-\x7e\u0100-\uffff && [^.>]]* ) >""")
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
    26
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    27
  private val bad_symbol = new Regex("(?xs) (?!" + symbol + ")" +
31545
5f1f0a20af4d discontinued escaped symbols such as \\<forall> -- only one backslash should be used;
wenzelm
parents: 31523
diff changeset
    28
    """ \\ < (?: (?! \s | [\"`\\] | \(\* | \*\) | \{\* | \*\} ) . )*""")
27924
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
    29
27939
41b1c0b769bf pattern: proper "." not "[.]"!
wenzelm
parents: 27938
diff changeset
    30
  // total pattern
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    31
  val regex = new Regex(plain + "|" + symbol + "|" + bad_symbol + "| .")
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    32
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    33
  // prefix of another symbol
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    34
  def is_open(s: String): Boolean =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    35
  {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    36
    val len = s.length
31929
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    37
    len == 1 && Character.isLowSurrogate(s(0)) ||
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    38
    s == "\\" ||
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    39
    s == "\\<" ||
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    40
    len > 2 && s(len - 1) != '>'
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    41
  }
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    42
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    43
31929
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    44
  /** Decoding offsets **/
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    45
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    46
  class Index(text: String)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    47
  {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    48
    case class Entry(chr: Int, sym: Int)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    49
    val index: Array[Entry] =
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    50
    {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    51
      val length = text.length
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    52
      val matcher = regex.pattern.matcher(text)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    53
      val buf = new mutable.ArrayBuffer[Entry]
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    54
      var chr = 0
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    55
      var sym = 0
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    56
      while (chr < length) {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    57
        val c = text(chr)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    58
        val len =
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    59
          if (c == '\\' || Character.isHighSurrogate(c)) {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    60
            matcher.region(chr, length).lookingAt
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    61
            matcher.group.length
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    62
          } else 1
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    63
        chr += len
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    64
        sym += 1
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    65
        if (len > 1) buf += Entry(chr, sym)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    66
      }
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    67
      buf.toArray
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    68
    }
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    69
    def decode(sym: Int): Int =
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    70
    {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    71
      val end = index.length
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    72
      def bisect(a: Int, b: Int): Int =
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    73
      {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    74
        if (a < b) {
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    75
          val c = (a + b) / 2
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    76
          if (sym < index(c).sym) bisect(a, c)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    77
          else if (c + 1 == end || sym < index(c + 1).sym) c
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    78
          else bisect(c + 1, b)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    79
        }
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    80
        else -1
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    81
      }
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    82
      val i = bisect(0, end)
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    83
      if (i < 0) sym
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    84
      else index(i).chr + sym - index(i).sym
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    85
    }
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    86
  }
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    87
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    88
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
    89
  /** Recoding text **/
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    90
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    91
  private class Recoder(list: List[(String, String)])
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    92
  {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    93
    private val (min, max) =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
    94
    {
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    95
      var min = '\uffff'
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    96
      var max = '\u0000'
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    97
      for ((x, _) <- list) {
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    98
        val c = x(0)
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
    99
        if (c < min) min = c
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   100
        if (c > max) max = c
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   101
      }
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   102
      (min, max)
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   103
    }
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   104
    private val table =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   105
    {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   106
      val table = new jcl.HashMap[String, String]   // reasonably efficient?
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   107
      for ((x, y) <- list) table + (x -> y)
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   108
      table
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   109
    }
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   110
    def recode(text: String): String =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   111
    {
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   112
      val len = text.length
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   113
      val matcher = regex.pattern.matcher(text)
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   114
      val result = new StringBuilder(len)
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   115
      var i = 0
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   116
      while (i < len) {
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   117
        val c = text(i)
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   118
        if (min <= c && c <= max) {
31929
ecfc667cac53 is_open: surrogate sequence is High..Low;
wenzelm
parents: 31651
diff changeset
   119
          matcher.region(i, len).lookingAt
27938
3d5b12f23f15 recode: proper result for unmatched symbols;
wenzelm
parents: 27937
diff changeset
   120
          val x = matcher.group
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   121
          result.append(table.get(x) getOrElse x)
27937
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   122
          i = matcher.end
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   123
        }
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   124
        else { result.append(c); i += 1 }
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   125
      }
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   126
      result.toString
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   127
    }
fdf77e7be01a more robust pattern: look at longer matches first, added catch-all case;
wenzelm
parents: 27935
diff changeset
   128
  }
27924
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
   129
27918
85942d2036a0 reading symbol interpretation tables;
wenzelm
parents: 27905
diff changeset
   130
27923
7ebe9d38743a use scala.collection.jcl.HashMap, which seems to be more efficient;
wenzelm
parents: 27918
diff changeset
   131
27927
eb624bb54bc6 tuned Recoder;
wenzelm
parents: 27926
diff changeset
   132
  /** Symbol interpretation **/
eb624bb54bc6 tuned Recoder;
wenzelm
parents: 27926
diff changeset
   133
29569
f3f529b5d8fb more general init of Symbol.Interpretation, independent of IsabelleSystem instance;
wenzelm
parents: 29174
diff changeset
   134
  class Interpretation(symbol_decls: Iterator[String])
f3f529b5d8fb more general init of Symbol.Interpretation, independent of IsabelleSystem instance;
wenzelm
parents: 29174
diff changeset
   135
  {
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   136
    /* read symbols */
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   137
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   138
    private val empty = new Regex("""(?xs) ^\s* (?: \#.* )? $ """)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   139
    private val key = new Regex("""(?xs) (.+): """)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   140
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   141
    private def read_decl(decl: String): (String, Map[String, String]) =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   142
    {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   143
      def err() = error("Bad symbol declaration: " + decl)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   144
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   145
      def read_props(props: List[String]): Map[String, String] =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   146
      {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   147
        props match {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   148
          case Nil => Map()
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   149
          case _ :: Nil => err()
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   150
          case key(x) :: y :: rest => read_props(rest) + (x -> y)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   151
          case _ => err()
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   152
        }
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   153
      }
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   154
      decl.split("\\s+").toList match {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   155
        case Nil => err()
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   156
        case sym :: props => (sym, read_props(props))
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   157
      }
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   158
    }
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   159
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   160
    private val symbols: List[(String, Map[String, String])] =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   161
      for (decl <- symbol_decls.toList if !empty.pattern.matcher(decl).matches)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   162
        yield read_decl(decl)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   163
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   164
31651
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   165
    /* misc properties */
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   166
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   167
    val names: Map[String, String] = {
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   168
      val name = new Regex("""\\<([A-Za-z][A-Za-z0-9_']*)>""")
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   169
      Map((for ((sym @ name(a), _) <- symbols) yield (sym -> a)): _*)
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   170
    }
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   171
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   172
    val abbrevs: Map[String, String] = Map((
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   173
      for ((sym, props) <- symbols if props.isDefinedAt("abbrev"))
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   174
        yield (sym -> props("abbrev"))): _*)
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   175
7d6a518b5a2b added names, abbrevs;
wenzelm
parents: 31548
diff changeset
   176
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   177
    /* main recoder methods */
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   178
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   179
    private val (decoder, encoder) =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   180
    {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   181
      val mapping =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   182
        for {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   183
          (sym, props) <- symbols
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   184
          val code =
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   185
            try { Integer.decode(props("code")).intValue }
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   186
            catch {
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   187
              case _: NoSuchElementException => error("Missing code for symbol " + sym)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   188
              case _: NumberFormatException => error("Bad code for symbol " + sym)
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   189
            }
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   190
          val ch = new String(Character.toChars(code))
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   191
        } yield (sym, ch)
31545
5f1f0a20af4d discontinued escaped symbols such as \\<forall> -- only one backslash should be used;
wenzelm
parents: 31523
diff changeset
   192
      (new Recoder(mapping),
31548
wenzelm
parents: 31545
diff changeset
   193
       new Recoder(mapping map { case (x, y) => (y, x) }))
31522
0466cb17064f more native Scala style;
wenzelm
parents: 29569
diff changeset
   194
    }
27918
85942d2036a0 reading symbol interpretation tables;
wenzelm
parents: 27905
diff changeset
   195
27924
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
   196
    def decode(text: String) = decoder.recode(text)
8dd8b564faf5 tuned comments;
wenzelm
parents: 27923
diff changeset
   197
    def encode(text: String) = encoder.recode(text)
27923
7ebe9d38743a use scala.collection.jcl.HashMap, which seems to be more efficient;
wenzelm
parents: 27918
diff changeset
   198
27918
85942d2036a0 reading symbol interpretation tables;
wenzelm
parents: 27905
diff changeset
   199
  }
27901
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
   200
}