regex - Antlr4 how to avoid syntax errors with anything between quotes rule? -
i'm trying build own dsl in order create custom rules match given json object.
for purpose i've created far 2 kind of rules following grammar:
grammar rulegrammar;  def: 'def(' jsonrule ')'; jsonrule: regex|composite; regex: '"' code '"'; composite: '[' jsonrule ('&&'jsonrule)* ']'; code: any+;  any: ( '\\"' | .);  ws: [ \t\r\n]+ -> skip();   this grammar fails syntax error when "code" of regex contains characters '[' or ']', such as:
def("[a-za-z0-9]+") line 1:5 extraneous input '[' expecting   i see has definition of composite rule, has ']' in it.
is there way avoid syntax error without escaping brackets in code?
regex , code should lexer rules. besides, code greedy, it'll consume input.
write regex rule instead:
regex: '"' ('\\' ["\\] | ~["\\\r\n])* '"';   if want explanation error get, it's because [ character implicitly defined token, used in composite rule. doesn't recognized any because of lexer priority rules.
Comments
Post a Comment