unquote
A reverse quote macro... that is: A macro to parse input from a ParseStream according to a given pattern.
Note: This library is a work in progress. While I don't expect large breaking changes to the syntax, there are missing features and error messages aren't always great yet.
This macro currently requires
synto be available in the current namespace with at least the"extra-traits"and"parsing"features enabled. This should get fixed with the next larger refactor.
Installation
Please use cargo-edit to always add the latest version of this library:
cargo add unquote
Example
use call2;
use quote;
use ;
use unquote;
Implementation Status
(roughly in order of priority)
| Tokens | |
|---|---|
| Punct | 🗸³ |
| Ident | |
| Literal | ✔ |
| Bindings | |
|---|---|
#binding |
✔ |
##-escapes |
| Groups | |
|---|---|
() |
|
{} |
|
[] |
| Variadics¹ | |
|---|---|
#(#binding)? |
|
#(#binding)* |
|
#(#binding),* |
|
#(#binding)+² |
|
#(#binding),+² |
| Bound Groups | |
|---|---|
#binding@() |
|
#binding@{} |
|
#binding@[] |
|
#@-escapes |
| Bound Compounds | |
|---|---|
#binding: Struct@() |
|
#binding: Struct@{} |
|
#binding: Struct@[] |
|
#:-escapes |
| Span Snapshots...? | |
|---|---|
#^span |
|
#$span |
?⁴ |
| Positional Bindings...?⁵ | |
|---|---|
#0 |
¹ Note that all variadics are eager beyond the first TokenTree and only do very shallow speculative parsing! In practice, this means that for example parsing ++ as #(+-)?++ will fail, as the first + "locks in" the optional phrase.
² Not specifically present in quote, but required variadics are great.
³ Currently without distinction regarding combinations like => vs. = > and such. This will change eventually, along with a breaking semver change.
⁴ I'm not yet sure how cleanly capturing spanning Spans would be, or how viable doing so is on stable.
⁵ This would come in handy when using the macro for example in if let conditions (since the positional bindings would be returned only by value in the macro expression's result), and wouldn't interfere with named bindings. It's definitely more of a bonus feature though, in case it can indeed be added cleanly.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.
Code of Conduct
Changelog
Versioning
unquote strictly follows Semantic Versioning 2.0.0 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.