69209
|
1 |
(* Title: Pure/Tools/ghc.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Support for GHC: Glasgow Haskell Compiler.
|
|
5 |
*)
|
|
6 |
|
|
7 |
signature GHC =
|
|
8 |
sig
|
|
9 |
val print_codepoint: UTF8.codepoint -> string
|
|
10 |
val print_symbol: Symbol.symbol -> string
|
|
11 |
val print_string: string -> string
|
|
12 |
end;
|
|
13 |
|
|
14 |
structure GHC: GHC =
|
|
15 |
struct
|
|
16 |
|
|
17 |
(** string literals **)
|
|
18 |
|
|
19 |
fun print_codepoint c =
|
|
20 |
(case c of
|
|
21 |
34 => "\\\""
|
|
22 |
| 39 => "\\'"
|
|
23 |
| 92 => "\\\\"
|
|
24 |
| 7 => "\\a"
|
|
25 |
| 8 => "\\b"
|
|
26 |
| 9 => "\\t"
|
|
27 |
| 10 => "\\n"
|
|
28 |
| 11 => "\\v"
|
|
29 |
| 12 => "\\f"
|
|
30 |
| 13 => "\\r"
|
|
31 |
| c =>
|
|
32 |
if c >= 32 andalso c < 127 then chr c
|
|
33 |
else "\\" ^ string_of_int c ^ "\\&");
|
|
34 |
|
|
35 |
fun print_symbol sym =
|
|
36 |
(case Symbol.decode sym of
|
|
37 |
Symbol.Char s => print_codepoint (ord s)
|
|
38 |
| Symbol.UTF8 s => UTF8.decode_permissive s |> map print_codepoint |> implode
|
|
39 |
| Symbol.Sym s => "\\092<" ^ s ^ ">"
|
|
40 |
| Symbol.Control s => "\\092<^" ^ s ^ ">"
|
|
41 |
| _ => translate_string (print_codepoint o ord) sym);
|
|
42 |
|
|
43 |
val print_string = quote o implode o map print_symbol o Symbol.explode;
|
|
44 |
|
|
45 |
end;
|