You need to use a Data rule instead of a terminal, anything that
requires context to parse can not be a terminal. Change your TIME_OF_DAY
time_of_day : INT ':' INT '.' INT
Add a converter for that rule that checks the formatting
(You may want a custom datatype as well - here it is just a string).
Hope that helps.
On 2012-10-12 17:20, Tommaso De Sica wrote:
> Good week everyone.
> This is an extract from my grammar:
> terminal INT returns ecore::EInt : ('0'..'9')+;
> terminal TIME_OF_DAY returns ecore::EString: (('0' | '1')('0'..'9') |
> 'CASE' caseValue=GenericExpression 'OF'
> value=INT '..'finalValue=INT ':'
> As you can see, TIME_OF_DAY constants are composed with this pattern:
> A 'case' is like this:
> CASE number..number:
> The problem is located on ':' keysimbol: if I write, in my dsl, this:
> CASE 1..10:
> I'll receive an error becuse it interprets "10:" as a (not complete)
> part of TIME_OF_DAY constant.
> Any suggests for these situations?
On 2012-11-12 10:00, Tommaso De Sica wrote:
> Henrik Lindberg wrote on Mon, 10 December 2012 17:45
>> You need to use a Data rule instead of a terminal, anything that
>> requires context to parse can not be a terminal. Change your TIME_OF_DAY
>> time_of_day : INT ':' INT '.' INT
>> Add a converter for that rule that checks the formatting
>> (You may want a custom datatype as well - here it is just a string).
>> Hope that helps.
>> - henrik
> Thanks for help, I think this is the better solution for my case but I
> can't understand how force INT to my value ranges.
Do you mean how to validate/convert the string passed to the terminal
converter for time_of_day ?
Well - look at the generated MyDSLTerminalConverters class (MyDSL is the
name of your language). There you should write a converter associated
with your "time_of_day" rule, and perform bidirectional conversion -
from string form to internal representation, and vice versa. If you do
not use a datatype other that String, you can simply just do validation
Alternatively, just add a validation method and validate the model.