Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext how to write grammar for custom hash comment (Xtext how to write grammar for custom hash comment )
Xtext how to write grammar for custom hash comment [message #1734191] Mon, 06 June 2016 05:48 Go to next message
Radhakrishna Kasiraju is currently offline Radhakrishna KasirajuFriend
Messages: 3
Registered: June 2016
Junior Member
In my language '##' is concatenation operator and also have hash comment which should not preceded or followed by anything except spaces.

But when a hash comment starts with two hashes ## it is taking it as concatenation operator specified in

Concatenation returns Expression:
Primary ({Concatenation.left=current} '##' right=Primary)*
;
and throwing error not showing as comment.
I want something like this

##This is a comment

a = "String1" ## "String2" -------------> this should be concatenation

I have tried something like this :

Model: {Model} NL* statements+=Statement*;

Statement: (OpenAssignment|HASH_COMMENT) NL*;

OpenAssignment: 'math' exp+=Expression(','? exp+=Expression*);

Expression:
LogicalOr
;
LogicalOr returns Expression:
BitwiseOr ({LogicalOr.left=current} '||' right=BitwiseOr)*
;
BitwiseOr returns Expression:
LogicalAnd ({BitwiseOr.left=current} '|' right=LogicalAnd)*
;
LogicalAnd returns Expression:
BitwiseAnd ({LogicalAnd.left=current} '&&' right=BitwiseAnd)*
;
BitwiseAnd returns Expression:
Equivalency ({BitwiseAnd.left=current} '&' right=Equivalency)*
;
Equivalency returns Expression:
Relational ({Equivalency.left=current} ('=='|'!='|'=') right=Relational)*
;
Relational returns Expression:
PlusMinus ({Relational.left=current} ('>='|'<='|'>'|'<') right=PlusMinus)*
;
PlusMinus returns Expression:
DivMult ({PlusMinus.left=current} ('+'|'-') right=DivMult)*
;
DivMult returns Expression:
LogicalNot ({DivMult.left=current} ('/'|'*') right=LogicalNot)*
;
LogicalNot returns Expression:
OnesComplement ({LogicalNot.left=current} '!' right=OnesComplement)*
;
OnesComplement returns Expression:
Exponentiation ({OnesComplement.left=current} ('~') right=Exponentiation)*
;
Exponentiation returns Expression:
Concatenation ({Exponentialtion.left=current} '^' right=Concatenation)*
;
Concatenation returns Expression:
Primary ({Concatenation.left=current} CONCAT right=Primary)*
;
Primary returns Expression: {Expression}
jplId=ID | number=NUMBER | str=STRING
;


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 CONCAT : (('\\'('\r'? '\n')) | !('\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: Xtext how to write grammar for custom hash comment [message #1734245 is a reply to message #1734191] Mon, 06 June 2016 14:20 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13193
Registered: July 2009
Senior Member
Posting the same question for the 4th time wont get faster help.
please strip down your grammar to a MINIMAL reproducing example.

i already tried to answer this before
https://www.eclipse.org/forums/index.php?t=msg&th=1077324&goto=1731885&#msg_1731885


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext from ecore model error - couldn't resolve reference to EPackage
Next Topic:xtext terminal rule
Goto Forum:
  


Current Time: Sat Nov 16 22:25:09 GMT 2019

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

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

Back to the top