Same keysimbol causes ambiguity [message #990045] |
Mon, 10 December 2012 11:20  |
Eclipse User |
|
|
|
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') | ('2')('0'..'3'))(':')('0'..'5')('0'..'9')(':')('0'..'5')('0'..'9')('.')('0'..'9')('0'..'9');
[...]
CaseStatement:
{CaseStatement}
'CASE' caseValue=GenericExpression 'OF'
listOfCases+=Case*
'END_CASE'';'
;
Case:
{Case}
value=INT '..'finalValue=INT ':'
instructionCase+=Instruction*
;
As you can see, TIME_OF_DAY constants are composed with this pattern:
number:number:number.number
A 'case' is like this:
CASE number..number:
The problem is located on ':' keysimbol: if I write, in my dsl, this:
I'll receive an error becuse it interprets "10:" as a (not complete) part of TIME_OF_DAY constant.
Any suggests for these situations?
|
|
|
|
|
|
Re: Same keysimbol causes ambiguity [message #990284 is a reply to message #990167] |
Tue, 11 December 2012 12:29  |
Eclipse User |
|
|
|
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
>> to:
>>
>> 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
here.
Alternatively, just add a validation method and validate the model.
Regards
- henrik
|
|
|
Powered by
FUDForum. Page generated in 1.04377 seconds