summaryrefslogtreecommitdiff
path: root/colm/colm.lm
blob: 4cf12923fb569f02f499938d58822cc7a800dee9 (plain)
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# Main region.
lex
	token DEF / 'def' /
	token LEX / 'lex' /
	token END / 'end' /
	token TOKEN / 'token' /
	token RL / 'rl' /
	token IGNORE / 'ignore' /
	token PRINT / 'print' /
	token PRINTS / 'prints' /
	token PRINT_XML / 'print_xml' /
	token PRINT_XML_AC / 'print_xml_ac' /
	token PARSE / 'parse' /
	token PARSE_STOP / 'parse_stop' /
	token CONS / 'construct' | 'cons' /
	token MATCH / 'match' /
	token REQUIRE / 'require' /
	token SEND / 'send' /
	token NAMESPACE / 'namespace' /
	token FOR / 'for' /
	token IF / 'if' /
	token YIELD / 'yield' /
	token WHILE / 'while' /
	token ELSIF / 'elsif' /
	token ELSE / 'else' /
	token IN / 'in' /
	token PARSER / 'parser' | 'accum' /
	token LIST / 'list' /
	token VECTOR / 'vector' /
	token MAP / 'map' /
	token PTR / 'ptr' /
	token ITER / 'iter' /
	token REF / 'ref' /
	token EXPORT / 'export' /
	token RETURN / 'return' /
	token BREAK / 'break' /
	token REJECT / 'reject' /
	token REDUCEFIRST / 'reducefirst' /
	token ALIAS / 'alias' /
	token COMMIT / 'commit' /
	token NEW / 'new' /
	token PREEOF / 'preeof' /
	token GLOBAL / 'global' /
	token EOS / 'eos' /

	token MAKE_TOKEN / 'make_token' /
	token MAKE_TREE / 'make_tree' /

	token TYPEID / 'typeid' /

	token LITERAL /'literal'/
	token CONTEXT /'context'/
	token NI /'ni'/

	token NIL / 'nil' /
	token TRUE / 'true' /
	token FALSE / 'false' /

	token LEFT /'left'/
	token RIGHT /'right'/
	token NONASSOC /'nonassoc'/

	token INCLUDE /'include'/

	token id / 
		( 'a' .. 'z' | 'A' .. 'Z' | '_' ) .
		( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' ) *
	/

	token number / ( '0' .. '9' ) + /

	token lit /
		'\'' . ( ^( '\'' | '\\' ) | '\\' . any )* .  '\''
	/

	token DQ / '\"' / ni
	token TILDE / '~' / ni

	token SQOPEN /'['/
	token SQCLOSE /']'/
	token BAR /'|'/
	token FSLASH /'/'/
	token COLON /':'/
	token DOUBLE_COLON /'::'/
	token DOT /'.'/
	token ARROW /'->'/
	token POPEN /'('/
	token PCLOSE /')'/
	token COPEN /'{'/
	token CCLOSE /'}'/
	token STAR /'*'/
	token QUESTION /'?'/
	token EQUALS /'='/
	token EQEQ /'=='/
	token NEQ /'!='/
	token COMMA /','/
	token LT /'<'/
	token GT /'>'/
	token LTEQ /'<='/
	token GTEQ /'>='/
	token BANG /'!'/
	token DOLLAR /'$'/
	token CARET /'^'/
	token PERCENT /'%'/
	token PLUS /'+'/
	token MINUS /'-'/
	token AMPAMP /'&&'/
	token BARBAR /'||'/

	ignore / ( '\n' | '\t' | ' ' )+ /
	ignore / '#' . ( ^'\n' )* . '\n' /
end

lex
	token CONS_DQ / '\"' /
	token CONS_NL / '\n' /
	token CONS_SQOPEN / '[' /
	token CONS_SQCLOSE / ']' /

	token cons_data 
		/ ( ^( '\n' | '\"' | '[' | ']' | '\\' ) | '\\' . any )+ /
end

lex
	token TILDE_NL / '\n' /
	token tilde_data 
		/ ( ^'\n' )+ /
end

lex
	token lex_id / 
		( 'a' .. 'z' | 'A' .. 'Z' | '_' ) .
		( 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' ) *
	/

	token lex_uint 
		/ ( '0' .. '9' )+ /

	token lex_hex 
		/ '0x' . ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ /

	token lex_lit / 
		'\'' . ( ^( '\'' | '\\' ) | '\\' . any )* . ( '\'' | '\'i' ) |
		'\"' . ( ^( '\"' | '\\' ) | '\\' . any )* . ( '\"' | '\"i' )
	/

	token LEX_DOT /'.'/
	token LEX_BAR /'|'/
	token LEX_AMP /'&'/
	token LEX_DASH /'-'/
	token LEX_POPEN /'('/
	token LEX_PCLOSE /')'/
	token LEX_STAR /'*'/
	token LEX_STARSTAR /'**'/
	token LEX_QUESTION /'?'/
	token LEX_PLUS /'+'/
	token LEX_CARET /'^'/
	token LEX_DOTDOT /'..'/
	token LEX_SQOPEN_POS /'['/ ni
	token LEX_SQOPEN_NEG /'[^'/ ni
	token LEX_FSLASH /'/'/

	token LEX_DASHDASH /'--'/
	token LEX_COLON_GT   /':>'/
	token LEX_COLON_GTGT /':>>'/
	token LEX_LT_COLON   /'<:'/

	ignore / 
		( '\n' | '\t' | ' ' ) .
		( '\n' | '\t' | ' ' )* 
	/

	ignore / '#' . ( ^'\n' )* . '\n' /
end

lex
	token RE_DASH / '-' /
	token RE_CHAR / ^( '\\' | '-' | ']' ) | '\\' . any /
	token RE_SQCLOSE / ']' /
end

def start
	[RootItemList: root_item*]

def root_item
	[RlDef: rl_def] :Rl commit
|	[LiteralDef: literal_def] :Literal commit
|	[TokenDef: token_def] :Token commit
|	[IgnoreDef: ignore_def] :Ignore commit
|	[CflDef: cfl_def] :Cfl commit
|	[RegionDef: region_def] :Region commit
|	[ContextDef: context_def] :Context commit
|	[NamespaceDef: namespace_def] :Namespace commit
|	[FunctionDef: function_def] :Function commit
|	[IterDef: iter_def] :Iter commit
|	[Statement: statement] :Statement commit
|	[GlobalDef: global_def] :Global commit
|	[ExportDef: export_def] :Export commit
|	[PreEofDef: pre_eof_def] :PreEof commit
|	[PrecedenceDef: precedence_def] :Precedence commit
|	[AliasDef: alias_def] :Alias commit
|	[Include: include] :Include commit

def include
	[INCLUDE File: lit]

def precedence_def
	[PredType: pred_type PredTokenList: pred_token_list]

def pred_type
	[Left: LEFT]
|	[Right: RIGHT]
|	[NonAssoc: NONASSOC]

def pred_token_list
	[PredTokenList: pred_token_list COMMA PredToken: pred_token]
|	[PredToken: pred_token]

def pred_token
	[RegionQual: region_qual Id: id]
|	[RegionQual: region_qual Lit: lit]

def pre_eof_def
	[PreEof: PREEOF COPEN LangStmtList: lang_stmt_list CCLOSE]

def alias_def
	[ALIAS Id: id TypeRef: type_ref]

def context_item
	[ContextVarDef: context_var_def] :ContextVar commit
|	[LiteralDef: literal_def] :Literal commit
|	[RlDef: rl_def] :Rl commit
|	[TokenDef: token_def] :Token commit
|	[IgnoreDef: ignore_def] :Ignore commit
|	[CflDef: cfl_def] :Cfl commit
|	[RegionDef: region_def] :Region commit
|	[ContextDef: context_def] :Context commit
|	[FunctionDef: function_def] :Function commit
|	[IterDef: iter_def] :Iter commit
|	[ExportDef: export_def] :Export commit
|	[PreEofDef: pre_eof_def] :PreEof commit
|	[PrecedenceDef: precedence_def] :Precedence commit

def export_def
	[EXPORT VarDef: var_def OptDefInit: opt_def_init]

def global_def
	[GLOBAL VarDef: var_def OptDefInit: opt_def_init]

def iter_def
	[ITER Id: id POPEN ParamVarDefList: param_var_def* PCLOSE
		COPEN LangStmtList: lang_stmt_list CCLOSE]

def reference_type_ref
	[R: REF LT TypeRef: type_ref GT]

def param_var_def
	[Id: id COLON TypeRef: type_ref]
|	[Id: id COLON RefTypeRef: reference_type_ref]

def opt_export
	[Export: EXPORT]
|	[]

def function_def
	[OptExport: opt_export TypeRef: type_ref Id: id 
			POPEN ParamVarDefList: param_var_def* PCLOSE 
			COPEN LangStmtList: lang_stmt_list CCLOSE]

def context_var_def
	[VarDef: var_def]

def context_def
	[CONTEXT Name: id ContextItemList: context_item* END]

def literal_def
	[LITERAL LiteralList: literal_list]

def literal_list
	[LiteralList: literal_list COMMA LiteralItem: literal_item]
|	[LiteralItem: literal_item]

def literal_item
	[NiLeft: opt_no_ignore Lit: lit NiRight: opt_no_ignore]

def opt_no_ignore
	[Ni: NI]
|	[]

def namespace_def
	[NAMESPACE Name: id RootItemList: root_item* END]

def obj_var_list
	[]

def opt_reduce_first
	[ReduceFirst: REDUCEFIRST]
|	[]

def cfl_def
	[DEF DefId: id 
		VarDefList: var_def* 
		OptReduceFirst: opt_reduce_first
		ProdList: prod_list]

def region_def
	[LEX RootItemList: root_item* END]

def rl_def
	[RL Id: id LEX_FSLASH Expr: lex_expr LEX_FSLASH]

def opt_lex_expr
	[Expr: lex_expr]
|	[]

def token_def
	[TOKEN Id: id VarDefList: var_def*
		NiLeft: opt_no_ignore
		LEX_FSLASH OptExpr: opt_lex_expr LEX_FSLASH
		NiRight: opt_no_ignore
		OptTranslate: opt_translate]

def opt_translate
	[COPEN LangStmtList: lang_stmt_list CCLOSE]
|	[]

def opt_id
	[Id: id]
|	[]

def ignore_def
	[I: IGNORE OptId: opt_id LEX_FSLASH OptExpr: opt_lex_expr LEX_FSLASH]

def prod_el
	[OptName: opt_prod_el_name RegionQual: region_qual Id: id OptRepeat: opt_repeat]
|	[OptName: opt_prod_el_name RegionQual: region_qual Lit: lit OptRepeat: opt_repeat]

def opt_prod_el_name
	[Name: id COLON]
|	[]

def prod_el_list
	[ProdElList: prod_el_list ProdEl: prod_el]
|	[]

def opt_commit
	[Commit: COMMIT]
|	[]

def opt_prod_name
	[COLON Name: id]
|	[]


def prod
	[Open: SQOPEN ProdElList: prod_el_list SQCLOSE 
		OptName: opt_prod_name
		OptCommit: opt_commit
		OptReduce: opt_reduce]

def opt_reduce
	[COPEN LangStmtList: lang_stmt_list CCLOSE]
|	[]

def prod_list
	[ProdList: prod_list BAR Prod: prod]
|	[Prod: prod]

def statement
	[Print: print_stmt]
|	[Expr: expr_stmt]
|	[VarDef: var_def OptDefInit: opt_def_init]
|	[FOR ForDecl: id COLON TypeRef: type_ref IN IterCall: iter_call
		BlockOrSingle: block_or_single]
|	[IF IfExpr: code_expr BlockOrSingle: block_or_single ElsifList: elsif_list]
|	[WHILE WhileExpr: code_expr BlockOrSingle: block_or_single]
|	[LhsVarRef: var_ref EQUALS CodeExpr: code_expr]
|	[YIELD YieldVarRef: var_ref]
|	[RETURN ReturnExpr: code_expr]
|	[Break: BREAK]
|	[Reject: REJECT]

def elsif_list
	[ElsifClause: elsif_clause ElsifList: elsif_list]
|	[OptionalElse: optional_else]

def elsif_clause
	[ELSIF ElsifExpr: code_expr BlockOrSingle: block_or_single]

def optional_else
	[ELSE BlockOrSingle: block_or_single]
|	[]

def iter_call
	[E1 VarRef: var_ref POPEN CodeExprList: code_expr* PCLOSE]
|	[E2 Id: id]
|	[E3 Expr: code_expr]

def block_or_single
	[COPEN LangStmtList: lang_stmt_list CCLOSE]
|	[Statement: statement]

def require_pattern
	[R: REQUIRE VarRef: var_ref Pattern: pattern]

def opt_require_stmt
	[Require: require_pattern LangStmtList: lang_stmt_list]
|	[]

def lang_stmt_list
	[StmtList: statement* OptRequire: opt_require_stmt]

def opt_def_init
	[EQUALS CodeExpr: code_expr]
|	[]

def var_def
	[Id: id COLON TypeRef: type_ref]

def print_stmt
	[Tree: PRINT O: POPEN CodeExprList: code_expr* PCLOSE]
|	[PrintStream: PRINTS O: POPEN CodeExprList: code_expr* PCLOSE]
|	[Xml: PRINT_XML O: POPEN CodeExprList: code_expr* PCLOSE]
|	[XmlAc: PRINT_XML_AC O: POPEN CodeExprList: code_expr* PCLOSE]

def expr_stmt
	[CodeExpr: code_expr]

def code_expr
	[Expr: code_expr AmpAmp: AMPAMP Relational: code_relational]
|	[Expr: code_expr BarBar: BARBAR Relational: code_relational]
|	[Relational: code_relational]

def code_relational
	[Relational: code_relational EqEq: EQEQ Additive: code_additive]
|	[Relational: code_relational Neq: NEQ Additive: code_additive]
|	[Relational: code_relational Lt: LT Additive: code_additive]
|	[Relational: code_relational Gt: GT Additive: code_additive]
|	[Relational: code_relational LtEq: LTEQ Additive: code_additive]
|	[Relational: code_relational GtEq: GTEQ Additive: code_additive]
|	[Additive: code_additive]

def code_additive
	[Additive: code_additive Plus: PLUS Multiplicitive: code_multiplicitive]
|	[Additive: code_additive Minus: MINUS Multiplicitive: code_multiplicitive]
|	[Multiplicitive: code_multiplicitive]

def code_multiplicitive
	[Multiplicitive: code_multiplicitive Star: STAR Unary: code_unary]
|	[Multiplicitive: code_multiplicitive Fslash: FSLASH Unary: code_unary]
|	[Unary: code_unary]

def code_unary
	[Bang: BANG Factor: code_factor]
|	[Dollar: DOLLAR Factor: code_factor]
|	[Caret: CARET Factor: code_factor]
|	[Percent: PERCENT Factor: code_factor]
|	[Factor: code_factor]

def opt_eos
	[Eos: DOT]
|	[Eos: EOS]
|	[]

def code_factor
	[Number: number]
|	[Lit: lit]
|	[VarRef: var_ref POPEN CodeExprList: code_expr* PCLOSE]
|	[VarRef: var_ref]
|	[Nil: NIL]
|	[True: TRUE]
|	[False: FALSE]
|	[POPEN ParenCodeExpr: code_expr PCLOSE]
|	[Send: SEND ToVarRef: var_ref Accumulate: accumulate OptEos: opt_eos]
|	[Parse: PARSE OptCapture: opt_capture TypeRef: type_ref
		OptFieldInit: opt_field_init Accumulate: accumulate]
|	[ParseStop: PARSE_STOP OptCapture: opt_capture TypeRef: type_ref
		OptFieldInit: opt_field_init Accumulate: accumulate]
|	[Cons: CONS OptCapture: opt_capture TypeRef: type_ref
		OptFieldInit: opt_field_init Constructor: constructor]
|	[MATCH MatchVarRef: var_ref Pattern: pattern]
|	[String: cstring]
|	[TypeRef: type_ref IN InVarRef: var_ref]
|	[MAKE_TREE POPEN MakeTreeExprList: code_expr* PCLOSE]
|	[MAKE_TOKEN POPEN MakeTokenExprList: code_expr* PCLOSE]
|	[TYPEID LT TypeIdTypeRef: type_ref GT]
|	[NEW NewCodeFactor: code_factor]

def type_ref
	[RegionQual: region_qual DirectId: id OptRepeat: opt_repeat]
|	[PTR LT RegionQual: region_qual PtrId: id OptRepeat: opt_repeat GT]
|	[MAP LT MapKeyType: type_ref MapValueType: type_ref GT]
|	[LIST LT ListType: type_ref GT]
|	[VECTOR LT VectorType: type_ref GT]
|	[PARSER LT ParserType: type_ref GT]

def region_qual
	[RegionQual: region_qual Id: id DOUBLE_COLON]
|	[]

def opt_repeat
	[Star: STAR]
|	[Plus: PLUS]
|	[Question: QUESTION]
|	[]

def opt_capture
	[Id: id COLON]
|	[]

def opt_field_init
	[POPEN FieldInitList: field_init* PCLOSE]
|	[]

def field_init
	[CodeExpr: code_expr]


#
# Pattern
#

def opt_label
	[Id: id COLON]
|	[]

def dq_lit_term
	[CONS_DQ] | [Nl: CONS_NL]

def opt_tilde_data
	[tilde_data]
|	[]

def pattern_el_lel
	[RegionQual: region_qual Id: id OptRepeat: opt_repeat]
|	[RegionQual: region_qual Lit: lit OptRepeat: opt_repeat]

def pattern_el
	[OptLabel: opt_label TypeOrLit: pattern_el_lel]
|	[DQ LitpatElList: litpat_el* Term: dq_lit_term]
|	[TILDE TildeData: opt_tilde_data Nl: TILDE_NL]

def litpat_el
	[ConsData: cons_data]
|	[CONS_SQOPEN PatternElList: pattern_el* CONS_SQCLOSE]

def pattern_top_el
	[DQ LitpatElList: litpat_el* Term: dq_lit_term]
|	[TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[SQOPEN PatternElList: pattern_el* SQCLOSE]

def pattern_list
	[PatternList: pattern_list PatternTopEl: pattern_top_el]
|	[PatternTopEl: pattern_top_el]

def pattern
	[PatternList: pattern_list]

#
# Constructor List
#

def E1 []
def E2 []
def E3 []

def cons_el
	[E1 RegionQual: region_qual Lit: lit]
|	[E1 DQ LitConsElList: lit_cons_el* Term: dq_lit_term]
|	[E1 TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[E2 CodeExpr: code_expr]

def lit_cons_el
	[ConsData: cons_data]
|	[CONS_SQOPEN ConsElList: cons_el* CONS_SQCLOSE]

def cons_top_el
	[DQ LitConsElList: lit_cons_el* Term: dq_lit_term]
|	[TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[SQOPEN ConsElList: cons_el* SQCLOSE]

def cons_list
	[ConsTopEl: cons_top_el ConsList: cons_list]
|	[ConsTopEl: cons_top_el]

def constructor
	[ConsList: cons_list]


#
# Accumulate
#

def accum_el
	[E1 DQ LitAccumElList: lit_accum_el* Term: dq_lit_term]
|	[E1 TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[E2 CodeExpr: code_expr]

def lit_accum_el
	[ConsData: cons_data]
|	[CONS_SQOPEN AccumElList: accum_el* CONS_SQCLOSE]

def accum_top_el
	[DQ LitAccumElList: lit_accum_el* Term: dq_lit_term]
|	[TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[SQOPEN AccumElList: accum_el* SQCLOSE]

def accum_list
	[AccumTopEl: accum_top_el AccumList: accum_list]
|	[AccumTopEl: accum_top_el]

def accumulate
	[AccumList: accum_list]

#
# String List
#

def string_el
	[E1 DQ LitStringElList: lit_string_el* Term: dq_lit_term]
|	[E1 TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[E2 CodeExpr: code_expr]

def lit_string_el
	[ConsData: cons_data]
|	[CONS_SQOPEN StringElList: string_el* CONS_SQCLOSE]

def string_top_el
	[DQ LitStringElList: lit_string_el* Term: dq_lit_term]
|	[TILDE TildeData: opt_tilde_data Nl: TILDE_NL]
|	[SQOPEN StringElList: string_el* SQCLOSE]

def string_list
	[StringTopEl: string_top_el StringList: string_list]
|	[StringTopEl: string_top_el]

def cstring
	[StringList: string_list]

#
# Variable References
#

def var_ref
	[Qual: qual Id: id]

def qual
	[Qual: qual Id: id Dot: DOT]
|	[Qual: qual Id: id Arrow: ARROW]
|	[]

#
# Lexical analysis.
#

def lex_expr
	[Expr: lex_expr LEX_BAR Term: lex_term] :Bar
|	[Expr: lex_expr LEX_AMP Term: lex_term] :Amp
|	[Expr: lex_expr LEX_DASH Term: lex_term] :Dash
|	[Expr: lex_expr LEX_DASHDASH Term: lex_term] :DashDash
|	[Term: lex_term] :Base

def opt_lex_dot
	[LEX_DOT]
|	[]

def lex_term
	[Term: lex_term opt_lex_dot FactorRep: lex_factor_rep] :Dot
|	[Term: lex_term LEX_COLON_GT FactorRep: lex_factor_rep] :ColonGt
|	[Term: lex_term LEX_COLON_GTGT FactorRep: lex_factor_rep] :ColonGtGt
|	[Term: lex_term LEX_LT_COLON FactorRep: lex_factor_rep] :LtColon
|	[FactorRep: lex_factor_rep] :Base

def lex_factor_rep
	[FactorRep: lex_factor_rep Star: LEX_STAR] :Star
|	[FactorRep: lex_factor_rep StarStar: LEX_STARSTAR] :StarStar
|	[FactorRep: lex_factor_rep Plus: LEX_PLUS] :Plus
|	[FactorRep: lex_factor_rep Question: LEX_QUESTION] :Question
|	[FactorRep: lex_factor_rep COPEN Exact: lex_uint CCLOSE ] :Exact
|	[FactorRep: lex_factor_rep COPEN COMMA Max: lex_uint CCLOSE ] :Max
|	[FactorRep: lex_factor_rep COPEN Min: lex_uint COMMA CCLOSE ] :Min
|	[FactorRep: lex_factor_rep COPEN Low: lex_uint COMMA High: lex_uint CCLOSE ] :Range
|	[FactorNeg: lex_factor_neg] :Base

def lex_factor_neg
	[LEX_CARET FactorNeg: lex_factor_neg] :Caret
|	[Factor: lex_factor] :Base

def lex_range_lit
	[Lit: lex_lit] :Lit
|	[Number: lex_num] :Number

def lex_num
	[lex_uint]
|	[lex_hex]

#|	[LEX_DASH num]

def lex_factor
	[Literal: lex_lit] :Literal
|	[Id: lex_id] :Id
|	[Number: lex_uint] :Number
|	[Hex: lex_hex] :Hex
|	[Low: lex_range_lit LEX_DOTDOT High: lex_range_lit] :Range
|	[LEX_SQOPEN_POS PosData: reg_or_data RE_SQCLOSE] :PosOrBlock
|	[LEX_SQOPEN_NEG NegData: reg_or_data RE_SQCLOSE] :NegOrBlock
|	[LEX_POPEN Expr: lex_expr LEX_PCLOSE] :Paren

def reg_or_data
	[Data: reg_or_data Char: reg_or_char] :Data
|	[] :Base

def reg_or_char
	[Char: RE_CHAR] :Char
|	[Low: RE_CHAR RE_DASH High: RE_CHAR] :Range