-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_parser.cmyacc
380 lines (316 loc) · 12.6 KB
/
make_parser.cmyacc
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
sml
name MakeParser
terminal NUMBER of int
terminal STRING of string
terminal CHAR of char
terminal LOWER_IDENT of string
terminal UPPER_IDENT of string
terminal QUOTE_IDENT of string
terminal VAL_OP of string
terminal EQUAL
terminal COLON
terminal COLON_GT
terminal COLON_EQ
terminal COLON_COLON precr 50
terminal RARROW precr 20
terminal BAR
terminal UNDERSCORE
terminal ASTERISK precl 70
terminal COMMA
terminal DOLLAR precr 0
terminal PLUS precl 60
terminal MINUS precl 60
terminal GT precl 40
terminal LT precl 40
terminal GT_EQ precl 40
terminal LT_EQ precl 40
terminal GT_GT_GT precr 10
terminal LT_LT_LT precr 10
terminal EQUAL_EQUAL precl 40
terminal SLASH_EQUAL precl 40
terminal LT_GT precl 60
terminal LT_PLUS_GT precl 60
terminal LPAREN of left_paren_kind_ref
terminal RPAREN
terminal LBRACE of left_paren_kind_ref
terminal RBRACE
terminal LBRACK
terminal RBRACK
terminal LPAREN_PROJ
terminal LBRACE_PROJ
terminal DOT
terminal SUBMODULE
terminal STRUCT
terminal SIG
terminal VAL
terminal TYPE
terminal MODULE
terminal SIGNATURE
terminal INCLUDE
terminal OPEN
terminal WHERE
terminal DATATYPE
terminal OF
terminal LET
terminal IN
terminal FUN
terminal FUNCTION
terminal FUNCTOR
terminal IF
terminal THEN
terminal ELSE
terminal FALSE
terminal TRUE
terminal MATCH
terminal WITH
terminal END
terminal REC
terminal AND
terminal PACK
terminal UNPACK
nonterminal Unit : program_unit =
1:Bindings => unit_bindings
1:Submodule 2:Unit => unit_cons
nonterminal Submodule : submodule =
SUBMODULE 1:STRING => submodule_include
SUBMODULE 1:UPPER_IDENT EQUAL 2:STRING => submodule_bind
nonterminal Module : module =
1:ModuleColon => module_colon
1:ModuleFunctor => module_functor
1:ModuleApp 2:ModuleFunctor => app_to_functor
UNPACK 1:ExprApp COLON 2:Signature => unpack
LET 1:Bindings IN 2:Module => let_module
nonterminal ModuleFunctor : module =
FUNCTOR 1:MParams RARROW 2:Module => functor_
FUN 1:MParams RARROW 2:Module => functor_
nonterminal MParams : mparams =
1:MParam => mparam1
1:MParam 2:MParams => mparam_cons
nonterminal MParam : mparam =
LPAREN 1:UPPER_IDENT COLON 2:Signature RPAREN => functor_param
nonterminal MParams0 : mparam_list =
/* empty */ => empty_mparam_list
1:MParams => mparam_list_from_non_empty
nonterminal ModuleColon : module =
1:ModuleApp => module_app
1:ModuleColon COLON 2:Signature => transparent_ascription
1:ModuleColon COLON_GT 2:Signature => seal
nonterminal ModuleApp : module =
1:ModuleAtom => module_atom
1:ModuleApp 2:ModuleAtom => app_module
nonterminal ModuleAtom : module =
LPAREN 1:Module RPAREN => paren_module
LPAREN_PROJ 1:Module RPAREN DOT 2:UPPER_IDENT 3:Projs => proj
STRUCT 1:Bindings END 2:Projs => bindings
LBRACE 1:Bindings RBRACE => bindings0
LBRACE_PROJ 1:Bindings RBRACE DOT 2:UPPER_IDENT 3:Projs => bindings1
1:UPPER_IDENT 2:Projs => module_ident
/* `Path` is always followed by `DOT` */
nonterminal Path : module =
LPAREN_PROJ 1:Module RPAREN => path
STRUCT 1:Bindings END => path_bindings
LBRACE_PROJ 1:Bindings RBRACE => path_bindings
1:UPPER_IDENT => path_module_ident
nonterminal Projs : projs =
/* empty */ => proj_none
DOT 1:UPPER_IDENT 2:Projs => proj_some
nonterminal UIDs1 : string_non_empty =
DOT 1:UPPER_IDENT 2:UIDs => uids1
nonterminal UIDs : string_list =
/* empty */ => uids_empty
DOT 1:UPPER_IDENT 2:UIDs => uids_cons
nonterminal LowerProj : string_non_empty =
DOT 1:LOWER_IDENT => lower_proj
DOT 1:UPPER_IDENT 2:LowerProj => cons_lower_proj
nonterminal Bindings : binding_list =
/* empty */ => empty_bindings
1:Binding 2:Bindings => cons_bindings
OPEN 1:Module 2:Bindings => open_binding
nonterminal Binding : binding =
VAL 1:ValBinding => val_binding_
TYPE 1:LOWER_IDENT 2:TypeVars EQUAL 3:Type => type_binding
MODULE 1:UPPER_IDENT 2:MParams0 3:SigAnn EQUAL 4:Module => module_binding
SIGNATURE 1:UPPER_IDENT EQUAL 2:Signature => signature_binding
INCLUDE 1:Module => include_binding
DATATYPE 1:LOWER_IDENT 2:TypeVars EQUAL 3:DatatypeDec 4:DatatypeAnd => datatype_binding
nonterminal SigAnn : signature_ann =
/* empty */ => no_sig_ann
COLON 1:Signature => ann_ascribe
COLON_GT 1:Signature => ann_seal
nonterminal ValBinding : val_binding =
1:Pattern EQUAL 2:Expr => val_binding1
1:LOWER_IDENT 2:TypeVars 3:Params EQUAL 4:Expr => val_binding2
REC 1:LOWER_IDENT 2:Params EQUAL 3:Expr 4:RecBinding => val_rec_binding
nonterminal RecBinding : val_rec_map =
/* empty */ => empty_val_rec
AND 1:LOWER_IDENT 2:Params EQUAL 3:Expr 4:RecBinding => val_rec_and
nonterminal OptBar : opt_bar =
/* empty */ => no_bar
BAR => bar
nonterminal DatatypeDec : datatype_dec =
BAR => empty_datatype
OptBar 1:UPPER_IDENT 2:Datatype1 => head_d1
OptBar 1:UPPER_IDENT OF 2:Type 3:Datatype1 => head_d2
nonterminal Datatype1 : datatype_dec =
/* empty */ => empty_d
BAR 1:UPPER_IDENT 2:Datatype1 => cons_d1
BAR 1:UPPER_IDENT OF 2:Type 3:Datatype1 => cons_d2
nonterminal DatatypeAnd : datatype_and =
/* empty */ => datatype_no_and
AND 1:LOWER_IDENT 2:TypeVars EQUAL 3:DatatypeDec 4:DatatypeAnd => datatype_and_
nonterminal TypeVars : type_vars =
1:TypeVarsAcc => from_type_vars_acc
nonterminal TypeVarsAcc : type_var_acc =
/* empty */ => empty_type_vars
1:TypeVar 2:TypeVarsAcc => cons_type_vars
nonterminal TypeVar : type_var =
1:QUOTE_IDENT => quote_ident
nonterminal Signature : signature_ =
1:SigWhere => sig_where
LPAREN 1:UPPER_IDENT COLON 2:Signature RPAREN RARROW 3:Signature => impure_functor
1:SigAtom RARROW 2:Signature => impure_functor_simple
LET 1:Bindings IN 2:Signature => let_sig
nonterminal SigWhere : signature_ =
1:SigAtom => sig_atom
1:SigWhere WHERE TYPE 2:LongType 3:TypeVars EQUAL 4:Type => where_type
1:SigWhere WHERE TYPE 2:LongType 3:TypeVars COLON_EQ 4:Type => where_type_destructive
nonterminal SigAtom : signature_ =
LPAREN 1:Signature RPAREN => paren_signature
SIG 1:Decls END => decls
LBRACE 1:Decls RBRACE => decls
1:UPPER_IDENT => signature_ident
1:Path 2:UIDs1 => sig_path
nonterminal LongType : long_type =
1:LOWER_IDENT => short_type_ident
1:UPPER_IDENT DOT 2:LongType => long_type_ident
nonterminal Decls : decl_list =
/* empty */ => empty_decls
1:Decl 2:Decls => cons_decls
OPEN 1:Module 2:Decls => open_decl
nonterminal Decl : decl =
VAL 1:LOWER_IDENT 2:TypeVars COLON 3:Type => val_decl
TYPE 1:LOWER_IDENT 2:TypeVars EQUAL 3:Type => transparent_type_decl
TYPE 1:LOWER_IDENT 2:TypeVars => opaque_type_decl
MODULE 1:UPPER_IDENT 2:MParams0 COLON 3:Signature => module_decl
SIGNATURE 1:UPPER_IDENT EQUAL 2:Signature => signature_decl
INCLUDE 1:Signature => include_decl
DATATYPE 1:LOWER_IDENT 2:TypeVars EQUAL 3:DatatypeDec 4:DatatypeAnd => datatype_decl
nonterminal Expr : expr =
1:ExprApp => expr_app
1:ExprBin_ => expr_binary
LET 1:Bindings IN 2:Expr => let_expr
OPEN 1:Module IN 2:Expr => open_in
FUN 1:Params RARROW 2:Expr => lambda
IF 1:Expr THEN 2:Expr ELSE 3:Expr => if_expr
MATCH 1:Expr WITH 2:Branches END => match
FUNCTION 1:Branches END => function
PACK 1:ModuleApp COLON 2:Signature => pack
1:VAL_OP 2:Pattern EQUAL 3:Expr IN 4:Expr => val_op
nonterminal ExprBin_ : expr =
1:ExprBin COLON_COLON 2:Expr => cons_list_expr
1:ExprBin DOLLAR 2:Expr => expr_dollar
1:ExprBin PLUS 2:Expr => expr_plus
1:ExprBin MINUS 2:Expr => expr_minus
1:ExprBin ASTERISK 2:Expr => expr_times
1:ExprBin GT 2:Expr => expr_gt
1:ExprBin LT 2:Expr => expr_lt
1:ExprBin GT_EQ 2:Expr => expr_gt
1:ExprBin LT_EQ 2:Expr => expr_lt
1:ExprBin GT_GT_GT 2:Expr => expr_gt_gt_gt
1:ExprBin LT_LT_LT 2:Expr => expr_lt_lt_lt
1:ExprBin EQUAL_EQUAL 2:Expr => expr_equal_equal
1:ExprBin SLASH_EQUAL 2:Expr => expr_slash_equal
1:ExprBin LT_GT 2:Expr => expr_lt_gt
1:ExprBin LT_PLUS_GT 2:Expr => expr_lt_plus_gt
nonterminal ExprBin : expr =
1:ExprApp => expr_app
1:ExprBin COLON_COLON 2:ExprBin => cons_list_expr
1:ExprBin PLUS 2:ExprBin => expr_plus
1:ExprBin MINUS 2:ExprBin => expr_minus
1:ExprBin ASTERISK 2:ExprBin => expr_times
1:ExprBin GT 2:ExprBin => expr_gt
1:ExprBin LT 2:ExprBin => expr_lt
1:ExprBin GT_EQ 2:ExprBin => expr_gt
1:ExprBin LT_EQ 2:ExprBin => expr_lt
1:ExprBin GT_GT_GT 2:ExprBin => expr_gt_gt_gt
1:ExprBin LT_LT_LT 2:ExprBin => expr_lt_lt_lt
1:ExprBin EQUAL_EQUAL 2:ExprBin => expr_equal_equal
1:ExprBin SLASH_EQUAL 2:ExprBin => expr_slash_equal
1:ExprBin LT_GT 2:ExprBin => expr_lt_gt
1:ExprBin LT_PLUS_GT 2:ExprBin => expr_lt_plus_gt
nonterminal ExprApp : expr =
1:ExprAtom => expr_atom
1:ExprApp 2:ExprAtom => app
nonterminal Tuple : expr_non_empty =
1:Expr => expr1
1:Expr COMMA 2:Tuple => cons_expr
nonterminal ExprAtom : expr =
LPAREN 1:Tuple RPAREN => tuple_or_paren
1:Literal => lit
1:LOWER_IDENT => val_ident
1:Path 2:LowerProj => expr_path
1:UPPER_IDENT => constructor
1:Path 2:UIDs1 => constructor_path
LBRACK 1:List RBRACK => list
nonterminal List : expr_list =
/* empty */ => empty_list
1:Expr => singleton_list
1:Expr COMMA 2:NonEmpty => cons_list
nonterminal NonEmpty : expr_non_empty =
1:Expr => singleton_non_empty
1:Expr COMMA 2:NonEmpty => cons_non_empty
nonterminal Branches : branches =
/* empty */ => empty_branches
OptBar 1:Branch 2:Branches1 => cons_branches
nonterminal Branches1 : branches =
/* empty */ => empty_branches1
BAR 1:Branch 2:Branches1 => cons_branches1
nonterminal Branch : branch =
1:PatternInfix RARROW 2:Expr => branch_expr
nonterminal Literal : literal =
1:NUMBER => number
1:STRING => string_literal
1:CHAR => char_literal
FALSE => bool_false
TRUE => bool_true
LPAREN RPAREN => unit_literal
nonterminal Params : params =
1:PatternAtom => param1
1:PatternAtom 2:Params => cons_params
nonterminal Pattern : pattern =
1:PatternInfix => pattern_infix
1:PatternInfix COLON 2:Type => typed_pattern
nonterminal PatternInfix : pattern =
1:PatternTerm => pattern_term
1:PatternTerm COLON_COLON 2:PatternInfix => cons_list_pattern
nonterminal PatternTerm : pattern =
1:PatternAtom => pattern_atom
1:UPPER_IDENT 2:PatternAtom => constructor_pattern2
1:Path 2:UIDs1 3:PatternAtom => constructor_path_pattern2
nonterminal PatternAtom : pattern =
LPAREN 1:TuplePattern RPAREN => tuple_or_paren_pattern
1:LOWER_IDENT => var_pattern
1:UPPER_IDENT => constructor_pattern1
1:Path 2:UIDs1 => constructor_path_pattern1
UNDERSCORE => wildcard
LBRACK RBRACK => nil_pattern
nonterminal TuplePattern : pattern_non_empty =
1:Pattern => pattern1
1:Pattern COMMA 2:TuplePattern => cons_pattern
nonterminal Type : typ =
1:TupleType => tuple_type
LET 1:Bindings IN 2:Type => let_type
1:TupleType RARROW 2:Type => arrow
nonterminal TupleType : type_list =
1:TypeApp => type_app
1:TypeApp ASTERISK 2:TupleType => cons_tuple
nonterminal TypeApp : typ =
1:TypeAtom => type_atom
1:TypeApp 2:TypeAtom => app_type
PACK 1:SigAtom => package_type
nonterminal TypeAtom : typ =
LPAREN 1:Type RPAREN => paren_type
1:LOWER_IDENT => type_ident
1:Path 2:LowerProj => type_path
1:TypeVar => type_variable
start Unit