This is an example grammar:
grammar org.xtext.example.mydsl.MyDsl with
org.eclipse.xtext.common.Terminalsgenerate myDsl “http://www.xtext.org/example/mydsl/MyDsl”
START: elem += DOG ;
DOG:
‘DOG’ INT ‘;’ ;terminal CAT : (‘A’..’Z’)(‘A’..’Z’)(‘A’..’Z’)’ ‘(‘0’..’9′)+;
When Xtext sees the line: DOG 1234, it can’t resolve and will give the error “mismatch input DOG 1234… expecting DOG” something like that. I thought that when Xtext encounters a keyword, it should have higher precedence than the terminal. But it seems like it’s confused. How can I fix this?
Note that DOG and CAT is used in different placed (i.e. the terminal CAT is used in other rule, but its definition conflicts with DOG rule)
In this situation, as you can see, error is not “Expection CAT_RULE ..”. So when you write DOG1234 as an element, Xtext is not parsing it as DOG and INT , instead it is getting ‘DOG1234’ as String, then looks for DOG rule and of course DOG rule only allows “DOG” keyword.
For example if you define DOG as another Terminal rule AFTER the CAT rule, also an element RAT ‘conflicting’ with CAT RULE and separate it’s INT value from keyword by using new line you will see all of them works.
And then usage of your new DSL example: