I have the following grammar:
grammar bxk;
options
{
language=CSharp3;
}
// start rule
start
: com=comment root EOF
;
root
: ROOT_ID CT_ID END
;
comment returns [string comment]
: ((('/*' des=(~'*/')* '*/'))NEWLINE) {$comment=$des.text;}
;
CHAR : ('a'..'z'|'A'..'Z') ;
ROOT_ID : 'ROOT_'(CHAR | DIGIT | SPECIAL)+ ;
CT_ID : 'ct_'(CHAR | DIGIT | SPECIAL)+ ;
DIGIT : '0'..'9';
SPECIAL : '_' ;
END : ';';
ASSIGN : '=';
STRING : CHAR (CHAR | DIGIT | SPECIAL)*;
WS : (' '|'\t' | '\n' | '\r' | '\u000C')+ {Skip();} ;
Now I will get the comment betwenn the /* and */. That works fine. But the spaces were cleaned because the WS token with the Skip() call.
Can I have anything to skip the white spaces but within the comment structure I want to have the spaces.
I hope anyone have an solution?
Don’t make
commenta parser rule. Make it a lexer rule instead:In your parser rule(s), you can then do: