equal
deleted
inserted
replaced
|
1 /* Title: Pure/ML/ml_syntax.scala |
|
2 Author: Makarius |
|
3 |
|
4 Concrete ML syntax for basic values. |
|
5 */ |
|
6 |
|
7 package isabelle |
|
8 |
|
9 |
|
10 object ML_Syntax |
|
11 { |
|
12 private def print_chr(c: Byte): String = |
|
13 c match { |
|
14 case 34 => "\\\"" |
|
15 case 92 => "\\\\" |
|
16 case 9 => "\\t" |
|
17 case 10 => "\\n" |
|
18 case 12 => "\\f" |
|
19 case 13 => "\\r" |
|
20 case _ => |
|
21 if (c < 0) "\\" + Library.signed_string_of_int(256 + c) |
|
22 else if (c < 32) new String(Array[Char](92, 94, (c + 64).toChar)) |
|
23 else if (c < 127) Symbol.ascii(c.toChar) |
|
24 else "\\" + Library.signed_string_of_int(c) |
|
25 } |
|
26 |
|
27 def print_char(s: Symbol.Symbol): String = |
|
28 if (s.startsWith("\\<")) s |
|
29 else UTF8.bytes(s).iterator.map(print_chr(_)).mkString |
|
30 |
|
31 def print_string(str: String): String = |
|
32 quote(Symbol.iterator(str).map(print_char(_)).mkString) |
|
33 |
|
34 def print_string_raw(str: String): String = |
|
35 quote(UTF8.bytes(str).iterator.map(print_chr(_)).mkString) |
|
36 } |