Re: xtext problem for definition terminal string [message #669786] |
Wed, 11 May 2011 09:51  |
Eclipse User |
|
|
|
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 03:55  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05256 seconds