| author | haftmann |
| Thu, 15 Jan 2009 14:52:35 +0100 | |
| changeset 29498 | 49675edf127c |
| parent 29140 | e7ac5bb20aed |
| child 29552 | 5b21c79785b0 |
| permissions | -rw-r--r-- |
| 27951 | 1 |
/* Title: Pure/Tools/isabelle_syntax.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Isabelle outer syntax. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
import java.util.{Properties, Enumeration}
|
|
10 |
||
11 |
||
12 |
object IsabelleSyntax {
|
|
13 |
||
14 |
/* string token */ |
|
15 |
||
16 |
def append_string(str: String, result: StringBuilder) = {
|
|
17 |
result.append("\"")
|
|
18 |
for (c <- str) {
|
|
19 |
if (c < 32 || c == '\\' || c == '\"') {
|
|
|
27954
4558d93e83b7
append_string: proper backslash in character escapes;
wenzelm
parents:
27951
diff
changeset
|
20 |
result.append("\\")
|
| 27951 | 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 |
} |