Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-references with alias
icon5.gif  Cross-references with alias [message #1723281] Sat, 13 February 2016 09:46 Go to next message
Johnny Bravo is currently offline Johnny BravoFriend
Messages: 5
Registered: January 2016
Junior Member
Hi,

I am implementing an SQL-like language with field names that may have an alias name. I want to reference the alias name, or if that not exists the field name, in the "where" part of the code.

So this should be valid:

select 
    field1 as alias1, 
    field2 
from table where 
    alias1=x and 
    field2=y


The language definition for a very simple case would look like this:

Query:
	'select' selection=Selection 'from table' where=Where
;

Selection:
	field+=Field (',' field+=Field)*
;

Field:
	name=ID ('as' alias=FieldAlias)?
;

FieldAlias:
	name=ID
;

Where:
	'where' name=[FieldAlias] '= condition'
;


Of course this does not work if the alias is not set. I also did not get it working properly with alternatives in the where part, if both field name and alias have the same terminal rule (ID).

My idea was to implicitly set alias=<Fieldname>, if it is not explicitly set. Is this possible, or is there a better way?

Many thanks!
Re: Cross-references with alias [message #1723282 is a reply to message #1723281] Sat, 13 February 2016 10:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The idea would be to reference to a field and adapt the scoping for the where reference by adapting the scopeprovider of your language

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-references with alias [message #1723432 is a reply to message #1723282] Mon, 15 February 2016 16:09 Go to previous messageGo to next message
Johnny Bravo is currently offline Johnny BravoFriend
Messages: 5
Registered: January 2016
Junior Member
Thanks Christian.
I tried a couple of implementations with using the ScopeProvider. It works just as expected for the content assist.

But then when I pick an alias in the "where", I get a validation error:

"Couldn't resolve reference to Field 'alias1'."

Can I make this work with the ScopeProvider only, or do I need to define a custom Validator?
Re: Cross-references with alias [message #1723433 is a reply to message #1723432] Mon, 15 February 2016 16:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you share your scope provider and grammar?

Depending on your grammar the context object may be a Where or a Query. so have have to handle that (EcoreUtil2.getContainerOfType might be helpful)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-references with alias [message #1723856 is a reply to message #1723433] Thu, 18 February 2016 13:55 Go to previous messageGo to next message
Johnny Bravo is currently offline Johnny BravoFriend
Messages: 5
Registered: January 2016
Junior Member
Thanks again, that pushed me in the right direction.

I have a context switch:
before "where" (content assist): context = Query
after "where" (validation): context = Where

So I had to catch both in my scope provider.
Re: Cross-references with alias [message #1723865 is a reply to message #1723856] Thu, 18 February 2016 14:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
alernatively to make at always a where

Where:
	{Where}'where' name=[FieldAlias] '= condition'
;



//{Type} is an unassigned action


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cross-references with alias [message #1723886 is a reply to message #1723865] Thu, 18 February 2016 17:48 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

Unrelated to your question, but since I see it in your grammar.
Don't put whitespace in keywords like this but rather make them two keywords, i.e. '=' 'condition'.
Previous Topic:How to reference available methods of a JvmTypeReference (Xbase)
Next Topic:Am I using a good approach for creating a documentation formatter
Goto Forum:
  


Current Time: Fri Apr 19 20:58:15 GMT 2024

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

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

Back to the top