-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.ebnf
48 lines (44 loc) · 1.92 KB
/
grammar.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
body ::= (entry NL)* (entry)? EOF;
entry ::= comment
| section
| message
;
comment ::= '#' .*;
section ::= '[[' keyword ']]';
__ ::= [ \t]*;
NL ::= [\r\n]+;
identifier ::= [a-zA-Z_.?-] ([a-zA-Z0-9_.?-])*;
variable ::= '$' identifier;
keyword ::= [^=|#{}\[\]()]+;
builtin ::= [A-Z_.?-]+;
number ::= [0-9]+ ('.' [0-9]+)?;
member ::= '*'? '[' keyword ']' __ pattern NL;
member-list ::= NL member+;
message ::= identifier __ '=' __ (pattern | pattern member-list | member-list);
pattern ::= unquoted-pattern
| quoted-pattern
;
unquoted-pattern ::= (unquoted-text | placeable | block-text)+;
quoted-pattern ::= '"' (quoted-text | placeable)* '"';
unquoted-text ::= ([^{] | '\{')+;
quoted-text ::= ([^{"] | '\{' | '\"')+;
block-text ::= NL __ '|' unquoted-pattern;
placeable ::= '{' __ placeable-list __ '}';
placeable-list ::= placeable-expression (__ ',' __ placeable-list)?;
placeable-expression ::= expression
| select-expression
;
expression ::= quoted-pattern
| number
| identifier
| variable
| call-expression
| member-expression
;
select-expression ::= expression __ ' ->' __ member-list;
call-expression ::= builtin '(' __ arglist? __ ')';
arglist ::= argument (__ ',' __ arglist)?;
argument ::= expression
| keyword-argument;
keyword-argument ::= identifier __ '=' __ quoted-pattern;
member-expression ::= identifier '[' keyword ']';