-
Notifications
You must be signed in to change notification settings - Fork 21
/
jssm-dot.peg
42 lines (31 loc) · 808 Bytes
/
jssm-dot.peg
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
/*
* Simple Arithmetics Grammar
* ==========================
*
* Accepts expressions like "2 * (3 + 4)" and computes their value.
*/
Expression
= Whitespace ExpList Whitespace
Integer "integer"
= [0-9]+ { return parseInt(text(), 10); }
ForwardArrow "forward arrow"
= "->"
TwoWayArrow "two way arrow"
= "<->"
Arrow
= ForwardArrow / TwoWayArrow
Label "label"
= [0-9a-zA-Z]+
Subexp
= Whitespace arrow:Arrow Whitespace label:Label Whitespace tail:Subexp* { return {kind: arrow, to: label, se:(tail === [])? undefined : tail}; }
Exp
= label:Label se:Subexp Whitespace ';' Whitespace {
const unroll = function(dive) { return true; }
return {from: label, se:(se === [])? undefined : se};
}
SubexpItem
= Subexp
ExpList
= exp:Exp*
Whitespace "whitespace"
= [ \t\n\r\v]*