Python LARK: terminal character inside text confusion

125 Views Asked by At

I'm trying to parse using Python Lark the output of a plan from a database. Here's my grammar:

start: op

op: command "(" op ")" "[" text "]"  
    | command "(" op ")" "[" text "]" WORD
    | command "(" op ")" "[" text "]" "," op 
    | command "(" op ")" "[" text "]" WORD "," op 
    | simple 

command: WORD | WORD WORD -> command

simple: /[A-Za-z"._]+/

text : /[A-Za-z0-9=.!%,\-" _:]+/ 

%import common.WORD
%import common.ESCAPED_STRING
%import common.WS
%ignore WS

Not the best grammar in the world, but it works for simple things. The problem is, sometimes there are parentheses and brackets INSIDE the text, that don't really matter. If I add them to the regex text rule, it messes up the op rule. Is there a simple way to fix this issue, or do I have to add complicated rules about the text?

0

There are 0 best solutions below