Skip to content

Commit 89ffa5d

Browse files
qmxeddyb
authored andcommitted
change grammar to allow rules to start with |
1 parent 04b1fdd commit 89ffa5d

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ and allows values to be parenthesized Rust expressions:
2626
mod json_like {
2727
::gll_macros::proc_macro_parser! {
2828
Value =
29-
Null:"null" |
30-
False:"false" |
31-
True:"true" |
32-
Literal:LITERAL |
33-
Array:{ "[" elems:Value* % "," "]" } |
34-
Object:{ "{" fields:Field* % "," "}" } |
35-
InterpolateRust:{ "(" TOKEN_TREE+ ")" };
29+
| Null:"null"
30+
| False:"false"
31+
| True:"true"
32+
| Literal:LITERAL
33+
| Array:{ "[" elems:Value* % "," "]" }
34+
| Object:{ "{" fields:Field* % "," "}" }
35+
| InterpolateRust:{ "(" TOKEN_TREE+ ")" }
36+
;
3637
Field = name:IDENT ":" value:Value;
3738
}
3839
}

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn main() {
9696
// Main grammar.
9797
Grammar = { {Shebang?} {rules:{RuleDef*}} Whitespace };
9898
RuleDef = { {name:Ident} "=" {rule:Or} ";" };
99-
Or = {rules:{Concat+ % "|"}};
99+
Or = {{"|"?} {rules:{Concat+ % "|"}}};
100100
Concat = {rules:{Rule+}};
101101
Rule = { {{ {field:Ident} ":" }?} {rule:Primary} {{modifier:Modifier}?} };
102102
Primary =

macros/tests/json.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ extern crate quote;
55
mod json_like {
66
::gll_macros::proc_macro_parser! {
77
Value =
8-
Null:"null" |
9-
False:"false" |
10-
True:"true" |
11-
Literal:LITERAL |
12-
Array:{ "[" elems:Value* % "," "]" } |
13-
Object:{ "{" fields:Field* % "," "}" } |
14-
InterpolateRust:{ "(" TOKEN_TREE+ ")" };
8+
| Null:"null"
9+
| False:"false"
10+
| True:"true"
11+
| Literal:LITERAL
12+
| Array:{ "[" elems:Value* % "," "]" }
13+
| Object:{ "{" fields:Field* % "," "}" }
14+
| InterpolateRust:{ "(" TOKEN_TREE+ ")" }
15+
;
1516
Field = name:IDENT ":" value:Value;
1617
}
1718
}

0 commit comments

Comments
 (0)