Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-references with ambiguous use of period '.'
Cross-references with ambiguous use of period '.' [message #802796] Mon, 20 February 2012 13:05 Go to next message
John J. Camilleri is currently offline John J. CamilleriFriend
Messages: 33
Registered: November 2011
Location: Göteborg
Member
My DSL uses the period '.' in a somewhat ambiguous way, both for module qualification and for record projection, i.e.:
1. Common.makeNoun - a function in an external module
2. person.name - a record field

In the grammar, these are handled by the same rule as below. Trying to have different rules would just introduce ambiguity to the grammar and prevent it from compiling.
Exp : name=[Ident] '.' label=Ident

But this causes a problem for resolving cross-references; in the case of qualification I want to be able to resolve the label, but in the case of projection I don't want this to be a cross-reference.

To me, the best solution seems to be making all labels cross-refs as follows:
Exp : name=[Ident] '.' label=[Ident]

and then inside my ScopeProvider, performing some sort of check such that if it is a case of projection, then the scope is trivially resolved to itself. However this doesn't feel very elegant.

Any ideas of a better way of handling this?
Re: Cross-references with ambiguous use of period '.' [message #803370 is a reply to message #802796] Tue, 21 February 2012 08:56 Go to previous messageGo to next message
John J. Camilleri is currently offline John J. CamilleriFriend
Messages: 33
Registered: November 2011
Location: Göteborg
Member
After some thought, I see that the "solution" above suffers from the following problem: the qualified name would never actually treated as a single reference, but as two separate ones which isn't conceptually accurate.

Perhaps a better approach would be leave the grammar as it is, and then somewhere in the linking, after performing the appropriate check, alter the cross-reference to treat the entire parent Exp as the reference. Is this doable? Does it even make sense?

I would really appreciate any advice you could provide for handling this!
Re: Cross-references with ambiguous use of period '.' [message #803515 is a reply to message #803370] Tue, 21 February 2012 12:44 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
For the benefit of your DSL, I'm guessing everything should be a cross-reference (option 2). Otherwise, "name" in "person.name" (e.g.) would just be text and not checked against the actual features of "person".

I've written a couple of blogs on this pattern, which you might want to look into:
http://dslmeinte.wordpress.com/2011/11/23/path-expressions-in-entity-models-revisited/
http://dslmeinte.wordpress.com/2010/08/16/path-expressions-in-entity-models/

There's hardly ever any need to go messing with the linker. Instead, you should write a custom scope provider implementation for this aspect - as shown in the blogs.

I'm not entirely sure where your ambiguity should come from: the Exp rule alone is not sufficient unless Ident is a (datatype) rule which uses '.' as well. Posting your grammar (as complete as possible, anyway) would help.


Re: Cross-references with ambiguous use of period '.' [message #804176 is a reply to message #803515] Wed, 22 February 2012 09:37 Go to previous message
John J. Camilleri is currently offline John J. CamilleriFriend
Messages: 33
Registered: November 2011
Location: Göteborg
Member
Thanks for your reply Meinte!

The ambiguity is more of a semantic one than a grammatical one; if the name of Exp is found to be a valid module name then label should be a cross-reference to an identifier defined that module. But if name is a local variable then label should not be treated as a cross-reference at all. This may sound strange, but essentially it is because I am intentionally avoiding type-checking of local variables.

The solution I went for works this way:
1. Both segments of Exp are treated as cross-refs in the grammar, i.e.:
Exp : name=[Ident] '.' label=[Ident]

2. Overriding DefaultLinkingService#getLinkedObjects, I check whether the condition as described above is met.
3. If it is determined that label should not be a cross-reference, then I trivially satisfy it by creating a matching EObject in a dummy resource and linking it to that.
4. As described in this thread, I also override LazyLinker#beforeModelLinked and delete the dummy resource to clean these dummy EObjects.

So far this solution seems adequate, although I will post more updates here if any new issues or improvements arise.
Previous Topic:Referencing EClasses from my dsl
Next Topic:How to get position of parsed token in input grammar
Goto Forum:
  


Current Time: Mon Apr 06 19:23:52 GMT 2020

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

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

Back to the top