Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.2] Using syntactic predicates within multi-cardinality constructs
[Xtext 2.2] Using syntactic predicates within multi-cardinality constructs [message #794737] Thu, 09 February 2012 16:45 Go to next message
Felix Feisst is currently offline Felix FeisstFriend
Messages: 20
Registered: February 2012
Location: Germany
Junior Member
Hello everybody,

what I was trying to do is writing a grammar that looks like this:

ManyIdsFollowedByOneId:
	manyIds=ManyIds id=ID
;

ManyIds:
	(ids+=ID)+
;


When I try to run the Xtext generator, I (correctly) get an error complaining about multiple alternatives.

I tried to solve the problem by introducing a syntactic predicate within ManyIds so that the ids only get consumed when there is at least one left:

ManyIdsFollowedByOneId:
	manyIds=ManyIds id=ID
;

ManyIds:
	((ID ID)=>(ids+=ID))+
;


Now the Xtext generator didn't put out an error message anymore. But the generated parser does not what i've intended to do. The generated parser code for ManyIds looks something like this (I've ommitted the generated actions):

ruleManyIds:
(ID ID) ((ID)=>(ids+=ID))+
;


Two ID's get consumed (without being added to ids though) and then it is checked for _one_ remaining ID in the generated predicate.

Is this kind of syntactic predicate not supported by Xtext, because ANTLR does support them. Or am I missing something?

Any ideas for an workaround without "inlining" ManyIds in the entry rule (I want to have seperate EMF Objects for those two guys) would be appreciated.

Felix
Re: [Xtext 2.2] Using syntactic predicates within multi-cardinality constructs [message #794797 is a reply to message #794737] Thu, 09 February 2012 18:01 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1770
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 02/09/2012 05:46 PM, Felix Atmanspacher wrote:
> Hello everybody,
>
> what I was trying to do is writing a grammar that looks like this:
>
>
> ManyIdsFollowedByOneId:
> manyIds=ManyIds id=ID
> ;
>
> ManyIds:
> (ids+=ID)+
> ;

Just a very quick answer, completely untested, but wouldn't this do what
you need?

ManyIdsFollowedByOneId:
(ids+=ID)+ id=ID
;


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: [Xtext 2.2] Using syntactic predicates within multi-cardinality constructs [message #794822 is a reply to message #794737] Thu, 09 February 2012 18:40 Go to previous message
Felix Feisst is currently offline Felix FeisstFriend
Messages: 20
Registered: February 2012
Location: Germany
Junior Member
Quote:

Just a very quick answer, completely untested, but wouldn't this do what
you need?

ManyIdsFollowedByOneId:
(ids+=ID)+ id=ID
;


Thanks but that's what I meant by "inlining" and yes, that would do the trick.
But the point is, I want the ManyIds (ids) to live in a seperate EObject in the resulting parser AST.
Previous Topic:get source position of tokens
Next Topic:Get token list for an EObject
Goto Forum:
  


Current Time: Sat Sep 19 10:24:44 GMT 2020

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

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

Back to the top