0
votes

I don't understand what is wrong with this grammar:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
    header=Header (elements+=Element)*;

Header:
 'Test:Revision' version=Decimal ';'
;

Decimal:
 INT'.'INT
;

Element:
 TableRow
;

TableRow:
 '__Row' name=ID '{'
   '__Alias' '=' Alias(','Alias)* ';'
 '}'
;

Alias:
 '0'|'1'|'H'|'L'
;

The following simple test statement fails with JUnit with the message "mismatched input '0' expecting RULE_INT on Header

Test:Revision2.0;

Everything works fine if I remove '0' from the Alias rule or I change the test statement to:

Test:Revision2.00;

Can you please tell me what is wrong with this grammar?

1

1 Answers

1
votes

With Alias you turn '0' into a keyword so it can never be matched by the INT terminal rule. The same would happen if you create a element with name 'L' or name 'H' you could introduce a datatype rule like

IntValue: INT | '0' | '1';

and use that one instead of INT inside Decimal