-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReprPrinter.sml
49 lines (48 loc) · 2.45 KB
/
ReprPrinter.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
signature ReprPrinter =
sig
type repr
val print : repr -> repr
end
functor ReprPrinter
(type repr
val printer : (repr -> repr -> repr) -> repr -> string * repr -> repr
structure Induction : Induction
where type repr = repr
structure Constructor : Constructor
where type repr = repr
structure Deconstructor : Deconstructor
where type repr = repr) :> ReprPrinter
where type repr = repr =
struct
type repr = repr
fun print repr =
let val fromMLString = Induction.Repr.rep_str o Induction.Str.fromMLString
val reprToString = Induction.reprToString
val reprListToString = Induction.reprListToString
fun out state s =
Constructor.constr ("output","out", [state, s])
val init = Constructor.constr ("output","init",[])
val print = printer out init
val result = Induction.Repr.prt_repr
(fn e => print ("EXP",Induction.Repr.rep_exp e))
(fn i => print ("EXP",Induction.Repr.rep_exp
(Induction.Exp.rep_infixopexp i)))
(fn b => print ("EXP",Induction.Repr.rep_exp
(Induction.Exp.rep_bindexp b)))
(fn p => print ("PAT",Induction.Repr.rep_pat p))
(fn t => print ("ATYPE",Induction.Repr.rep_atype t))
(fn s => out init (Induction.Repr.rep_str s))
(fn rr =>
(case Deconstructor.deconstr (Induction.Repr.rep_reprrepr rr) of
("exp",_,_) => print ("EXP",Induction.Repr.rep_reprrepr rr)
| ("infixopexp",_,_) => print ("EXP",Induction.Repr.rep_reprrepr rr)
| ("pat",_,_) => print ("PAT",Induction.Repr.rep_reprrepr rr)
| ("atype",_,_) => print ("ATYPE",Induction.Repr.rep_reprrepr rr)
| ("str",_,_) => out init (Induction.Repr.rep_reprrepr rr)
| ("reprrepr",_,_) => out init
(fromMLString (reprToString (Induction.Repr.rep_reprrepr rr)))
| (t,c,l) => raise Fail ("ReprPrinter.print(repr): no case "^t^"."^c^" "
^(reprListToString l)))) repr
in Constructor.constr ("output","result",[result])
end
end