Just wanted to get a rough idea of how feasible something like antlr4-c3 would be for a SQL lezer grammar.
I.e rather than showing a list of all keywords during autocomplete, if a user types CREATE it would be great to only show the list of keywords which are valid immediately following CREATE, i.e. TEMPORARY | TABLE | DATABASE etc.
Since we are already specifying valid keyword combinations in the grammar, it would be great to take advantage of that, we effectively just need a way to get all possible future N + 1 branches after a parse, but I don’t think that’s possible at the moment.
A completion source could look before the cursor to see what keywords are there, and base its completions on that—what makes you say that that isn’t possible at the moment?
I’d like the source of truth for what completion items to show to effectively come from the grammar:
i.e. given this grammar:
OrReplace {
Or Replace
}
IfNotExists {
If Not Exists
}
CreateStmt {
Create OrReplace? (Table | Database | Schema) IfNotExists? Identifier
}
when parsing text that just contains CREATE I’d like to know what valid tokens could show up per the grammar definition, i.e. OrReplace | Table | Database | Schema, and parsing CREATE OR should just return REPLACE.
Currently parsing these example strings will return ErrorNodes, I’d like to see all possible branches that start after the cursor.
A completion source could look before the cursor to see what keywords are there, and base its completions on that—what makes you say that that isn’t possible at the moment?
Yes, we can do that but that means we basically have to maintain a bunch of logic alongside the grammar to walk the tree to produce said list of valid options. With a language like SQL this is non-trivial to say the least.