Search code examples
parsingenumsgrammarxtext

Xtext - enum literal overrides id


I have following excerpt of my grammar, where the rule Format seems to override the FieldColumnName rule.

Statement:
    'select * from' table=Table where=WhereClause;

WhereClause: 
    'where' symbol=FieldColumn op="=" right=STRING; 

FieldColumn:
    fieldName=FieldColumnName;

FieldColumnName hidden():
    ID ('.' ID)?;

enum Format:
    iso | de | en;

Developing an DSL-Script on following grammar I am getting an validation error in the editor, with following Statement:

select * from foo where foo.de = 'bar';

The error marks the de in foo.de and its message is:

mismatched input 'de' expecting RULE_ID

How can I use reserved words like the de in contexts where I do not expect that keyword?


Solution

  • You should be very careful with spaces in keywords. Please try to refactor your grammar, e.g. use 'select' '*' 'from' instead of 'select * from'. To fix your issue, you'll have to introduce a rule ValidID: ID | 'de' |'en' | 'iso'; and use ValidID instead of ID in FieldColumnName.