src/Pure/General/symbol.scala
author wenzelm
Fri, 15 Aug 2008 21:53:40 +0200
changeset 27901 28083e9f8d1d
child 27905 070b4a6a9d58
permissions -rw-r--r--
Basic support for Isabelle symbols.
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
    ID:         $Id$
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     4
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     5
Basic support for Isabelle symbols.
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     6
*/
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     7
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     8
package isabelle
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
     9
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    10
import java.util.regex.Pattern
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    11
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    12
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    13
object Symbol {
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    14
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    15
  /* Regular expressions */
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    16
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    17
  private def compile(s: String) =
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    18
    Pattern.compile(s, Pattern.COMMENTS | Pattern.DOTALL)
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    19
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    20
  private val symbol_src = """ \\ \\? < (?:
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    21
      \^? [A-Za-z][A-Za-z0-9_']* |
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    22
      \^raw: [\x20-\x7e\u0100-\uffff && [^.>]]* ) >"""
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    23
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    24
  private val bad_symbol_src = "(?!" + symbol_src + ")" +
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    25
    """ \\ \\? < (?: (?! \p{Space} | ["`\\] | \(\* | \*\) | \{\* | \*\} ) . )*"""
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    26
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    27
  val symbol_pattern = compile(symbol_src)
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    28
  val bad_symbol_pattern = compile(bad_symbol_src)
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    29
  val pattern = compile(symbol_src + "|" + bad_symbol_src + "| .")
28083e9f8d1d Basic support for Isabelle symbols.
wenzelm
parents:
diff changeset
    30
}