-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexpressioncvt.sml
95 lines (79 loc) · 3.14 KB
/
expressioncvt.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(* $Id$
*
* Copyright (c) 2008 Timothy Bourke (University of NSW and NICTA)
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the "BSD License" which is distributed with the
* software in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the BSD
* License for more details.
*)
(* TODO:
* rename? now that it also includes some conversion functions for
declarations and environments.
*)
structure ExpressionCvt :> EXPRESSION_CVT
=
struct
structure E = Expression
structure D = Declaration
structure StringPPS = PPStreamFn (structure Token = StringToken
and Device = PPDevString)
structure StringPPD = PPDescFn (StringPPS)
structure StringEPP = ExpressionPPFn (structure PPD=StringPPD and E=E)
structure OutPPS = PPStreamFn (structure Token = StringToken
and Device = SimpleTextIODev)
structure OutPPD = PPDescFn (OutPPS)
structure OutEPP = ExpressionPPFn (structure PPD=OutPPD and E=E)
structure OutDPP = DeclarationPPFn (structure PPD=OutPPD
and D=D and EPP=OutEPP)
type expr = E.expr
and ty = E.ty
and var = E.var
and decl = D.decl
type outstream = TextIO.StreamIO.outstream
val width = ref 76
fun ppdToString pp_desc = let
val dev = PPDevString.openDev {dst="", wid=(!width)}
val strm = StringPPD.PPS.openStream dev
in
StringEPP.print strm pp_desc;
StringPPD.PPS.closeStream strm;
PPDevString.toString dev
end
fun ppdToOutput (os, pp_desc) = let
val dev = SimpleTextIODev.openDev {dst=TextIO.mkOutstream os,
wid=Settings.maxLabelWidth()}
val strm = OutPPD.PPS.openStream dev
in
OutEPP.print strm pp_desc;
OutPPD.PPS.closeStream strm
end
structure Expr = struct
fun toString e = ppdToString (StringEPP.fromExpr e)
(*val fromString = UppaalParse.parseExpression "ExpressionCvt"*)
fun toStream (os, e) = ppdToOutput (os, OutEPP.fromExpr e)
end
structure Ty = struct
fun toString t = ppdToString (StringEPP.fromType t)
fun toStream (os, t) = ppdToOutput (os, OutEPP.fromType t)
end
structure Var = struct
fun toString v = ppdToString (StringEPP.fromVar v)
fun toStream (os, v) = ppdToOutput (os, OutEPP.fromVar v)
end
structure Decl = struct
fun toStream (os, d) = ppdToOutput (os, OutDPP.fromDecl d)
end
fun selectToStream (os, sels) = ppdToOutput (os, OutEPP.fromSelects sels)
fun selectToString sels = ppdToString (StringEPP.fromSelects sels)
fun syncToStream (os, sync) = ppdToOutput (os, OutEPP.fromSync sync)
fun syncToString sync = ppdToString (StringEPP.fromSync sync)
fun exprlistToStream (os, exprs) = ppdToOutput (os,OutEPP.fromExprList exprs)
fun exprlistToString exprs = ppdToString (StringEPP.fromExprList exprs)
fun paramlistToStream (os, params) = ppdToOutput(os,OutDPP.fromParams params)
end