Terminal rule keywords highlighting [message #1733138] |
Tue, 24 May 2016 10:19  |
Eclipse User |
|
|
|
Hi,
Can we highlight selected keywords in terminal rule?
Terminal Notes: 'Start' -> NL+;
terminal NL : ('\r'? '\n')+;
If anything comes after can be any text. So if any keywords comes in the text I need to highlight them. Is it possible?
I can highlight every word in the rule but I don't want that.
|
|
|
|
|
Re: Terminal rule keywords highlighting [message #1733229 is a reply to message #1733222] |
Wed, 25 May 2016 14:55   |
Eclipse User |
|
|
|
Hi,
Why my custom terminal rule is not showing up as instanceof tTerminalRuleImpl?
I have written below code:
class JPLSemanticHighlightingCalculator implements ISemanticHighlightingCalculator {
override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor,CancelIndicator cancelIndicator) {
val ICompositeNode rootNode = resource.getParseResult().getRootNode();
val BidiTreeIterator<INode> it = rootNode.getAsTreeIterable().iterator();
while(it.hasNext){
val INode node = it.next();
if( node.getGrammarElement() instanceof TerminalRuleImpl)
{
val s = node.text
println("Node ######################### "+s)
acceptor.addPosition( node.getOffset(), node.getLength(), s );
}
}
}
}
and my terminal rules are:
terminal DBMS: 'DBMS' -> ('\n' | '\r')+;
terminal ID : ('a'..'z'|'A'..'Z'|'_'|'$'|'.'|'@')('a'..'z'|'A'..'Z'|'_'|'-'|'+'|'$'|'.'|'0'..'9'|'@')*;
terminal STRING :
'"' ( '\\'('"'|('\r'? '\n')) | !('\n'|'"') )* '"' |
"'" ( '\\'("'"|('\r'? '\n')) | !('\n'|"'") )* "'";
terminal SL_COMMENT: '//' !('\n' | '\r')*;
terminal HASH_COMMENT : ('#'('\r'? '\n')?) | ('#' !('#'|'\n'|'\r')+ ('\r'? '\n')?) | (('#''#''#') !('\n'|'\r')* ('\r'? '\n')?);
terminal WS : (' '|'\t'| ('\\'(' '* '\r'? '\n')))+;
terminal NL : ('\r'? '\n')+;
terminal NUMBER: (OCTAL|FLOAT|INT|BINARY|HEX);
terminal OCTAL returns ecore::EInt: ('0')('0'..'7')+;
terminal FLOAT returns ecore::EFloat: ('0'..'9' ('0'..'9')*) '.' ('0'..'9')*;
terminal INT returns ecore::EInt: '0'..'9' ('0'..'9')*;
terminal RANGE: '0'..'9' '..' ('0'..'9')*;
terminal BINARY returns ecore::EInt: ('0b'|'0B') ('0'|'1')+;
terminal HEX returns ecore::EInt:('0x'|'0X')('0'..'9'|'a'..'f'|'A'..'F')+;
|
|
|
Re: Terminal rule keywords highlighting [message #1733252 is a reply to message #1733229] |
Wed, 25 May 2016 17:32  |
Eclipse User |
|
|
|
Looks like you have 2 missunderstandings at one
- how the node model grammar elements look like
- how the api of the accept method looks like
class JPLSemanticHighlightingCalculator implements
ISemanticHighlightingCalculator {
override provideHighlightingFor(XtextResource resource,
IHighlightedPositionAcceptor acceptor,
CancelIndicator cancelIndicator) {
val ICompositeNode rootNode = resource.getParseResult().getRootNode();
val BidiTreeIterator<INode> it = rootNode.getAsTreeIterable().iterator();
while (it.hasNext) {
val INode node = it.next();
if (node.getGrammarElement() instanceof RuleCall) {
val rc = node.getGrammarElement() as RuleCall
val rule = rc.getRule()
if (rule instanceof TerminalRule) {
val s = node.text
println("Node ######################### " + s)
acceptor.addPosition(node.getOffset(), node.getLength(),
DefaultHighlightingConfiguration.KEYWORD_ID);
}
}
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03558 seconds