Skip to content

Commit 8106286

Browse files
committed
Add explicit whitespace definitions. The grammar is now LL(1) with backtracking.
1 parent 27ad3cc commit 8106286

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

spec/message.ebnf

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
Message ::= Declaration* ( Pattern | Selector Variant+ )
1+
Message ::= (s? Declaration)* s? Body s?
22

3-
/* Preamble */
4-
Declaration ::= 'let' WhiteSpace Variable '=' '{' Expression '}'
5-
Selector ::= 'match' ( '{' Expression '}' )+
3+
Declaration ::= 'let' s Variable s? '=' s? '{' s? Expression s? '}'
4+
Body ::= Pattern | Selector (s? Variant)+
65

7-
/* Variants and Patterns */
8-
Variant ::= 'when' ( WhiteSpace VariantKey )+ Pattern
9-
VariantKey ::= Literal | Nmtoken | '*'
10-
Pattern ::= '{' (Text | Placeholder)* '}' /* ws: explicit */
6+
Pattern ::= '{' (Text | Placeholder)* '}'
7+
Selector ::= 'match' (s? '{' s? Expression s? '}')+
8+
Variant ::= 'when' (s Key)+ s? Pattern
9+
Key ::= Nmtoken | Literal | '*'
1110

12-
/* Placeholders */
13-
Placeholder ::= '{' (Expression | Markup | MarkupEnd)? '}'
11+
Placeholder ::= '{' s? (Expression | Markup | MarkupEnd)? s? '}'
1412

15-
/* Expressions */
16-
Expression ::= Operand Annotation? | Annotation
17-
Operand ::= Literal | Variable
18-
Annotation ::= Function Option*
19-
Option ::= Name '=' (Literal | Nmtoken | Variable)
13+
Expression ::= (Literal | Variable) (s Annotation)? | Annotation
14+
Annotation ::= Function (s Option)*
15+
Option ::= Name s? '=' s? (Literal | Nmtoken | Variable)
2016

21-
/* Markup Tags */
22-
Markup ::= MarkupStart Option*
17+
Markup ::= MarkupStart (s Option)*
2318

2419
<?TOKENS?>
2520

@@ -29,12 +24,12 @@ TextChar ::= AnyChar - ('{' | '}' | Esc)
2924
AnyChar ::= [#x0-#x10FFFF] - [#xD800-#xDFFF]
3025

3126
/* Names */
32-
Variable ::= '$' Name /* ws: explicit */
33-
Function ::= ':' Name /* ws: explicit */
34-
MarkupStart ::= '+' Name /* ws: explicit */
35-
MarkupEnd ::= '-' Name /* ws: explicit */
36-
Name ::= NameStart NameChar* /* ws: explicit */
37-
Nmtoken ::= NameChar+ /* ws: explicit */
27+
Variable ::= '$' Name
28+
Function ::= ':' Name
29+
MarkupStart ::= '+' Name
30+
MarkupEnd ::= '-' Name
31+
Name ::= NameStart NameChar*
32+
Nmtoken ::= NameChar+
3833
NameStart ::= [a-zA-Z] | "_"
3934
| [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF]
4035
| [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D]
@@ -44,13 +39,13 @@ NameChar ::= NameStart | [0-9] | "-" | "." | #xB7
4439
| [#x0300-#x036F] | [#x203F-#x2040]
4540

4641
/* Literals */
47-
Literal ::= '(' (LiteralChar | LiteralEscape)* ')' /* ws: explicit */
42+
Literal ::= '(' (LiteralChar | LiteralEscape)* ')'
4843
LiteralChar ::= AnyChar - ('(' | ')' | Esc)
4944

5045
/* Escape sequences */
5146
Esc ::= '\'
5247
TextEscape ::= Esc Esc | Esc '{' | Esc '}'
5348
LiteralEscape ::= Esc Esc | Esc '(' | Esc ')'
5449

55-
/* WhiteSpace */
56-
WhiteSpace ::= #x9 | #xD | #xA | #x20 /* ws: definition */
50+
/* White space */
51+
s ::= (#x9 | #xD | #xA | #x20)+

0 commit comments

Comments
 (0)