Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Semantic Highlighting Cross-References
Semantic Highlighting Cross-References [message #1767219] Mon, 03 July 2017 17:00 Go to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
I've managed to get a semantic highlighter working fine identifying parser rules using the RuleCall class when a rule is directly referred to.

However this doesn't seem to work when a reference is used in the grammer, as in [MyRule]. I can detect that the grammarElement is an instance of CrossReference, but then I can't see how to get from that CrossReference the name of the rule it is a cross reference to (ie, MyRule). According to the API it has only two members, type and terminal, and neither are really appropriate.

How can I get the name of the rule that a CrossReference is a reference to?
Re: Semantic Highlighting Cross-References [message #1767223 is a reply to message #1767219] Mon, 03 July 2017 17:22 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14083
Registered: July 2009
Senior Member
You can do something like

@Inject MyDslGrammarAccess ga

...

If (mygrammarelement == ga.getMyRuleAccess().getMyCrossRef()) ...


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Semantic Highlighting Cross-References [message #1767274 is a reply to message #1767223] Tue, 04 July 2017 12:08 Go to previous messageGo to next message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
Hi,

I'm not sure how to interpret that. I have injected the GrammarAccess but there is no getMyRuleAccess() method. There is myRuleAccess and myRuleRule, but that's all. myRuleAccess doesn't contain any "get" methods and I'm not sure what you would want me to put in place of "MyCrossRef" because the cross-reference doesn't have a separate name in the grammar, it's just "[MyRule]". MyRuleRule does have an eCrossReferences list inside it but it appears to be empty. It turns out that the cross reference is in the parent rule, not the cross-referenced one?
Re: Semantic Highlighting Cross-References [message #1767280 is a reply to message #1767274] Tue, 04 July 2017 12:32 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14083
Registered: July 2009
Senior Member
how does your grammar look like?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Semantic Highlighting Cross-References [message #1767350 is a reply to message #1767280] Tue, 04 July 2017 22:41 Go to previous message
Mark Green is currently offline Mark GreenFriend
Messages: 37
Registered: June 2017
Member
I think I figured it out, the trick is to get the cross reference type from the referring rule.
Previous Topic:Using linked .jar libraries in code generator
Next Topic:QualifiedNameProvider not working with custom Scopes
Goto Forum:
  


Current Time: Thu Oct 28 02:59:15 GMT 2021

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

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

Back to the top