[Xtext] Can a keyword not be generated as a lexer rule ? [message #504786] |
Tue, 22 December 2009 11:31  |
Eclipse User |
|
|
|
Hi guys,
Given the following grammar :
grammar org.xtext.example.NonKeywordChar with
org.eclipse.xtext.common.Terminals
generate nonKeywordChar "http://www.xtext.org/example/NonKeywordChar"
AB: name=ID '=' '[' a=INT 'x' b=INT ']';
The following file is correctly parsed :
a = [ 1 x 2 ]
The following is legal but doesn't parse:
x = [ 1 x 2 ]
The 'x' keyword appears in the AB parser rule, therefore 'x' is
generated as a lexer rule.
Therefore, in "x = [ 1 x 2 ]", 'x' is parsed as a token by the 'x'
keyword lexer rule and hence the RULE_ID doesn't match.
I'm aware that it's possible to escape IDs by prepending them with '^'
but the syntax I'm trying to parse is not mine and doesn't allow such
escaping.
Do you see any solution allowing this syntax ?
Regards,
Cédric
|
|
|
|
|
Re: [Xtext] Can a keyword not be generated as a lexer rule ? [message #505006 is a reply to message #505002] |
Thu, 24 December 2009 05:28  |
Eclipse User |
|
|
|
It worked ! Thanx.
Cédric Vidal a écrit :
> Thanx Sebastian !
>
> I'll try that.
>
> Kind regards,
>
> Cédric
>
> Sebastian Zarnekow a écrit :
>> Hi Cedric,
>>
>> I'm adding the tmf newsgroup to this reply.
>>
>> You could introduce a data type rule such as:
>>
>> MyID: ID | 'x';
>>
>> and use this one instead of the terminal rule ID. This should solve
>> your problem.
>>
>> Regards,
>> Sebastian
|
|
|
Powered by
FUDForum. Page generated in 0.05264 seconds