Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Alternative Cross reference not working as expected
Alternative Cross reference not working as expected [message #1005386] Fri, 25 January 2013 03:20 Go to next message
Ian Warwick is currently offline Ian Warwick
Messages: 20
Registered: April 2012
Junior Member
Hi All,

I have a grammar that uses an alternative reference, I have pulled out the parts in question below full source here):

SingleSource:
	{SingleSourceTable} tableReference=TableReference ('as' name=ID)? |
	{SingleSourceSelectStatement} '(' selectStatement=SelectStatement ')' ('as' name=ID)? |
	{SingleSourceJoin} '(' joinSource=JoinSource ')'
;

TableOrSourceReference:
	TableReference | =>SingleSourceReference
;

TableReference:
	table=[CreateTableStatement|ID]
;

SingleSourceReference:
	source=[SingleSource|ID]
;


ResultColumn:
	{ResultColumnAll} (reference=TableOrSourceReference '.')? '*' |
	{ResultColumnExpression} expression=SqlExpression ('as' name=ID)?
;


The problem is when I use the grammar, it gives me proposals for both TableReference and SingleSourceReference for ResultColumn completion, but when I choose the path SingleSourceReference it gives me an error: Couldn't resolve reference to CreateTableStatement 'j':-

select j.* from table3 as j


But j should not be a CreateTableStatement reference, it should be a SingleSourceTable via the SingleSourceReference.

However its ok if I use the table reference:-

select table3.* from table3 as j


Not sure what I am doing wrong here, any advice would be greatly appreciated!
Re: Alternative Cross reference not working as expected [message #1005388 is a reply to message #1005386] Fri, 25 January 2013 03:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6205
Registered: July 2009
Senior Member
Hi have a look how Xtext builds qualified names (pressing crtl shift
f3 shows the contents of the index with their name)

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Alternative Cross reference not working as expected [message #1005389 is a reply to message #1005388] Fri, 25 January 2013 03:26 Go to previous messageGo to next message
Ian Warwick is currently offline Ian Warwick
Messages: 20
Registered: April 2012
Junior Member
Wow cheers Christian that is an awesome tip!
Re: Alternative Cross reference not working as expected [message #1005397 is a reply to message #1005386] Fri, 25 January 2013 03:56 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
HI,

>> TableOrSourceReference:
>> TableReference | =>SingleSourceReference

The parser willways parse this as SingleSourceReference (both are parsed
as ID thus the predicate always succeeds if the first path in the
alternative would succeed) since it does not know anything about cross
references. You'll have to rework your language in order to make a
proper decision.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 25.01.13 09:20, schrieb Ian Warwick:
> Hi All,
>
> I have a grammar that uses an alternative reference, I have pulled out
> the parts in question below
> https://github.com/robotoworks/mechanoid/blob/master/plugins/com.robotoworks.mechanoid.sqlite/src/com/robotoworks/mechanoid/sqlite/SqliteModel.xtext):
>
>
>
> SingleSource:
> {SingleSourceTable} tableReference=TableReference ('as' name=ID)? |
> {SingleSourceSelectStatement} '(' selectStatement=SelectStatement
> ')' ('as' name=ID)? |
> {SingleSourceJoin} '(' joinSource=JoinSource ')'
> ;
>
> TableOrSourceReference:
> TableReference | =>SingleSourceReference
> ;
>
> TableReference:
> table=[CreateTableStatement|ID]
> ;
>
> SingleSourceReference:
> source=[SingleSource|ID]
> ;
>
>
> ResultColumn:
> {ResultColumnAll} (reference=TableOrSourceReference '.')? '*' |
> {ResultColumnExpression} expression=SqlExpression ('as' name=ID)?
> ;
>
>
> The problem is when I use the grammar, it gives me proposals for both
> TableReference and SingleSourceReference for ResultColumn completion,
> but when I choose the path SingleSourceReference it gives me an error:
> Couldn't resolve reference to CreateTableStatement 'j':-
>
>
> select j.* from table3 as j
>
>
> But j should not be a CreateTableStatement reference, it should be a
> SingleSourceTable via the SingleSourceReference.
>
> However its ok if I use the table reference:-
>
>
> select table3.* from table3 as j
>
>
> Not sure what I am doing wrong here, any advice would be greatly
> appreciated!
Re: Alternative Cross reference not working as expected [message #1005400 is a reply to message #1005397] Fri, 25 January 2013 04:15 Go to previous message
Ian Warwick is currently offline Ian Warwick
Messages: 20
Registered: April 2012
Junior Member
Hi Sebastian,

Thanks for pointing that out, is there a standard (or known way) to deal with scenarios with aliases in the grammar such as the "as" clause in SQL?

I will try to rework my grammar I think the mistake I made was modelling it on the SQLite syntax diagrams, now I know the grammar I should probably try to take a fresh approach.


Previous Topic:Java.Lang.NullpointerException in UNIT TEST
Next Topic:Ecore -> Text inverse transformation
Goto Forum:
  


Current Time: Thu Aug 21 14:08:36 EDT 2014

Powered by FUDForum. Page generated in 0.03546 seconds