Grammar and Color high light of Nested Variable Names [message #1798212] |
Wed, 14 November 2018 04:28  |
Eclipse User |
|
|
|
Hi All,
First of Thanks to read my queries and trying to help me.
I am trying to write the Grammar for the new requirement
I have two type of variables, local and global variable.
local variable syntax: (* path1>path2) or (# path1>path2>)
terminal LOCALVARIABLESTRING: '(*' -> ')' | '(#' -> ')'
Global variable syntax: ($ path1>path2)
terminal GLOBALVARIABLESTRING: '($' -> ')'
I am able to write the grammar for the above and working fine for the color high light also.
But now the new requirement is nested structure variables
(* localpath1>localpath2>($ globalpath1>globalpath2)>localpath3)
($ glopath1>glopath2>(* localpath1>localpath2)>globalpath3)
It is like a path to get the values, so local variable can contain global variable same like global contains local variables.
I am struck in nested structure grammar and syntax color high light.
|
|
|
|
|
|
Re: Grammar and Color high light of Nested Variable Names [message #1798366 is a reply to message #1798365] |
Fri, 16 November 2018 04:07  |
Eclipse User |
|
|
|
public class MyDslSemanticHighlightingCalculator extends DefaultSemanticHighlightingCalculator {
@Inject
private MyDslGrammarAccess ga;
@Inject
private OperationCanceledManager operationCanceledManager;
@Override
protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor,
CancelIndicator cancelIndicator) {
if (object instanceof Model) {
ICompositeNode node = NodeModelUtils.findActualNodeFor(object);
handlePathNode(node,acceptor,cancelIndicator);
}
return super.highlightElement(object, acceptor, cancelIndicator);
}
private void handlePathNode(INode n, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
acceptor.addPosition(n.getOffset(), n.getLength()-1, HighlightingStyles.STRING_ID);
BidiTreeIterable<INode> iterable = n.getAsTreeIterable();
for (INode nx : iterable) {
operationCanceledManager.checkCanceled(cancelIndicator);
EObject grammarElement = nx.getGrammarElement();
if (grammarElement instanceof RuleCall) {
if (ga.getGlobalPathRule() == ((RuleCall) grammarElement).getRule()) {
acceptor.addPosition(nx.getOffset(), nx.getLength(), HighlightingStyles.KEYWORD_ID);
}
}
}
}
}
[Updated on: Fri, 16 November 2018 04:09] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05313 seconds