user5981786
user5981786

Reputation:

Antlr grammar for a string inside a string

"Choose ""A"" for All Areas." is the string and my grammar rule for string is STRING : '\"' .* '\"' ; its not going in a way I thought and stopped till "choose " . what rule can I write to accept the above input.

Upvotes: 1

Views: 203

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170188

Something like this would do the trick:

STRING
 : '"' ( ~["] | '""' )* '"' 
 ;

Note that the rule above would also accept line breaks inside your string literal. If you don't want that, include \r\n in the negated set:

STRING
 : '"' ( ~["\r\n] | '""' )* '"' 
 ; 

Upvotes: 1

Related Questions