This repository has been archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
grammar.ebnf
54 lines (47 loc) · 2.03 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
49
50
51
52
53
54
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;
message ::= identifier __ '=' __ (value | trait-list);
value ::= pattern;
trait-list ::= NL (__ trait NL)+ __ trait?;
trait ::= member;
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-reference
| call-expression
| member-expression
;
select-expression ::= expression __ ' ->' __ NL variant+;
variant ::= member;
call-expression ::= builtin '(' __ arglist? __ ')';
arglist ::= argument (__ ',' __ arglist)?;
argument ::= expression
| keyword-argument;
keyword-argument ::= identifier __ '=' __ quoted-pattern;
member-expression ::= identifier '[' keyword ']';