Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to solve QualifiedName ambiguity
How to solve QualifiedName ambiguity [message #1151332] Wed, 23 October 2013 09:20 Go to next message
Filipp Andjelo is currently offline Filipp AndjeloFriend
Messages: 3
Registered: October 2013
Junior Member
Hi all,

I have following grammar (simplified):
Type: 
  name = ID
;

Member: 
  type = [Type | QualifiedName] name = ID
;

Reference:
    type = [Type | QualifiedName] '.' member = [Member | QualifiedName]
;


This grammar is ambigous, since Type and Member are both defined through QualifiedNames. I think, this example is comparable to Java static members access. The Types are nested in my DSL, so I could have references like this: com.example.A.B.c.d, where com.example is a namespace, A.B are nested Types and c.b are Members.

How can I solve this? Changing the language is not an option, because I'm writing editor/generator for existing one.


Re: How to solve QualifiedName ambiguity [message #1151717 is a reply to message #1151332] Wed, 23 October 2013 14:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

can you change the ast?

if so:

Reference:
member = [Member | QualifiedName]
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to solve QualifiedName ambiguity [message #1152799 is a reply to message #1151332] Thu, 24 October 2013 07:17 Go to previous messageGo to next message
Filipp Andjelo is currently offline Filipp AndjeloFriend
Messages: 3
Registered: October 2013
Junior Member
Hi,

I don't understand what you mean. I have reference paths, which contain Type and Member as its parts. The real grammar I have is following:

Reference:
   type = [Type | QualifiedName] tail = ReferenceTail
;

ReferenceTail:
    '.' member = [Member | ID] tail = ReferenceTail?
;


This way I can implement a IScopeProvider for available Members, since I have to detect a Type of one member to calculate scope for the next one. The problem here is, that I'm using QualifiedName for Type reference, that way ANTLR can't decide where the QualifiedName is finished and where my the ReferenceTail rule starts, since this one has the same signature as QualifiedName. If I use ID (instead of QualifiedName) for Type reference, I can't reference my Types by using namespaces.

I want two following examples working:

com.example.MyTypeA.memberA.memberB - This one needs QualifiedName for Type reference, but is ambigous grammar

MyTypeA.memberA.memberB
- Works fine with ID for Type reference, but ignores namespaces. What if I have MyTypeA in multiple namespaces and I want to mix them?

Re: How to solve QualifiedName ambiguity [message #1152806 is a reply to message #1152799] Thu, 24 October 2013 07:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi

the answer is not. the only thing you can do is to change the syntax or put the
members by name <typename>.<membername> into the scope


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to solve QualifiedName ambiguity [message #1152807 is a reply to message #1152806] Thu, 24 October 2013 07:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
=> you can not solve this
unless you have an an object foreacht part between 2 dots

.<part>.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to solve QualifiedName ambiguity [message #1152917 is a reply to message #1151332] Thu, 24 October 2013 08:54 Go to previous messageGo to next message
Filipp Andjelo is currently offline Filipp AndjeloFriend
Messages: 3
Registered: October 2013
Junior Member
You mean, this is not possible at all? How would I parse Java files then? For instance if I have a class like:

package com.example;
class Foo { public static final int BAR = 42; }


Somewhere else accessing com.example.Foo.BAR would be ok as well as Foo.BAR or even just BAR, if inside a Foo derivation.

Ok, another one in the same direction. I have Types and Members (global Members too) and I want reference them by name, doing following:

MyTypeA.memberA.memberB or just accessing global or local member directly by memberA.memberB, without the Type prefix. In my grammar I have to expect a Reference to a Type or Member. This would be also not possible, because of ambiguity. Consider:

Member: 'var' name = ID;
Type: name = ID '{' (members += Member ';')* '}'

Reference:
   ref = ([Member] | [Type])  // <-- Unfortunately this is not possible


My solution was to redefine this as:
Member: 'var' name = ItemName;
Type: name = ItemName '{' (members += Member ';')* '}';
ItemName: name = ID;

Reference:
   ref = [ItemName]  // <-- Now it's ok


Now I have to define my IQualifiedNameProvider to rebuild the Type and Member names again and use the Validator to check if an allowed reference was provided in context. Is this the right way?




Re: How to solve QualifiedName ambiguity [message #1152926 is a reply to message #1152917] Thu, 24 October 2013 08:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

the problem is: it is not trivial. you may have a look at Xbase or xtend Xtend
(XFeatureCall if i am right, but i fear they do what i told you first)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to solve QualifiedName ambiguity [message #1152945 is a reply to message #1152926] Thu, 24 October 2013 09:12 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
its actually XMemberFeatureCall

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Loading XtextResources correctly
Next Topic:Assignment rules and EOperations
Goto Forum:
  


Current Time: Thu Mar 28 11:33:31 GMT 2024

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

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

Back to the top