Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Same keysimbol causes ambiguity
Same keysimbol causes ambiguity [message #990045] Mon, 10 December 2012 16:20 Go to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

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:
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?
Re: Same keysimbol causes ambiguity [message #990051 is a reply to message #990045] Mon, 10 December 2012 16:30 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 112
Registered: July 2009
Senior Member
I wouldn't introduce any new terminals, but use data type TimeOfDay + validation instead.

Take a look of this blog for more details: http://zarnekow.blogspot.de/2012/11/xtext-corner-6-data-types-terminals-why.html
Re: Same keysimbol causes ambiguity [message #990057 is a reply to message #990045] Mon, 10 December 2012 16:45 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
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



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') |
> ('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:
>
> 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?
>
Re: Same keysimbol causes ambiguity [message #990167 is a reply to message #990057] Tue, 11 December 2012 09:00 Go to previous messageGo to next message
Tommaso De Sica is currently offline Tommaso De SicaFriend
Messages: 131
Registered: March 2012
Location: Italy
Senior Member

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.
Re: Same keysimbol causes ambiguity [message #990284 is a reply to message #990167] Tue, 11 December 2012 17:29 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
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
Previous Topic:LazyLinkingResource and EagerLinking
Next Topic:Data type characteristics
Goto Forum:
  


Current Time: Thu Apr 25 12:43:10 GMT 2024

Powered by FUDForum. Page generated in 0.03572 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top