syn icon indicating copy to clipboard operation
syn copied to clipboard

Consider providing a `parse_file_with` function to support shebang-handling in preprocessors

Open dfoxfranke opened this issue 11 months ago • 0 comments

It would be useful to have a function available with a signature of

fn parse_file_with<T, F>(content: &str, parse: F) -> (Option<String>, Result<T>)
    where 
        T: Parse,
        F: FnOnce(&str) -> Result<T>;

I'm using syn to implement a preprocessor which outputs Rust code (and needs to do some things that are hard to do with proc macros), and want it to handle shebangs the same way that Rust does. Lacking a function like the one above, this requires me to make a wholesale copy of syn's private whitespace module and an almost-wholesale copy of parse_file. Having it available would let me avoid such code duplication.

dfoxfranke avatar Nov 12 '24 18:11 dfoxfranke