/
parser.rlmeta
51 lines (51 loc) · 2.23 KB
/
parser.rlmeta
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
Parser {
grammar =
| name:x space '{' rule*:ys space '}' -> ["Grammar" x ~ys]
rule =
| name:x space '=' choice:y -> ["Rule" x y]
choice =
| (space '|')?
sequence:x (space '|' sequence)*:xs -> ["Or" x ~xs]
sequence =
| expr:x expr*:xs -> ["Scope" ["And" x ~xs]]
expr =
| expr1:x space ':' name:y -> ["Bind" y x]
| expr1
expr1 =
| expr2:x space '*' -> ["Star" x]
| expr2:x space '?' -> ["Or" x ["And"]]
| space '!' expr2:x -> ["Not" x]
| space '%' -> ["MatchCallRule"]
| space '#' -> ["Label"]
| expr2
expr2 =
| space '->' hostExpr:x -> ["SemanticAction" x]
| name:x !(space '=') -> ["MatchRule" x]
| space char:x '-' char:y -> ["MatchRange" x y]
| space string:x -> ["MatchString" x]
| space charseq:x -> ["MatchCharseq" x]
| space '.' -> ["MatchAny"]
| space '(' choice:x space ')' -> x
| space '[' expr*:xs space ']' -> ["MatchList" ["And" ~xs]]
hostExpr =
| space string:x -> ["String" x]
| space '[' hostExprListItem*:xs space ']' -> ["List" ~xs]
| space '{' formatExpr*:xs space '}' -> ["Format" ~xs]
| name:x space '(' hostExpr*:ys space ')' -> ["FnCall" x ~ys]
| name:x -> ["VarLookup" x]
hostExprListItem =
| space '~'*:ys hostExpr:x -> ["ListItem" len(ys) x]
formatExpr =
| space '>' formatExpr*:xs space '<' -> ["Indent" ["Format" ~xs]]
| hostExpr
string = '"' (!'"' innerChar)*:xs '"' -> { xs }
charseq = '\'' (!'\'' innerChar)*:xs '\'' -> { xs }
char = '\'' !'\'' innerChar :x '\'' -> x
innerChar = '\\' escape | .
escape = '\\' -> "\\" | '\'' -> "'"
| '"' -> "\"" | 'n' -> "\n"
name = space nameStart:x nameChar*:xs -> { x xs }
nameStart = 'a'-'z' | 'A'-'Z'
nameChar = 'a'-'z' | 'A'-'Z' | '0'-'9'
space = (' ' | '\n')*
}