Search code examples
eclipsegrammareclipse-emfxtexteclipse-emf-ecore

Is it possible to concatenate rules in Xtext?


I have a language with a set of keywords in the following form:

MyWord1
MyWord2
...
MyWord500

Like "MyWord", there are several other keywords with the same range of 500 allowable values. How could I create a grammar to parse this without making a rule with all 500 possible values piped one after the other? After reading the documentation, the closest I've come to a solution is the following:

MyWord:
    "MyWord"INT;

But Xtext puts a space between MyWord and the integer. Also, INT must be 2 digits for some reason, but I can define my own to get around that.


Solution

  • MyWord:
    "MyWord"INT;
    

    is a datatype rule. to your space problem: maybe you should use a terminal rule

    terminal MyWord :
    "MyWord" INT;