dtolnay / dtolnay/syn

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

Open
#1,781 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
3.4k
Forks
374
Avg merge
1d 5h
Merged PRs (30d)
2

Description

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

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

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.