Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » narrow cross references
narrow cross references [message #963982] Tue, 30 October 2012 06:55 Go to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi All,

My grammar for DSL in xtext is like below:

Model: cs+=Company* employees+=Emp* block=Block
;
Block: emp1=company_crossRef
| emp_id=empId_crossRef
;

company_crossRef: empId1=[Company] ;
empId_crossRef: emp1=[Emp] ':' empId1=[empId];

Company: c='Company' name=ID;

Emp: r='Emp' name=ID '{' empIdName+= empId* '}'';' ;
empId: 'Employee_id' name=ID;

I have different companies, having different employees with different names and Ids. I need cross referencing for company names only or for employee with his Id. Both of these separately work for me, by providing dynamic scope in scope provider. and my scope provider looks like:

IScope scope_empId_crossRef_empId1( empId_crossRef emp, EReference ref) {
return Scopes.scopeFor(emp.getEmp1().getEmpIdName());
}

In the language, cross referencing for employee with his Id works, however cross referencing for company names is getting messed up with the cross referencing of employee and errors out. Do I need to write my scope provider in any different way for both of these cross references to work correct or is there any other class i need to change for this to work?

The current drop down in the language is like this:

Company amazon
Company sony

Emp amazon_emp1
{
Employee_id amazon_1
Employee_id amazon_2
};

sony :

with error on line sony :

Thanks,
Sri.
Re: narrow cross references [message #964236 is a reply to message #963982] Tue, 30 October 2012 11:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i do not get your problem im you write sony: you are parsing an empId_crossRef and not an company_crossRef


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #965294 is a reply to message #964236] Wed, 31 October 2012 05:49 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,
I want to make empId_crossRef and company_crossRef work under OR condition.

empId_crossRef should show something like
amazon_emp1 : amazon_1 (where amazon_emp1 is employee name and amazon_1 is employee Id)

company_crossRef should show company like
sony

The problem is when I select sony from drop down, it should match company_crossRef and finish the rule. But when Ctrl-Space is pressed ':' from empId_crossRef is down.

Block should parse any of the following:

amazon
amazon_emp1:amazon_1
sony
amazon_emp1:amazon_2
Re: narrow cross references [message #965443 is a reply to message #965294] Wed, 31 October 2012 08:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Still the question.
what is the actual problem you have?
that content assist proposes the : ?????


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #965515 is a reply to message #965443] Wed, 31 October 2012 09:45 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,

yes content assist proposes : is the problem and once i enter : as it proposes,i see an error in the language, It should not propose : for the rules i had written. Here it does not look like much of a problem, however i need to cross reference for OR of two level and another 3 level separated with separator like : so there the problems i face are still more messy.
Re: narrow cross references [message #965537 is a reply to message #965515] Wed, 31 October 2012 10:07 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Below is the grammar i am trying with for correct cross referencing:

Model: cs+=Company* employees+=Emp* block+=Block+
;
Block: emp1=company_crossRef
| emp_id=empId_crossRef
;

company_crossRef: comp1=[Company] ':' emp2=[Emp] ':' empId2=[empId] ;
empId_crossRef: emp1=[Emp] ':' empId1=[empId];

Company: c='Company' name=ID '{' emp+=Emp+ '}';

Emp: r='Emp' name=ID '{' empIdName+= empId* '}'';' ;
empId: 'Employee_id' name=ID;

and my scope providers are:

IScope scope_company_crossRef_emp2( company_crossRef comp, EReference ref) {
return Scopes.scopeFor(comp.getComp1() . getEmp());
}
IScope scope_company_crossRef_empId2( company_crossRef comp, EReference ref) {
return Scopes.scopeFor(comp.getEmp2().getEmpIdName());
}

IScope scope_empId_crossRef_empId1( empId_crossRef empId, EReference ref) {
return Scopes.scopeFor(empId.getEmp1().getEmpIdName());
}

In this case, content assistance for both company and empId do not work properly when they are ORed. Drop down shows mix of both of these and none works correct. Whereas company and empId cross references work fine separately. So, I have no clue about what extra i should do to make OR of these two to work correctly.

so for a language like:
Company sony {
Emp sony_emp1 {
Employee_id sony_1
Employee_id sony_2
};
}

Emp amazon_emp1 {
Employee_id amazon_1
Employee_id amazon_2
};

Block should show correct cross references like:
sony : sony_emp1 : sony_1
sony : sony_emp1 : sony_2
amazon_emp1 : amazon_1
amazon_emp1 : amazon_2
Re: narrow cross references [message #965569 is a reply to message #965537] Wed, 31 October 2012 10:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you grammar is highly amigous. thus in scoping the context object may not be a concrete instance company_crossRef but its parent.
i dont know a clean solution to this besides introducing different keywords
it may work if you change the grammar but i dont know


company_crossRef: comp1=[Company] ':' bla= empId_crossRef;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #965592 is a reply to message #965569] Wed, 31 October 2012 11:01 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
I tried company_crossRef: comp1=[Company] ':' bla= empId_crossRef; still cross-referencing is mixing both sony and amazon employees ie., company and employee cross references.

can you please let me know, which rules in my grammar appear ambiguous, so that i can try to improve them?
Re: narrow cross references [message #965606 is a reply to message #965592] Wed, 31 October 2012 11:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi

at the point you write x : y the parser does not know if it is a company_crossRef or a empId_crossRef
even worse: you allow multiple of these blocks with no separator.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #965617 is a reply to message #965606] Wed, 31 October 2012 11:28 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,
I do not need to allow multiple of these blocks.

If I write:
block = Block

Block should provide correct content assist for any one of the following:
sony : sony_emp1 : sony_2
amazon_emp1 : amazon_1

Is the above possible atleast?
Re: narrow cross references [message #965646 is a reply to message #965617] Wed, 31 October 2012 11:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no,

the problem still is: the parser knows where it is after the second ":"

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #965674 is a reply to message #965646] Wed, 31 October 2012 12:21 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,
after the first ":" itself, drop down shows incorrect employee cross reference. Neither of them are working correct together. By no, do you mean i can not do this at all?

Is the cross referencing making it ambiguous?
Re: narrow cross references [message #965688 is a reply to message #965674] Wed, 31 October 2012 12:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the problem is. xtext creates objects lazy. and your grammar leads that xtext cant decide what to do until you write the second :
if you stick on the syntax you have to trick.

so do you need this syntax or not?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #965704 is a reply to message #965688] Wed, 31 October 2012 12:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S: if you dont care about semantics and spaces around the : and this is your only cross ref

Model: cs+=Company* employees+=Emp* block+=Block
; 

Block:
	ref=[empId|QName]
;

QName : ID (":" ID)*;

Company: c='Company' name=ID '{' emp+=Emp+ '}';

Emp: r='Emp' name=ID '{' empIdName+= empId* '}'';' ; 
empId: 'Employee_id' name=ID;


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {

	public Class<? extends IQualifiedNameConverter> bindIQualifiedNameConverter() {
		return MyQNC.class;
	}
}



public class MyQNC extends IQualifiedNameConverter.DefaultImpl{
	
	@Override
	public String getDelimiter() {
		return ":";
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #968198 is a reply to message #965704] Fri, 02 November 2012 09:24 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,
The dropdown is successfully showing all fully qualified names:

sony:sony_emp:sony_1
amazon_emp1:amazon_1

In case of first example, can we have qualified name only upto: "sony:sony_emp" and then ctrl+space should show me : and then the list of corresponding employee Ids
Similarly, I should be able to get : and amazon_1 after amazon_emp1


[Updated on: Fri, 02 November 2012 09:51]

Report message to a moderator

Re: narrow cross references [message #968208 is a reply to message #968198] Fri, 02 November 2012 09:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

with the suff i posted it actuall works as expected ???????

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #968234 is a reply to message #968208] Fri, 02 November 2012 09:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
P.S: if this is about whitespace between the ids and the :

public class MyQNC extends IQualifiedNameConverter.DefaultImpl{
	
	@Override
	public String getDelimiter() {
		return ":";
	}
	
	@Override
	public QualifiedName toQualifiedName(String qualifiedNameAsString) {
		return super.toQualifiedName(qualifiedNameAsString.replaceAll(" ", ""));
	}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #968254 is a reply to message #968208] Fri, 02 November 2012 10:13 Go to previous messageGo to next message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi Christian,
all the fully qualified names are shown correctly. Is it possible to have qualified name only upto: "sony:sony_emp" and then ctrl+space should show me : and then the list of corresponding employee Ids (like sony_1). Similarly, after "amazon_emp1" ctrl+space should show : and then its ids like amazon_1.
Re: narrow cross references [message #968295 is a reply to message #968254] Fri, 02 November 2012 10:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
NO,

as i said "if you dont care"


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: narrow cross references [message #971915 is a reply to message #968295] Mon, 05 November 2012 08:01 Go to previous message
sri sri is currently offline sri sriFriend
Messages: 20
Registered: October 2012
Junior Member
Hi,
thank you for your replies.

Can I get cross referencing of both at a time with eager linking instead of xtext's lazy linking? I tried by mentioning eager linking in mwe2 file, however did not see any difference in the confusion of xtext after the first ":" .

Is customization of doGenerate method or ProposalProvider class related to the cross referencing problem i am trying to solve?

[Updated on: Wed, 07 November 2012 07:37]

Report message to a moderator

Previous Topic:Setting Developer Environment
Next Topic:Exclude files from indexing
Goto Forum:
  


Current Time: Wed Apr 24 18:28:57 GMT 2024

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

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

Back to the top