Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Re: xtext problem for definition terminal string
Re: xtext problem for definition terminal string [message #669786] Wed, 11 May 2011 13:51 Go to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
You're best to ask on the eclipse.modeling.tmf forum. I've added it to
the "to" list of the reply, so no need to repost.

tian1qi wrote:
> hi!
> I'm new in xtext,i have a big problem to define my grammar!
> :x
> in my grammar, i have the equation with the operator, and i
> define the operator as enum, like:
> enum Operateur_Relationnel returns Operateur_Relationnel:
> egal='=' |presque_egal='<>' |different='/='
> |inferieur='<';
>
> but in the grammar, i have also the chain with the type
> string which could take all caracters. i define the string
> like:
>
> terminal ID returns ecore::EString:
> '^'?('a'..'z'|'A'..'Z'|'_'|':'|'$'|'`'|'#'|'é'|'è'|'ç'|'


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: xtext problem for definition terminal string [message #669788 is a reply to message #669786] Wed, 11 May 2011 14:03 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Sorry, but I don't understand what your problem is.
Can you elaborate?
- henrik
On 5/11/11 3:51 PM, Ed Merks wrote:
> You're best to ask on the eclipse.modeling.tmf forum. I've added it to
> the "to" list of the reply, so no need to repost.
>
> tian1qi wrote:
>> hi!
>> I'm new in xtext,i have a big problem to define my grammar!
>> :x
>> in my grammar, i have the equation with the operator, and i
>> define the operator as enum, like:
>> enum Operateur_Relationnel returns Operateur_Relationnel:
>> egal='=' |presque_egal='<>' |different='/='
>> |inferieur='<';
>>
>> but in the grammar, i have also the chain with the type
>> string which could take all caracters. i define the string
>> like:
>>
>> terminal ID returns ecore::EString:
>> '^'?('a'..'z'|'A'..'Z'|'_'|':'|'$'|'`'|'#'|'é'|'è'|'ç'|'
Re: xtext problem for definition terminal string [message #669959 is a reply to message #669786] Thu, 12 May 2011 07:55 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

part of your terminal definition seems to be cut off. I assume the characters '>','<' appear there. If this is the case, the tokeniser will process "x<y" not as three tokens "x" "less than" "<" (which you semantically want and expect) but rather as one token "x<y" (as that is your ID definition).

The normal way out would be to exclude these characters from the terminal definition and have a datatype rule.

IdIncludingComparators hidden(): (ID|'<'|'>'|...)+;

You would use ID wherever the characters are not allowed in a name/value/whathever and use IdIncludingComparators if these characters are actually allowed.

Side note: messing with terminal definitions is always risky. Use datatype rules wherever possible.

E.g. you could also leave the ID definition untouched and introcude a datatype rule along the following lines (not really working, but should give you the idea)
MyId: (ID|'>'|listOfKeywordsFromTheGrammarAllowedInMyId|ANYOTHER)*;
Note that ANYOTHER is a terminal rule from the default Termianls-Grammar which picks up any characters not covered by other terminals, such as é and è etc.

Alex
Previous Topic:[XText] Problems getting grammar working
Next Topic:Node command
Goto Forum:
  


Current Time: Tue Apr 16 19:28:31 GMT 2024

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

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

Back to the top