zesterer / chumsky

Write expressive, high-performance parsers with ease.
https://crates.io/crates/chumsky
MIT License
3.63k stars 155 forks source link

"escape" parser in json example seems to be wrong #647

Closed ShuiRuTian closed 4 months ago

ShuiRuTian commented 4 months ago

If I get it correctly, escape parser is using ignore this indicates that the result will be ,ah, ignored. And the string is using to_slice() which will just use the origin string rather than mapped value.

So, for string "\\r", it will still be "\\r", rather than "\r".

zesterer commented 4 months ago

Yes, the JSON parser in the example doesn't attempt to translate the string, only parse its structure: an attempt to translate the string would necessarily require character replacement and so on, which I consider to be beyond the scope of the example (and not necessarily useful for understanding how chumsky works).

ShuiRuTian commented 4 months ago

Does make sense, thanks for the answer!