Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext get parser rule name based on context(xtext get parser rule name based on context)
xtext get parser rule name based on context [message #1742755] Wed, 07 September 2016 13:22 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

Can anyone tell me how to get the parser rule for the context below?
Here in the below I am getting linkText but I am not able to get parser rule name of that particular linkText.

class JPLHyperlinkHelper extends LinkingDiagnosticMessageProvider {
override DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
val EClass referenceType = context.getReference().getEReferenceType();
var String linkText = "";
try {
linkText = context.getLinkText();
} catch (IllegalNodeException e){
linkText = e.getNode().getText();
}
if(!linkText.startsWith("sm_") && !linkText.startsWith("dm_") && !linkText.startsWith("jm_")) {
val String msg = "Couldn't resolve reference to " + referenceType.getName() + " '" + linkText + "'.";
return new DiagnosticMessage(msg, Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC);
}
}
}
Re: xtext get parser rule name based on context [message #1742768 is a reply to message #1742755] Wed, 07 September 2016 13:51 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
simply ask the context for its object and the you nodemodelutil to access the node model and then ask the nodes for their grammar elements does not work?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742770 is a reply to message #1742768] Wed, 07 September 2016 13:56 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I tried but no luck. So which method should I use to get its object?

I used NodeModelUtil.getNode

val ICompositeNode node = NodeModelUtils.getNode(context.context);
println("Node :::::::::::::::: "+node.grammarElement)

[Updated on: Wed, 07 September 2016 14:06]

Report message to a moderator

Re: xtext get parser rule name based on context [message #1742775 is a reply to message #1742770] Wed, 07 September 2016 14:11 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Oh shoot.

val ICompositeNode node = NodeModelUtils.getNode(context.context);
println("Node :::::::::::::::: "+node.text)

is working
Re: xtext get parser rule name based on context [message #1742776 is a reply to message #1742775] Wed, 07 September 2016 14:13 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
and what is the nodes grammar element?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742777 is a reply to message #1742776] Wed, 07 September 2016 14:19 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
RuleCallImpl
Re: xtext get parser rule name based on context [message #1742779 is a reply to message #1742777] Wed, 07 September 2016 14:20 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
that should give you a rule

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742780 is a reply to message #1742779] Wed, 07 September 2016 14:26 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
No. I am just getting complete line text and checking whether it is preceding by any of the parser rules or not?
Re: xtext get parser rule name based on context [message #1742782 is a reply to message #1742780] Wed, 07 September 2016 14:35 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
i dont get that can you post the code you try to do and how the grammar place you are looking for differes from others?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742783 is a reply to message #1742782] Wed, 07 September 2016 14:47 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
To be frank. I don't know how to do this! I am trying all possiblities
Re: xtext get parser rule name based on context [message #1742787 is a reply to message #1742783] Wed, 07 September 2016 14:59 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
how does the grammar situation look like you wish to detect?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742789 is a reply to message #1742787] Wed, 07 September 2016 15:10 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Suppose I have code like

vars a=b

test = abc()

call abc()

proc abc()
{
}

Here I am getting each line which contains cross reference and if the line starts with call or simple expression I want to show warning else ignoring the warning.
Re: xtext get parser rule name based on context [message #1742790 is a reply to message #1742789] Wed, 07 September 2016 15:13 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
but how do the rules for that look like?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742801 is a reply to message #1742790] Wed, 07 September 2016 16:54 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
If I understand rule looks like;

org.eclipse.xtext.nodemodel.impl.CompositeNodeWithSemanticElement@1ae4e6e3

If not could you please tell me what should I send?

My code is:

class JPLHyperlinkHelper extends LinkingDiagnosticMessageProvider {
override DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
val EClass referenceType = context.getReference().getEReferenceType();
var String linkText = "";
try {
linkText = context.getLinkText();
} catch (IllegalNodeException e){
linkText = e.getNode().getText();
}
val ICompositeNode node = NodeModelUtils.getNode(context.context);
println("Node:::: "+node)
if(!linkText.startsWith("sm_") && !linkText.startsWith("dm_") && !linkText.startsWith("jm_") && node.text.trim.startsWith("call")) {
val String msg = "Couldn't resolve reference to " + referenceType.getName() + " '" + linkText + "'.";
return new DiagnosticMessage(msg, Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC);
}
}
}
Re: xtext get parser rule name based on context [message #1742802 is a reply to message #1742801] Wed, 07 September 2016 16:58 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
i am still dont understand what are the different situations you want to differentiate?


is is ObjectA: ref=[X] from ObjectB: ref=[Y]

or ObjectA: ref=[X] from ObjectB: ref=[X]

or ObjectA: ref=[X] ref2=[Y]

....


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742804 is a reply to message #1742802] Wed, 07 September 2016 17:09 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
ObjectA: ref=[X] from ObjectB: ref=[X]
and
ObjectA: ref=[X] ref2=[Y]
Re: xtext get parser rule name based on context [message #1742806 is a reply to message #1742804] Wed, 07 September 2016 17:14 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 11494
Registered: July 2009
Senior Member
why dont you then simply compare content.getReference() == MyDslPackage.Literals.OBJECT_A__X

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: xtext get parser rule name based on context [message #1742872 is a reply to message #1742806] Thu, 08 September 2016 10:59 Go to previous message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Yes. I will try.
Previous Topic:Grammar generation bug when adding cross-reference
Next Topic:Parser Rule Fragments
Goto Forum:
  


Current Time: Tue Dec 12 15:56:46 GMT 2017

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

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