Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext hash comment problem(Xtext hash comment problem)
Xtext hash comment problem [message #1733726] Tue, 31 May 2016 09:01
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior 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')+;
Previous Topic:Xtext optional keyword grammar is not working
Next Topic:How to add files to the build?
Goto Forum:
  


Current Time: Fri Nov 15 23:48:12 GMT 2019

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

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

Back to the top