|
27951
|
1 |
/* Title: Pure/Tools/isabelle_syntax.scala
|
|
|
2 |
ID: $Id$
|
|
|
3 |
Author: Makarius
|
|
|
4 |
|
|
|
5 |
Isabelle outer syntax.
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
package isabelle
|
|
|
9 |
|
|
|
10 |
import java.util.{Properties, Enumeration}
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
object IsabelleSyntax {
|
|
|
14 |
|
|
|
15 |
/* string token */
|
|
|
16 |
|
|
|
17 |
def append_string(str: String, result: StringBuilder) = {
|
|
|
18 |
result.append("\"")
|
|
|
19 |
for (c <- str) {
|
|
|
20 |
if (c < 32 || c == '\\' || c == '\"') {
|
|
|
21 |
if (c < 10) result.append('0')
|
|
|
22 |
if (c < 100) result.append('0')
|
|
|
23 |
result.append(c.asInstanceOf[Int].toString)
|
|
|
24 |
}
|
|
|
25 |
else result.append(c)
|
|
|
26 |
}
|
|
|
27 |
result.append("\"")
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
def encode_string(str: String) = {
|
|
|
31 |
val result = new StringBuilder(str.length + 20)
|
|
|
32 |
append_string(str, result)
|
|
|
33 |
result.toString
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
/* properties */
|
|
|
38 |
|
|
|
39 |
def append_properties(props: Properties, result: StringBuilder) = {
|
|
|
40 |
result.append("(")
|
|
|
41 |
val names = props.propertyNames.asInstanceOf[Enumeration[String]]
|
|
|
42 |
while (names.hasMoreElements) {
|
|
|
43 |
val name = names.nextElement; val value = props.getProperty(name)
|
|
|
44 |
append_string(name, result); result.append(" = "); append_string(value, result)
|
|
|
45 |
if (names.hasMoreElements) result.append(", ")
|
|
|
46 |
}
|
|
|
47 |
result.append(")")
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
def encode_properties(props: Properties) = {
|
|
|
51 |
val result = new StringBuilder(40)
|
|
|
52 |
append_properties(props, result)
|
|
|
53 |
result.toString
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
}
|