Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtext] Can a keyword not be generated as a lexer rule ?
[Xtext] Can a keyword not be generated as a lexer rule ? [message #504786] Tue, 22 December 2009 16:31 Go to next message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
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 #504828 is a reply to message #504786] Tue, 22 December 2009 20:30 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Cédric Vidal schrieb:
> 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 #505002 is a reply to message #504828] Thu, 24 December 2009 10:07 Go to previous messageGo to next message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
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
Re: [Xtext] Can a keyword not be generated as a lexer rule ? [message #505006 is a reply to message #505002] Thu, 24 December 2009 10:28 Go to previous message
Cédric Vidal is currently offline Cédric VidalFriend
Messages: 101
Registered: July 2009
Senior Member
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
Previous Topic:[XPAND] [XTEND] hot to get the number of parameters for an operation
Next Topic:From generated output how to execute another work flow
Goto Forum:
  


Current Time: Thu Apr 25 09:17:57 GMT 2024

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

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

Back to the top