0

I need to filter a 'reference number' of the form XX.XX, where X is any upper or lower-case letter or number (0-9). This is what I have came up with:

SCR_REF:
  'Scr_Ref' ':' value=PROFILE
;

terminal PROFILE :
   ((CHAR|INT)(CHAR|INT)'.'(CHAR|INT)(CHAR|INT))
;

terminal CHAR returns ecore::EString : ('a'..'z'|'A'..'Z');

But his doesn't work in the generated editor. The following test entry:

Scr_Ref: 11.22

throws an error saying:

"no viable alternative at character '.' "

What I'm I doing wrong?

A.R.
  • 1,888
  • 2
  • 14
  • 22

1 Answers1

3

I think your problem is that you are using default INT in here. Both 11 and 22 is an integer by themselves. You need digits in here not Integer. Down here I made an example for you.


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

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
import"http://www.eclipse.org/emf/2002/Ecore" as ecore 

Model:
    greetings+=Greeting*;

Greeting:
    'Hello' name=ID '!' "val=" val= PROFILE;
terminal PROFILE :
   ((CHAR|DIGIT)(CHAR|DIGIT)'.'(CHAR|DIGIT)(CHAR|DIGIT))
;
terminal DIGIT:
    ('0'..'9')
;
terminal CHAR returns ecore::EString : 
    ('a'..'z'|'A'..'Z')
;

Hope this helps.

Semih Korkmaz
  • 1,125
  • 13
  • 26