Move actiont checking from codegen to ast validation. - #659
Conversation
There was a problem hiding this comment.
There is a similar error here that should probably also be moved in this patch
There was a problem hiding this comment.
Ditto for this error.
| InvalidString, | ||
| NoStartRule, | ||
| UnknownSymbol, | ||
| UnrecognizedDollarVariable, |
There was a problem hiding this comment.
Would UnrecognizedActionVariable be better?
| ) -> Result<(), YaccGrammarError> { | ||
| let kind_requires_actiont = matches!( | ||
| yacc_kind, | ||
| Some(YaccKind::Original(YaccOriginalActionKind::UserAction)) | Some(YaccKind::Grmtools) |
There was a problem hiding this comment.
We could consider making this boolean check a method on YaccKind?
With a different name like YaccKind::requires_actions?
I think it might also simplify a similar check in CTParserBulder.
| )], | ||
| }); | ||
| } else { | ||
| last = last + off + "$$".len(); |
There was a problem hiding this comment.
This else is probably a bit wonky, but it doesn't seem totally wrong in that we know each match is going to be at least 2?
There is one corner case here though where we get a weird span.
If we slightly modify the test I added:
(Modified test)
r#"
%token a
%%
start -> () : "a" {$};
"#,
);
assert_eq!(
ast_validity.errors(),
vec![YaccGrammarError {
kind: YaccGrammarErrorKind::UnrecognisedActionVariable,
spans: vec![Span::new(33, 33)],
}]
);
We see that the cursor with the removed space before the $ points to a zero length span
beginning right after the $ at the very end of the action. I would probably expect a span of like (32, 33). Morning brain hasn't started working yet to figure out what's going on with this calculation.
let ast_validity = ASTWithValidityInfo::new(
YaccKind::Grmtools,
r#"
%token a
%%
start -> () : "a" { $foo; };
"#,
);
assert_eq!(
ast_validity.errors(),
vec![YaccGrammarError {
kind: YaccGrammarErrorKind::UnrecognisedActionVariable,
spans: vec![Span::new(33, 37)],
}]
);
Here is an attempt to validate actiont earlier,
adding it to
YaccGrammarError.I'm uncertain it's possible to trigger for
YaccKind::GrmtoolsI would imagine you'd get a syntax error before it couldcomplete_and_validate. So I checked that with a manually constructed AST.