https://github.com/tamschi/salve
Greasy parsing extensions for `syn`, to calm down macro errors.
https://github.com/tamschi/salve
Last synced: 3 months ago
JSON representation
Greasy parsing extensions for `syn`, to calm down macro errors.
- Host: GitHub
- URL: https://github.com/tamschi/salve
- Owner: Tamschi
- License: other
- Created: 2022-06-30T18:26:49.000Z (almost 3 years ago)
- Default Branch: develop
- Last Pushed: 2023-11-13T21:56:45.000Z (over 1 year ago)
- Last Synced: 2025-01-28T05:23:41.284Z (5 months ago)
- Language: Rust
- Size: 49.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# salve
[](https://lib.rs/crates/salve)
[](https://crates.io/crates/salve)
[](https://docs.rs/salve)
[](https://github.com/Tamschi/salve/actions?query=workflow%3ACI+branch%3Adevelop)
[](https://github.com/Tamschi/salve)
[](https://github.com/Tamschi/salve/issues)
[](https://github.com/Tamschi/salve/pulls)
[](https://github.com/Tamschi/salve/contribute)[](https://web.crev.dev/rust-reviews/crate/salve/)
[](https://iteration-square.schichler.dev/#narrow/stream/project.2Fsalve)Greasy parsing extensions for [`syn`](https://lib.rs/crates/syn), to soften proc macro errors.
## Installation
Please use [cargo-edit](https://crates.io/crates/cargo-edit) to always add the latest version of this library:
```cmd
cargo add salve
```## Example
```rust
use catch::CatchExt;
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote_spanned;
use salve::ParseOrForgeExt;
use syn::{parse::ParseStream, Error, Token};pub fn parse_triple(input: ParseStream, errors: &mut Vec) -> (Ident, Token![,], Ident) {
(
// Parsing will continue here regardless of errors, yielding dummy values iff needed.
// Errors are collected for later use.
input.parse_or_forge().catch_item(errors),
input.parse_or_forge().catch_item(errors),
input.parse_or_forge().catch_item(errors),
)
}pub fn macro_transform(input: ParseStream) -> TokenStream {
let mut errors = vec![];
let (first, _, second) = parse_triple(input, &mut errors);
if !input.is_empty() {
// Added last, since this is often incidental.
errors.push(Error::new_spanned(
input.parse::().expect("infallible"),
"Unexpected tokens.",
))
}
let errors = errors.into_iter().map(Error::into_compile_error);
quote_spanned! {Span::mixed_site()=>
#(#errors)* // Emit parsing errors first, for better visibility.// Even if `second` is unavailable, `first` may be present, reducing errors elsewhere.
#[automatically_derived]
struct #first;// Even if `first` is unavailable, `second` may be present, reducing errors elsewhere.
#[automatically_derived]
struct #second;
}
}
```## License
Licensed under either of
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license
([LICENSE-MIT](LICENSE-MIT) or )at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.See [CONTRIBUTING](CONTRIBUTING.md) for more information.
## [Code of Conduct](CODE_OF_CONDUCT.md)
## [Changelog](CHANGELOG.md)
## Versioning
`salve` strictly follows [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html) with the following exceptions:
- The minor version will not reset to 0 on major version changes (except for v1).
Consider it the global feature level.
- The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
Consider it the global patch level.This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.Which versions are affected by features and patches can be determined from the respective headings in [CHANGELOG.md](CHANGELOG.md).
Note that dependencies of this crate may have a more lenient MSRV policy!
Please use `cargo +nightly update -Z minimal-versions` in your automation if you don't generate Cargo.lock manually (or as necessary) and require support for a compiler older than current stable.