Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Grammar and Color high light of Nested Variable Names(Two type of variables, which we can use nested format )
Grammar and Color high light of Nested Variable Names [message #1798212] Wed, 14 November 2018 04:28 Go to next message
Eclipse UserFriend
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 #1798299 is a reply to message #1798212] Thu, 15 November 2018 01:05 Go to previous messageGo to next message
Eclipse UserFriend
are you sure path are terminals and not a datatype (parser rule) or a real parser rule something like:

Model:
	(paths +=Path ";")*;
	
Path:
	GlobalPath | LocalPath
;	

GlobalPath:
	"($" (PathSegment(">" PathSegment)*)? ")"
;

LocalPath:
	"(*" (PathSegment(">" PathSegment)*)? ")"	
;

PathSegment:
	ID | Path
;
Re: Grammar and Color high light of Nested Variable Names [message #1798364 is a reply to message #1798299] Fri, 16 November 2018 03:39 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Christian.

I chose as Terminal to make simple for the color high light.

if it is terminal rule, then I need to use semantic high light approach. In that I am not able to make the color coding.

The Local variable color is Blue and Global variable color is PINK.

then I need to show this like below

(* localpath1>localpath2>($ globalpath1>globalpath2)>localpath3)

In Semantic logic, I am able to get the rootNode and loop the each node, but I am not able find the algorithm to make the color with the help of acceptor.addPosition().

Could you please guide me how to use the addPosition() method to make color partially in the node.
Re: Grammar and Color high light of Nested Variable Names [message #1798365 is a reply to message #1798364] Fri, 16 November 2018 03:54 Go to previous messageGo to next message
Eclipse UserFriend
can you please share why you have tried so far?
Re: Grammar and Color high light of Nested Variable Names [message #1798366 is a reply to message #1798365] Fri, 16 November 2018 04:07 Go to previous message
Eclipse UserFriend
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

Previous Topic:modifications to imported models
Next Topic:[Formatter2] format action does nothing
Goto Forum:
  


Current Time: Sun Jun 15 04:26:56 EDT 2025

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

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

Back to the top