instaparse

ghaskins 2024-07-16T23:38:55.326219Z

I have a rule for parsing quoted strings that looks like this:

 ::= <"\"">
string  ::= quote #"[^\"]*" quote
but I have a use-case now where the strings can potentially be stringified json and thus contain escaped quotes that break the above rule, for example
"{\"k\": 1}"
I am trying to devise a new rule that handles this, but am struggling. I’ve looked at things like negative lookahead, as so
 ::= <#"(?
string  ::= quote (!quote)* quote

ghaskins 2024-07-16T23:39:57.569929Z

But this doesn’t seem to work and I’m not sure what else I could do. Any ideas?