Skip to content

Commit 10e6d74

Browse files
committed
Add a rust-like ":" between keys and values
1 parent 57b94aa commit 10e6d74

File tree

13 files changed

+50
-41
lines changed

13 files changed

+50
-41
lines changed

cfgrammar/src/lib/yacc/parser.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,14 @@ impl YaccParser {
455455
let (key_end_pos, key) = self.parse_name(i)?;
456456
i = self.parse_ws(key_end_pos, false)?;
457457
if key == "yacckind" {
458+
if let Some(j) = self.lookahead_is(":", i) {
459+
i = self.parse_ws(j, false)?;
460+
} else {
461+
return Err(YaccGrammarError {
462+
kind: YaccGrammarErrorKind::InvalidGrmtoolsHeaderKey,
463+
spans: vec![Span::new(i, i)]
464+
})
465+
}
458466
let val_end_pos = self.parse_yacckind(i, update_yacc_kind)?;
459467
if let Some(orig) = yacc_kind_key_span {
460468
let dupe = Span::new(key_start_pos, key_end_pos);
@@ -2838,20 +2846,20 @@ B";
28382846
#[test]
28392847
fn test_grmtools_section_yacckinds() {
28402848
let srcs = [
2841-
"%grmtools{yacckind Original(NoAction)}
2849+
"%grmtools{yacckind: Original(NoAction)}
28422850
%%
28432851
Start: ;",
2844-
"%grmtools{yacckind YaccKind::Original(GenericParseTree)}
2852+
"%grmtools{yacckind: YaccKind::Original(GenericParseTree)}
28452853
%%
28462854
Start: ;",
2847-
"%grmtools{yacckind YaccKind::Original(yaccoriginalactionkind::useraction)}
2855+
"%grmtools{yacckind: YaccKind::Original(yaccoriginalactionkind::useraction)}
28482856
%actiontype ()
28492857
%%
28502858
Start: ;",
2851-
"%grmtools{yacckind Original(YACCOriginalActionKind::NoAction)}
2859+
"%grmtools{yacckind: Original(YACCOriginalActionKind::NoAction)}
28522860
%%
28532861
Start: ;",
2854-
"%grmtools{yacckind YaccKind::Grmtools}
2862+
"%grmtools{yacckind: YaccKind::Grmtools}
28552863
%%
28562864
Start -> () : ;",
28572865
];
@@ -2871,7 +2879,7 @@ B";
28712879
// but that is part of `lrpar` which cfgrammar doesn't depend upon.
28722880
let src = r#"
28732881
%grmtools{
2874-
yacckind YaccKind::Grmtools,
2882+
yacckind: YaccKind::Grmtools,
28752883
}
28762884
%%
28772885
Start -> () : ;
@@ -2881,7 +2889,7 @@ B";
28812889
.unwrap();
28822890
let src = r#"
28832891
%grmtools{
2884-
yacckind YaccKind::Grmtools
2892+
yacckind: YaccKind::Grmtools
28852893
}
28862894
%%
28872895
Start -> () : ;

lrlex/examples/calc_manual_lex/src/calc.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools{yacckind Grmtools}
1+
%grmtools{yacckind: Grmtools}
22
%start Expr
33
%avoid_insert "INT"
44
%expect-unused Unmatched "UNMATCHED"

lrlex/src/lib/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ where
340340
let mut grmtools_section_span_map = HashMap::new();
341341
let mut grmtools_section_lex_flags = UNSPECIFIED_LEX_FLAGS;
342342
if let Some(j) = self.lookahead_is("%grmtools", i) {
343+
// lrlex currently doesn't have any `key: value' settings.
343344
i = self.parse_ws(j)?;
344345
if let Some(j) = self.lookahead_is("{", i) {
345346
i = self.parse_ws(j)?;

lrpar/cttests/src/calc_nodefault_yacckind.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test basic user actions using the calculator grammar
22
grammar: |
3-
%grmtools {yacckind Original(UserAction)}
3+
%grmtools {yacckind: Original(UserAction)}
44
%start Expr
55
%actiontype Result<u64, ()>
66
%avoid_insert 'INT'

lrpar/cttests/src/calc_wasm.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test running on wasm targets
22
grammar: |
3-
%grmtools {yacckind Grmtools}
3+
%grmtools {yacckind: Grmtools}
44
%start Expr
55
%avoid_insert "INT"
66
%expect-unused Unmatched "UNMATCHED"

lrpar/cttests/src/grmtools_section.test

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
grammar: |
2-
%grmtools{yacckind Grmtools}
2+
%grmtools{yacckind: Grmtools}
33
%token MAGIC IDENT NUM
44
%epp MAGIC "%grmtools"
55
%%
@@ -25,7 +25,7 @@ grammar: |
2525
path -> Path<'input>
2626
: IDENT {
2727
let ident = $lexer.span_str($1.as_ref().unwrap().span());
28-
Path::Ident(&ident)
28+
Path::Ident(&ident)
2929
}
3030
| IDENT '::' IDENT {
3131
let scope = $lexer.span_str($1.as_ref().unwrap().span());
@@ -34,29 +34,28 @@ grammar: |
3434
}
3535
;
3636

37-
valbind -> ValBind<'input>
38-
: IDENT val {
37+
valbind -> ValBind<'input>
38+
: IDENT ':' val {
3939
let key = $lexer.span_str($1.as_ref().unwrap().span());
40-
if let Some(val) = $2 {
41-
ValBind::Bind(key, val)
42-
} else {
43-
ValBind::TrueKey(key)
44-
}
40+
ValBind::Bind(key, $3)
41+
}
42+
| IDENT {
43+
let key = $lexer.span_str($1.as_ref().unwrap().span());
44+
ValBind::TrueKey(key)
4545
}
4646
| '!' IDENT {
47-
let s = $lexer.span_str($2.as_ref().unwrap().span());
48-
ValBind::FalseKey(s)
47+
let key = $lexer.span_str($2.as_ref().unwrap().span());
48+
ValBind::FalseKey(key)
4949
}
5050
;
5151

52-
val -> Option<Val<'input>>
53-
: %empty { None }
54-
| path { Some(Val::PathLike($1)) }
52+
val -> Val<'input>
53+
: path { Val::PathLike($1) }
5554
| NUM {
5655
let n = str::parse::<u64>($lexer.span_str($1.as_ref().unwrap().span()));
57-
Some(Val::Num(n.expect("convertible")))
56+
Val::Num(n.expect("convertible"))
5857
}
59-
| path '(' path ')' { Some(Val::ArgLike($1, $3)) }
58+
| path '(' path ')' { Val::ArgLike($1, $3) }
6059
;
6160

6261
comma_opt -> ()
@@ -100,4 +99,5 @@ lexer: |
10099
\( '('
101100
\) ')'
102101
:: '::'
102+
: ':'
103103
[\n\t\ ] ;

lrpar/cttests/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,18 +365,18 @@ fn test_grmtools_section() {
365365
"%grmtools{x,}",
366366
"%grmtools{!x}",
367367
"%grmtools{!x,}",
368-
"%grmtools{x y}",
369-
"%grmtools{x y,}",
368+
"%grmtools{x: y}",
369+
"%grmtools{x: y,}",
370370
"%grmtools{x, y}",
371371
"%grmtools{x, y,}",
372372
"%grmtools{x, !y}",
373373
"%grmtools{x, !y,}",
374-
"%grmtools{x y(z)}",
375-
"%grmtools{x y(z),}",
376-
"%grmtools{a, x y(z),}",
377-
"%grmtools{a, x y(z)}",
378-
"%grmtools{a, !b, x y(z), e f}",
379-
"%grmtools{a, !b, x y(z), e f,}",
374+
"%grmtools{x: y(z)}",
375+
"%grmtools{x: y(z),}",
376+
"%grmtools{a, x: y(z),}",
377+
"%grmtools{a, x: y(z)}",
378+
"%grmtools{a, !b, x: y(z), e: f}",
379+
"%grmtools{a, !b, x: y(z), e: f,}",
380380
];
381381

382382
let lexerdef = grmtools_section_l::lexerdef();

lrpar/cttests/src/storaget.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools{yacckind Grmtools}
1+
%grmtools{yacckind: Grmtools}
22
%%
33
word_seq -> Vec<String>
44
: "word" {vec![$lexer.span_str($1.as_ref().unwrap().span()).to_string()]
@@ -9,4 +9,4 @@ word_seq -> Vec<String>
99
$1
1010
}
1111
;
12-
%%
12+
%%

lrpar/examples/calc_actions/src/calc.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools {yacckind Grmtools}
1+
%grmtools {yacckind: Grmtools}
22
%start Expr
33
%avoid_insert "INT"
44
%%

lrpar/examples/calc_ast/src/calc.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools {yacckind Grmtools}
1+
%grmtools {yacckind: Grmtools}
22
%start Expr
33
%avoid_insert "INT"
44
%expect-unused Unmatched "UNMATCHED"

lrpar/examples/calc_parsetree/src/calc.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools{yacckind Original(GenericParseTree)}
1+
%grmtools{yacckind: Original(GenericParseTree)}
22
%start Expr
33
%avoid_insert "INT"
44
%%

lrpar/examples/clone_param/src/param.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools {yacckind Grmtools}
1+
%grmtools {yacckind: Grmtools}
22
%token Incr Decr
33
%parse-param val: Rc<RefCell<i64>>
44
%%

lrpar/examples/start_states/src/comment.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%grmtools{yacckind Original(GenericParseTree)}
1+
%grmtools{yacckind: Original(GenericParseTree)}
22
%start Expr
33
%%
44
Expr: Expr Text | ;

0 commit comments

Comments
 (0)