-
Notifications
You must be signed in to change notification settings - Fork 3
/
pegasus.grammar
27 lines (26 loc) · 1.15 KB
/
pegasus.grammar
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
token whitespace = /([ \t]|\r?\n)+/ [ skip ];
token identifier = /[a-zA-Z_\-]+/;
token keyword_token = /token/;
token keyword_rule = /rule/;
token equals_delimiter = /=/;
token semicolon_delimiter = /;/;
token or_delimiter = /\|/;
token regex = /\/([^\/]|\\.)*\//;
token open_square = /\[/;
token closed_square = /\]/;
token open_parenth = /\(/;
token closed_parenth = /\)/;
token comma = /,/;
token optional = /\?/;
rule S = token_list grammar_list | token_list | grammar_list;
rule token_list = token_def | token_def token_list;
rule token_def = keyword_token identifier equals_delimiter regex statement_end;
rule grammar_list = grammar_rule | grammar_rule grammar_list;
rule grammar_rule = keyword_rule identifier equals_delimiter grammar_bodies statement_end;
rule grammar_bodies = grammar_body | grammar_body or_delimiter grammar_bodies;
rule grammar_body = grammar_element | grammar_element grammar_body;
rule grammar_element = identifier | identifier optional;
rule statement_end = options semicolon_delimiter | semicolon_delimiter;
rule options = open_square options_list closed_square;
rule options_list = option | option comma options_list;
rule option = identifier;