-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsassy_messages_peg.js
60 lines (42 loc) · 1019 Bytes
/
sassy_messages_peg.js
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
start
= decl
// disallowing vars, handled.
// uninitialized vals, handled
decl = vt:vartype id typedef? a:assign?
{
if (vt === "var")
error("what part of IMMUTABLE do you not understand?")
else if (!a)
error("You should probably assign something now...you can't change it later!");
}
vartype = val/var
// Missing equals sign...handled.
// Missing rvalue: also handled.
assign =
e:eq? n:num?
{
if (e && !n)
error(". . . it equals what?");
else if (n && !e)
error("it does WHAT to " + n + "?");
return parseInt(n);
}
// use of reserved tokens--BOOM! handled!
id = &(p:reserved) {error("You can't call it that!");}
/ [A-Za-z_][A-Za-z_0-9]* sp
typedef
= COLON typename
eq = '=' sp
val = 'val' sp {return text().trim();}
var = 'var' sp {return text().trim();}
num = [0-9]+ sp {return parseInt(text());}
COLON = ':' sp
reserved
= typename / vartype
typename
= int/float/string/unit
int = 'Int' sp
float = 'Float' sp
string = 'String' sp
unit = 'Unit' sp
sp = [ \t]*