dabeaz / sly

Sly Lex Yacc
Other
816 stars 107 forks source link

Parsing a string with escape characters #85

Open senyai opened 2 years ago

senyai commented 2 years ago

Hi!

I want to parse (lex) "He\"llo" "𝑤𝑜𝑟𝑙𝑑!" as two tokens He"llo and 𝑤𝑜𝑟𝑙𝑑!. I couldn't find anything that would work. I think #79 is a similar issue. r'"(?:\\.|[^"\\])*"' idea from so didn't work as expected as it merged two strings. @_(r'''("[^"\\]*(\\.[^"\\]*)*"|'[^'\\]*(\\.[^'\\]*)*')''') trick from medium.com didn't work. All sly json parsers out there use r"\".*?\"" which is wrong. Is it even possible?

senyai commented 2 years ago

Found it! r'"(\\.|[^\"])*"'. I think an example in the docs is needed.

alingse commented 2 years ago

Let me try try