Skip to main content



      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 09:22 Go to next message
Eclipse UserFriend
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 09:51 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: xtext get parser rule name based on context [message #1742770 is a reply to message #1742768] Wed, 07 September 2016 09:56 Go to previous messageGo to next message
Eclipse UserFriend
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 10:06] by Moderator

Re: xtext get parser rule name based on context [message #1742775 is a reply to message #1742770] Wed, 07 September 2016 10:11 Go to previous messageGo to next message
Eclipse UserFriend
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 10:13 Go to previous messageGo to next message
Eclipse UserFriend
and what is the nodes grammar element?
Re: xtext get parser rule name based on context [message #1742777 is a reply to message #1742776] Wed, 07 September 2016 10:19 Go to previous messageGo to next message
Eclipse UserFriend
RuleCallImpl
Re: xtext get parser rule name based on context [message #1742779 is a reply to message #1742777] Wed, 07 September 2016 10:20 Go to previous messageGo to next message
Eclipse UserFriend
that should give you a rule
Re: xtext get parser rule name based on context [message #1742780 is a reply to message #1742779] Wed, 07 September 2016 10:26 Go to previous messageGo to next message
Eclipse UserFriend
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 10:35 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: xtext get parser rule name based on context [message #1742783 is a reply to message #1742782] Wed, 07 September 2016 10:47 Go to previous messageGo to next message
Eclipse UserFriend
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 10:59 Go to previous messageGo to next message
Eclipse UserFriend
how does the grammar situation look like you wish to detect?
Re: xtext get parser rule name based on context [message #1742789 is a reply to message #1742787] Wed, 07 September 2016 11:10 Go to previous messageGo to next message
Eclipse UserFriend
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 11:13 Go to previous messageGo to next message
Eclipse UserFriend
but how do the rules for that look like?
Re: xtext get parser rule name based on context [message #1742801 is a reply to message #1742790] Wed, 07 September 2016 12:54 Go to previous messageGo to next message
Eclipse UserFriend
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 12:58 Go to previous messageGo to next message
Eclipse UserFriend
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]

....
Re: xtext get parser rule name based on context [message #1742804 is a reply to message #1742802] Wed, 07 September 2016 13:09 Go to previous messageGo to next message
Eclipse UserFriend
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 13:14 Go to previous messageGo to next message
Eclipse UserFriend
why dont you then simply compare content.getReference() == MyDslPackage.Literals.OBJECT_A__X
Re: xtext get parser rule name based on context [message #1742872 is a reply to message #1742806] Thu, 08 September 2016 06:59 Go to previous message
Eclipse UserFriend
Yes. I will try.
Previous Topic:Grammar generation bug when adding cross-reference
Next Topic:Parser Rule Fragments
Goto Forum:
  


Current Time: Fri Jul 11 20:44:44 EDT 2025

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

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

Back to the top