langium
langium copied to clipboard
Declared Types cannot include Keywords as Properties
Present in Langium version: 0.4.0
We can currently generate AST types via inference that include various Langium keywords as properties, like so:
A: interface=ID type=ID grammar=ID;
infers...
export interface A extends AstNode {
grammar: string
interface: string
type: string
}
However, if cannot do the same via declared types. The following is an example demonstrating how this fails, but also shows that Langium is highlighting the properties incorrectly as keywords.
Unless we intend to remove these properties from being used via inference, we should also support them in their declared forms.
To solve this:
- we should be able to declare the same properties via inference as we can explicitly
- we should have a test verifying this behavior
- if we choose to block certain keywords, we'll need extra tests guarding against those keywords (should we choose this route instead)
You can always escape keywords using the ^
token at the start of the ID. But anway, we should use the appropriate data type rule for the names of properties.
Yep, missed that the first time around with the ^
token, that does correct the issue above. Highlighting is still the same as before, but it generates ok 👍 . I think in this case, with just the highlighting thing, this can probably be closed as is. Maybe a separate issue to resolve the highlighting can be opened separately.
Lastly, @msujew could you elaborate on what you mean about using the appropriate data type rule for the names of properties in this context? Are you talking about #559 by chance?
@montymxb There's a special data type rule that can be used to work around the ^
token:
https://github.com/langium/langium/blob/207b6e59f063d04825ab77185cda1baa96b7ee25/packages/langium/src/grammar/langium-grammar.langium#L198-L199
Got it, makes more sense now how this can be rectified 👍
I have a probably similar problem: When creating the hello-world-language (langium 0.5.0) and changing the grammar from 'person' name=ID
to 'ID' name=ID
I get a problem:
Person:
'ID' name=ID;
with the model
ID Pierre
Hello Pierre!
--> Error "Expecting token of type 'EOF' but found ID
.hello-world(parsing-error)".
Renaming the rule ID
to Id
fixes the issue...
@goto40 This seems to be a less relevant issue. After a few tests, I find that this behavior occurs if a terminal rule uses a keyword (like 'ID' in this example) as its name. Also, this error does not occur at v0.5.0 (but occurs after that).
Fixed with #811.