| author | haftmann |
| Thu, 02 Oct 2008 17:18:36 +0200 | |
| changeset 28462 | 6ec603695aaf |
| parent 27954 | 4558d93e83b7 |
| child 29140 | e7ac5bb20aed |
| permissions | -rw-r--r-- |
| 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 == '\"') {
|
|
|
27954
4558d93e83b7
append_string: proper backslash in character escapes;
wenzelm
parents:
27951
diff
changeset
|
21 |
result.append("\\")
|
| 27951 | 22 |
if (c < 10) result.append('0')
|
23 |
if (c < 100) result.append('0')
|
|
24 |
result.append(c.asInstanceOf[Int].toString) |
|
25 |
} |
|
26 |
else result.append(c) |
|
27 |
} |
|
28 |
result.append("\"")
|
|
29 |
} |
|
30 |
||
31 |
def encode_string(str: String) = {
|
|
32 |
val result = new StringBuilder(str.length + 20) |
|
33 |
append_string(str, result) |
|
34 |
result.toString |
|
35 |
} |
|
36 |
||
37 |
||
38 |
/* properties */ |
|
39 |
||
40 |
def append_properties(props: Properties, result: StringBuilder) = {
|
|
41 |
result.append("(")
|
|
42 |
val names = props.propertyNames.asInstanceOf[Enumeration[String]] |
|
43 |
while (names.hasMoreElements) {
|
|
44 |
val name = names.nextElement; val value = props.getProperty(name) |
|
45 |
append_string(name, result); result.append(" = "); append_string(value, result)
|
|
46 |
if (names.hasMoreElements) result.append(", ")
|
|
47 |
} |
|
48 |
result.append(")")
|
|
49 |
} |
|
50 |
||
51 |
def encode_properties(props: Properties) = {
|
|
52 |
val result = new StringBuilder(40) |
|
53 |
append_properties(props, result) |
|
54 |
result.toString |
|
55 |
} |
|
56 |
||
57 |
} |