lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.64k stars 397 forks source link

multiline strings in python3 grammar #1373

Closed kediaharshit9 closed 3 months ago

kediaharshit9 commented 7 months ago

A common way to write strings in python is to put a backslash at the end and continue in the next line, this makes code more readable as well.

To Reproduce

x = "abc \
def"

This is valid python code, but lark parser fails with error

lark.exceptions.UnexpectedCharacters: No terminal matches '"' in the current parser context, at line ...
MegaIng commented 7 months ago

Use the STRING definition from this draft PR: https://github.com/lark-parser/lark/pull/1351/files#diff-0c6c68851bb98bda0665017b99a92f90d67ff56e55dca71a83ae390129a3a538