-
Notifications
You must be signed in to change notification settings - Fork 1
/
urgent.exrbnf
113 lines (88 loc) · 3.87 KB
/
urgent.exrbnf
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
START : <BOF> 'module' module list(stmt) { Module($2, $3) } ;
ID : (<UPPER>|<LOWER>) { *$0 } ;
LET : 'let' { $0 } | 'def' { $0 } ;
bind : bop '=' expr { (@1, *$0, $2) }
| ID '=' expr { (@1, $0, $2) }
| '!' '=' expr { (@1, *$0, $2) }
;
binds : separated_list(',', bind) { $0 };
stmt : LET binds { Let(@0, False, $1) }
| 'rec' binds { Let(@0, True, $1) }
| 'do' expr { Do(@0, $1) }
| 'open' module { Open(@0, $1) }
| 'import' module { Import(@0, $1) }
| 'infixl' bop <INT> { Infix(@0, False, *$1, int(*$2)) }
| 'infixr' bop <INT> { Infix(@0, True, *$1, int(*$2)) }
| 'data' separated_list(',', cons) { Data(@0, $1) }
;
cons : <UPPER> slots { Cons(@0, *$0, $1) }
| <UPPER> { Cons(@0, *$0, []) }
;
module : separated_list('.', ID) { $0 };
slot : ID { $0 }
| '_' { *$0 }
;
slots : '(' separated_list(',', slot) ')' { $1 };
expr : bind_expr { $0 }
| expr '?' expr 'else' expr { If(@1, $0, $2, $4) }
| expr 'match' match_cases { Match(@1, $0, $2) }
| expr2 { $0 }
;
expr2 : boolor { $0 }
| boolor '->' expr { Fun(@1, $0, TCO($2)) }
;
boolor : boolor 'or' booland { Or(@1, $0, $2) }
| booland { $0 }
;
booland : booland 'and' bin { And(@1, $0, $2) }
| bin { $0 }
;
bind_expr : stmt expr_cont { In($0, $1) } ;
expr_cont : 'in' expr { $1 }
| bind_expr { $0 }
;
match_cases : separated_list(',', match_case) { $0 } ;
match_case : pat '=>' expr { (@1, $0, $2) } ;
bop : | '^' { $0 }
| '::' { $0 }
| <OP> { $0 }
| <SOP> { $0 }
| '==' { $0 }
| '`' <UPPER> '`' { $1 }
| '`' <LOWER> '`' { $1 }
;
btr : bop call_expr { (@0, *$0, $1) }
| bop bind_expr { (@0, *$0, $1) }
;
bin : call_expr { $0 }
| call_expr list(btr) { Bin($0, $1) }
;
pat : boolor { $0 } ;
call_expr : call_expr atomExpr { Call($0, $1) }
| atomExpr { $0 }
;
atomExpr :
| atomExpr '.' ID { Field(@1, $0, $2) }
| atomExpr '.' bop { Field(@1, $0, *$2) }
| atomExpr '.' '(' separated_list(',', expr) ')' { PyCall($0, $3) }
| atomExpr '.' '(' ')' { PyCall($0, []) }
| atom { $0 }
;
atom : '(' ')' { Tuple(@0, []) }
| '[' ']' { List(@0, []) }
| '[' separated_list(',', expr) ']' { List(@0, $1) }
| '(' separated_list(',', expr) ')' { Tuple(@0, $1) }
| '(' bop ')' { Var(@0, *$1) }
| '(' '!' ')' { Var(@0, *$1) }
| <UPPER> { Var(@0, *$0) }
| <LOWER> { Var(@0, *$0) }
| '_' { Var(@0, *$0) }
| <INT> { Lit(@0, int(*$0)) }
| <FLOAT> { Lit(@0, float(*$0)) }
| <STRING> { Lit(@0, DQString(*$0)) }
| 'True' { Lit(@0, True) }
| 'False' { Lit(@0, False) }
| 'extern' <STRING> { Extern(@0, DQString(*$1)) }
| '!' atom { Call(Var(@0, DEREF), $1) }
| '{' expr '}' { Fun(@0, Var(@0, WILDCARD), TCO($1)) }
;