rust-bakery / nom

Rust parser combinator framework
MIT License
9.21k stars 793 forks source link

make `escape_transform` return a parser outputing `Cow<str>` #1069

Open changhe3 opened 4 years ago

changhe3 commented 4 years ago

In many cases, the parsed text segment contains no escaped symbols, returning a reference would be sufficient. Current ExtendInto API also doesn't support custom implementations.

shepmaster commented 4 years ago

Is there any suggested path to adding this?

changhe3 commented 4 years ago

I think making nom::ExtendInto::Extender into a generic type parameter and implement ExtendInto<Cow<'_, str>> and ExtendInto<Cow<'_, [u8]>> for various types would be enough. This would be breaking change though. Maybe add another trait ExtendIntoV2 that does the same and add a escape_transform_v2 using the new trait.

changhe3 commented 4 years ago

I attempted but encountered some lifetime issues. I believe a complete redesign of ExtendInto may be warranted.