-
Notifications
You must be signed in to change notification settings - Fork 1
/
sym.sml
159 lines (151 loc) · 3.42 KB
/
sym.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
structure Sym = struct
datatype t =
Arr
| And
| Andalso
| Andtype
| Backslash
| Bar
| Case of int
| Cend
| Char
| Colon
| Comma
| Cstart of int
| Darr
| Datatype of int
| DoubleQuote of int
| Else
| ElseIf
| End
| Eof
| Eq of int
| Exception of int
| Fn of int
| FnArr of int
| Fun of int
| Functor of int
| Handle of int
| Id of int
| If of int
| In
| Include of int
| Infix of int
| Lbrace of int
| Lbrack of int
| Let
| Local of int
| Lparen of int
| Of
| Opaque
| Open of int
| Orelse
| Rbrace
| Rbrack
| Rparen
| Semi
| Sig
| Signature of int
| SingleQuote
| Star
| Struct of int
| Structure of int
| Then
| Type of int
| Val of int
| Wheretype of int
| Withtype
val startsDec = fn
Structure _ => true
| Signature _ => true
| Functor _ => true
| Include _ => true
| Val _ => true
| Fun _ => true
| Datatype _ => true
| Type _ => true
| Exception _ => true
| Open _ => true
| Infix _ => true
| Local _ => true
| _ => false
fun endsExpr s =
startsDec s
orelse
List.mem [Bar, Then, Else, ElseIf, Rbrace, Rparen, Rbrack, Comma
, In, End, Semi, And, Arr, Of, Bar, Darr, Andalso, Orelse
, Withtype, Andtype, Colon, Opaque, Star, Sig ] s
orelse
case s of
Eq _ => true
| Handle _ => true
| Fn _ => true
| FnArr _ => true
| Wheretype _ => true
| Include _ => true
| Struct _ => true
| _ => false
fun int s n = String.concat [s, "(", Int.toString n, ")" ]
(* val closeAfterIndent = fn *)
(* Orelse => true *)
(* | Andalso => true *)
(* | _ => false *)
fun closeAfterIndent _ = false
fun closeBeforeIndent s = not (closeAfterIndent s)
fun toString t = case t of
And => "And"
| Andalso => "Andalso"
| Arr => "Arr"
| Backslash => "Backslash"
| Bar => "Bar"
| Case n => int "Case" n
| Cend => "Cend"
| Char => "Char"
| Colon => "Colon"
| Comma => "Comma"
| Cstart n => int "Cstart" n
| Darr => "Darr"
| Datatype n => int "Datatype" n
| DoubleQuote n => int "DoubleQuote" n
| Else => "Else"
| ElseIf => "ElseIf"
| End => "End"
| Eof => "Eof"
| Eq n => int "Eq" n
| Exception n => int "Exception" n
| Fn n => int "Fn" n
| FnArr n => int "FnArr" n
| Fun n => int "Fun" n
| Functor n => int "Functor" n
| Handle n => int "Handle" n
| Id n => int "Id" n
| If n => int "If" n
| In => "In"
| Include n => int "Include" n
| Infix n => int "Infix" n
| Lbrace n => int "Lbrace" n
| Lbrack n => int "Lbrack" n
| Let => "Let"
| Local n => int "Local" n
| Lparen n => int "Lparen" n
| Of => "Of"
| Opaque => "Opaque"
| Open n => int "Open" n
| Orelse => "Orelse"
| Rbrace => "Rbrace"
| Rbrack => "Rbrack"
| Rparen => "Rparen"
| Semi => "Semi"
| Sig => "Sig"
| Signature n => int "Signature" n
| SingleQuote => "SingleQuote"
| Star => "Star"
| Struct n => int "Struct" n
| Structure n => int "Structure" n
| Then => "Then"
| Type n => int "Type" n
| Val n => int "Val" n
| Wheretype n => int "Wheretype" n
| Andtype => "Andtype"
| Withtype => "Withtype"
end