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
50 lines (45 loc) · 2.02 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
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 ::= [a-zA-Z_.?-] ([a-zA-Z0-9_.?- ]* [a-zA-Z0-9_.?-])?;
builtin ::= [A-Z_.?-]+;
number ::= [0-9]+ ('.' [0-9]+)?;
member ::= __ '*'? '[' member-key ']' __ pattern NL;
member-key ::= number | (identifier '/')? keyword;
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 ']';