Closed kyle-sawatsky closed 2 years ago
Following up with a simpler test I did
statement: expression ;
expression: identifier OP_PLUS subIdentifier ;
subIdentifier: ID ;
OP_PLUS: '+' ;
DOLLAR: '$' ;
fragment ALPHA : [A-Za-z] ;
fragment DIGIT : [0-9] ;
ID: DOLLAR? '_'* ALPHA(ALPHA|DIGIT|'_')* ;
Preferred rules set to identifier
and subIdentifier
and I've got no rules showing up on input foo+
with the caret at the end.
I feel like I'm missing something critical on how this is supposed to work.
Apologies for the multiple posts. I've just read through the test cases for the simpleExpr grammar again and it appears that it doesn't suggest a rule until you actually start matching it, so it seems like I did have a slight misunderstanding. I thought I could get around this for something like a dot-accessor expression by providing a 'blank' rule that will always match, but that didn't seem to work either. I think I'm just really confused on how c3 decides when a rule is a candidate.
For a suggestion a walk is necessary from the beginning of the grammar to a specific point (usually the caret position). The engine cannot find any suggestion without finding a valid path up to the given position, in the grammar.
I've tried to cut down the grammar a bit for this but it's not particularly complex. So given the following grammar
Let's say I've got an example input like
foo.
and I'm setting mypreferredRules
withidentifier
andbinaryDotCompletion
. As I typefoo
I'm getting parse tree output like(statement (expression (term (identifier foo))) <EOF>)
and the collected rules containsidentifier
as I would expect. But as soon as I add the.
no rules are collected at all. The parse tree output becomes(statement (expression (expression (term (identifier foo))) . (binaryDotCompletion <missing ID>)) <EOF>)
so the parser seems to know what should come next.I verified that the token index being used for assessing
foo.
is1
As soon as I add another letter after the
.
the rules candidates hasbinaryDotCompletion
but not a single token candidate is collected anymore (I haven't set any to be ignored while debugging this so I end up getting a lot of operator tokens). The missing tokens isn't particularly important for my purposes but it seems weird.The concept here looks really similar to the example grammar in the README with
simpleExpression
etc. so I'm baffled as to the results I'm getting.