How can i read a multiline text in ANTLR untill a special symbol occurs. Like as in below text:-
@Description("
Hi There I am.
")
I need to read it as key -> @Description and value -> "Hi There I am".
I tried it with following grammar
KEY
: '@' [a-zA-Z] (~[(\r\n] | '\\)')*
;
VALUE
: '(' ~[\r\n]*
;
I tried many variations of VALUE grammar but no luck.
You're likely confused by the lexer/parser separation here. You did only provide a single example, but I can infer the following:
declarationis a parser rule. It consists of aKEY(@followed by letters), an opening parenthesis, aSTRING(any text between quotes), and a closing parenthesis.KEYandSTRINGare the lexer rules.Be aware that the
STRINGrule above won't let you escape characters. If you need to be able to escape a quote with a backslash (and also a backslash with a backslash), use the following rule instead: