-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrouwer.ebnf
261 lines (198 loc) · 5.83 KB
/
brouwer.ebnf
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
(*
integers as valid property accessors: item.0.display()
ranges: [1..10] is just {x | x >= 1 ^ x <= 10 ^ x `elem` Z}, sorted ascending
[10..1]
[10,7..1]
[1..] maybe? using generators?
initialization syntax for lists: [256; 8]
break, continue
ADTs
no inheritance, only traits
"generator" functions like js/python
? as syntax sugar for Maybe
go, join (?!)
*)
program =
[ module declaration ], { import }, { line } ;
module declaration =
"module", identifier, [ ( "exposing" | "hiding" ), identifier, { ",", identifier }, [ "," ] ], newline ;
import =
"import", identifier, [ "as", identifier | ( "exposing" | "hiding" ), identifier, { ",", identifier }, [ "," ] ], newline ;
line =
[ expression ], [ line comment ], line termination ;
line comment =
"--", [ print character - operator symbol, { print character } ] ;
expression =
subexpression, { subexpression } ;
subexpression =
var declaration
| assignment
| function declaration
| parened expression
| return statement
| case
| if else
| try catch
| while loop
| for loop
| anonymous function
| tuple literal
| list literal
| list comprehension
| dictionary literal
| dictionary comprehension
| set literal
| set comprehension
| qualified identifier
| operator
| infixed function
| numeric literal
| character literal
| string literal
;
var declaration =
"var", pattern, [ ":", type identifier ], "=", expression ;
assignment =
pattern, [ ":", type identifier ], "=", expression ;
function declaration =
"fn", identifier, parameter, { parameter }, [ "->", type identifier ], newline,
line block ;
parened expression =
"(", expression, ")" ;
return statement =
"return", expression ;
case =
"case", expression, newline,
INDENT, pattern, "=>", line,
{ INDENT, pattern, "=>", line } ;
if else =
"if", expression, newline,
line block,
[ "else", ( if else | newline,
line block ) ] ;
try catch =
"try", newline,
line block,
"catch", identifier, newline,
line block ;
while loop =
"while", expression, newline,
line block ;
for loop =
"for", pattern, "in", expression, newline,
line block ;
anonymous function =
"\\", parameter, { ",", parameter }, "->", expression ;
tuple literal =
"(", [ expression, ",", expression, { ",", expression }, [ "," ] ], ")" ;
list literal =
"[", [ expression, { ",", expression }, [ "," ] ], "]" ;
list comprehension =
"[", expression, "|", [ ( generator | expression ), { ",", ( generator | expression ) }, [ "," ] ], "]" ;
dictionary literal =
"{", "}"
| "{", expression, "=", expression, { ",", expression, "=", expression }, [ "," ], "}"
;
dictionary comprehension =
"{", expression, "=", expression, "|", [ ( generator | expression ), { ",", ( generator | expression ) }, [ "," ] ], "}" ;
set literal =
"{", "}"
| "{", expression, { ",", expression }, [ "," ], "}"
;
set comprehension =
"{", expression, "|", [ ( generator | expression ), { ",", ( generator | expression ) }, [ "," ] ], "}" ;
qualified identifier =
member identifier
| scoped identifier
| identifier
;
namespaced identifier =
scoped identifier
| identifier
;
identifier =
letter
| ( letter | "_" ), ( letter | digit | "_" ), { letter | digit | "_" }
;
member identifier =
identifier, ".", identifier ;
scoped identifier =
identifier, "::", identifier ;
type identifier =
namespaced identifier
| "(", [ type identifier, ",", type identifier, { ",", type identifier }, [ "," ] ], ")"
| "[", type identifier, "]"
| "{", type identifier, ",", type identifier "}"
| "{", type identifier, "}"
;
operator =
operator symbol, { operator symbol } ;
numeric literal =
real literal
| integer literal
;
character literal =
"'", ( print character - "'" - "\\" ), "'"
| "'\\", escape sequence, "'"
;
string literal =
'"', { string character }, '"' ;
infixed function =
"`", qualified identifier, "`" ;
pattern =
identifier
| character literal
| string literal
| numeric literal
| "_"
| "(", [ pattern, ",", pattern, { ",", pattern }, [ "," ] ], ")"
| "[", [ pattern, { ",", pattern }, [ "," ] ], "]"
| "{", [ pattern, "=", pattern, { ",", pattern, "=", pattern }, [ "," ] ], "}"
| "{", [ pattern, { ",", pattern }, [ "," ] ], "}"
;
string character =
( print character - '"' - "\\" )
| "\\", escape sequence
;
parameter =
pattern
| "(", pattern, ":", type identifier, ")"
;
generator =
pattern, "<-", expression ;
real literal =
[ "-" ], digit, { digit }, ".", digit, { digit }
| [ "-" ], "Infinity"
| "NaN"
;
integer literal =
[ "-" ], digit, { digit } ;
print character =
? any 7-bit ASCII print character ? ;
letter =
"A" | "B" | "C" | "D" | "E" | "F" | "G" | "H"
| "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P"
| "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X"
| "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f"
| "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v"
| "w" | "x" | "y" | "z" ;
digit =
"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7"
| "8" | "9" ;
escape sequence =
'"' | "'" | "t" | "v" | "n" | "r" | "b" | "0" ;
operator symbol =
"?" | "<" | ">" | "=" | "%" | "\\" | "~" | "!"
| "@" | "#" | "$" | "|" | "&" | "*" | "/" | "+"
| "^" | "-" | ":" | ";" ;
line block =
INDENT, line, { INDENT, line } ;
line termination =
newline | ? EOF ? ;
newline =
( "\n" | "\r" ), { "\n" | "\r" } ;
INDENT =
? one additional level of indentation ? ;
BLOCK COMMENT =
"{-", { print character | newline }, "-}" ;