syn
syn copied to clipboard
Parser for Rust source code
Pending acceptance of https://github.com/rust-lang/rfcs/pull/2582.
As part of the library from #607 -- users will want to generate code that calls visitor / folder methods on specific syntax tree node types. Something like: ```rust impl...
Visiting a particular syntax tree node with [`syn::visit`](https://docs.rs/syn/0.14/syn/visit/index.html), the number of calls to `visit_span` should be equal to the number of tokens when converted into TokenStream. This test would help...
This can result in quadratic behavior as each interpolated value is flattened to tokens before being parsed again. ```rust for ... { let x = parse_quote! { ... #x ......
I'm learning how to use `syn`, and after starting with some simple examples, I'm now running into issues that relate to blocks, specifically, how to: * store the `TokenStream` of...
This macro is commonly useful for building a syntax tree and should be featured more prominently. ```rust // Add a trait bound to every type parameter for param in &mut...
Many of our modules have pretty nasty conditional imports. https://github.com/dtolnay/syn/blob/6f03cfcdd9438fb50a7618882d8ec77f3f12cc2b/src/lit.rs#L9-L24 I believe Serde handles this better by having [one shared module](https://github.com/serde-rs/serde/blob/v1.0.27/serde/src/lib.rs#L130-L133) that contains all possible imports and is imported [all...
Add a test asserting that the upstream [`parse-fail`](https://github.com/rust-lang/rust/tree/master/src/test/parse-fail) test cases each fail to parse. Okay if we need to blacklist some of them to begin with.
`serde_json::Value` has an easy way to map an enum variant to an option, e.g. ```rust let val = Value::("abc") assert_eq!(val.as_str(), Some("abc")); assert_eq!(val.as_bool(), None); ``` I feel like this pattern would...
Rustc considers this code syntactically valid, it's only a later stage of compilation that reports an error. Syn does not currently permit these. ```rust #[cfg(any())] fn f(_: impl 'static, _:...