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

String definition from Python 3 issue with parse string '\' #1336

Closed Fxztam closed 10 months ago

Fxztam commented 10 months ago

Hi,

I just encountered a problem with Lark's Python 3 string definition::

string : /([ubf]?r?|r[ubf])('(?!'').*?(?<!\\)(\\\\)*?')/i

-> the parse string '\' does not work:

lark.exceptions.UnexpectedCharacters: No terminal matches ''' in the current parser context, at line 9 col 25

            `   x := '\';`
                    ^
 Expected one of: 
    * /([ubf]?r?|r[ubf])('(?!'').*?(?<!\\)(\\\\)*?')/i
    * ...

I'm afraid I have an understanding problem with escaped strings.?

Here is an example

Thanks, Fried

MegaIng commented 10 months ago

Yes, '\' is not a valid string in python. This is the correct behavior.

Fxztam commented 10 months ago

It's nice to know. Maybe there's a suggestion for the solution when parsing a non-Python language here, please?

Fxztam commented 10 months ago

I tied with this

([ubf]?r?|r[ubf])('(?!'').*?(\\\\)*?'

and it seems that works.

Thanks, Fried