grammar gram;
program : st*;
st : sqlSt | commentSt;
sqlSt :
'<!--SQL' commentText '-->';
commentSt :
'<!--' commentText '-->';
var : '$' Identifier '$';
commentText
: var commentText | raw commentText;
raw : Raw+;
Identifier : [a-zA-Z]+[a-zA-Z0-9_-]*;
Raw : .+?;
Newline :('\r' '\n'? | '\n') -> skip;
<!--SQL SOME TEXT -->
<!-- $var123$ COMMENT!!!$var123$ -->
Console output:
line 1:8 extraneous input 'SOME' expecting {'$', Raw}line 1:13 extraneous input 'TEXT' expecting {'$', Raw}line 1:18 extraneous input '-->' expecting {'$', Raw}line 2:14 extraneous input 'COMMENT' expecting {'$', Raw}line 2:33 extraneous input '-->' expecting {'$', Raw}