diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 947935b..3387b52 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -27,7 +27,7 @@ If applicable, add screenshots to help explain your problem. **please complete the following information:** - `rustc --version`: [e.g. 1.45.0] -- Crate version (if applicable): [e.g. 0.0.6] +- Crate version (if applicable): [e.g. 0.0.7] **Additional context** Add any other context about the problem here. diff --git a/.github/workflows/audit_at_midnight.yml b/.github/workflows/audit_at_midnight.yml index ec830df..3098d5d 100644 --- a/.github/workflows/audit_at_midnight.yml +++ b/.github/workflows/audit_at_midnight.yml @@ -7,6 +7,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.3.4 - - uses: actions-rs/audit-check@v1 + - uses: actions-rs/audit-check@v1.2.0 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/audit_on_push.yml b/.github/workflows/audit_on_push.yml index 8f3802e..1b92e9d 100644 --- a/.github/workflows/audit_on_push.yml +++ b/.github/workflows/audit_on_push.yml @@ -9,6 +9,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.3.4 - - uses: actions-rs/audit-check@v1 + - uses: actions-rs/audit-check@v1.2.0 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b5d7b6e..d742f0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 - run: cat CI.toml >> Cargo.toml - run: cargo test --workspace --all-features @@ -31,7 +31,7 @@ jobs: workspace: ${{matrix.no-workspace || '--workspace'}} steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 with: toolchain: ${{matrix.rust}} profile: minimal @@ -46,7 +46,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 with: toolchain: nightly - run: cat CI.toml >> Cargo.toml @@ -58,7 +58,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 with: toolchain: nightly profile: minimal @@ -71,7 +71,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 with: toolchain: nightly profile: minimal diff --git a/.github/workflows/deny_warnings.yml b/.github/workflows/deny_warnings.yml index 30c049f..09f6053 100644 --- a/.github/workflows/deny_warnings.yml +++ b/.github/workflows/deny_warnings.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 with: toolchain: nightly profile: minimal diff --git a/.github/workflows/rust_auto_format.yml b/.github/workflows/rust_auto_format.yml index 7758429..c937c42 100644 --- a/.github/workflows/rust_auto_format.yml +++ b/.github/workflows/rust_auto_format.yml @@ -20,7 +20,7 @@ jobs: # github.head_ref only exists on pull requests. ref: ${{ github.head_ref || github.ref }} - - uses: actions-rs/toolchain@v1 + - uses: actions-rs/toolchain@v1.0.7 with: toolchain: nightly profile: minimal @@ -28,7 +28,7 @@ jobs: - run: cat CI.toml >> Cargo.toml - run: cargo +nightly fmt --all - - uses: Tamschi/git-auto-commit-action@v4.7.2 + - uses: Tamschi/git-auto-commit-action@v4.8.0 with: commit_message: Automatic formatting commit (cargo +nightly fmt) file_pattern: '**/*.rs' diff --git a/.vscode/extensions.json b/.vscode/extensions.json index dec8c3c..e05328f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,6 @@ { "recommendations": [ - "bungcip.better-toml", + "tamasfe.even-better-toml", "serayuzgur.crates", "editorconfig.editorconfig", "matklad.rust-analyzer", diff --git a/CHANGELOG.md b/CHANGELOG.md index 819bebc..8253fef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ +## 0.0.7 + +2023-08-26 + +* **Breaking changes** + * Removed [`Span`] for the time being. + > The previous implementation caused more issues than it solved, since it retrieved [`Span`]s of previously parsed tokens. +* Features + * [`quote`] now doesn't have to be in scope to unquote literal identifiers. +* Fixed + * Missing `syn/printing` dependency feature. +* Revisions + * Updated Syn dependency to version `2.0.29`. + * Fixed a few warnings. + +[`Span`]: https://docs.rs/proc-macro2/1/proc_macro2/struct.Span.html +[`quote`]: https://docs.rs/quote/1.0.9/quote/macro.quote.html + ## 0.0.6 2020-12-05 diff --git a/Cargo.toml b/Cargo.toml index a8eabf0..37d96c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "unquote" -version = "0.0.6" +version = "0.0.7" authors = ["Tamme Schichler "] edition = "2018" description = "A reverse quote macro... that is: A macro to parse input from a ParseStream according to a given pattern." license = "MIT OR Apache-2.0" repository = "https://github.com/Tamschi/unquote" -homepage = "https://github.com/Tamschi/unquote/tree/v0.0.6" -documentation = "https://docs.rs/unquote/0.0.6" +homepage = "https://github.com/Tamschi/unquote/tree/v0.0.7" +documentation = "https://docs.rs/unquote/0.0.7" keywords = ["syn"] categories = ["development-tools::procedural-macro-helpers"] readme = "README.md" @@ -31,10 +31,10 @@ proc-macro = true # TODO: Re-export libraries! [dependencies] -call2-for-syn = "2.0.3" +call2-for-syn = "3.0.4" proc-macro2 = "1.0.24" quote = "1.0.7" -syn = { version = "1.0.48", features = ["extra-traits", "parsing"], default-features = false } +syn = { version = "2.0.29", features = ["extra-traits", "parsing", "printing"], default-features = false } [dev-dependencies] diff --git a/README.md b/README.md index e5551f4..23499e9 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ![Rust 1.45.0](https://img.shields.io/static/v1?logo=Rust&label=&message=1.45.0&color=grey) [![CI](https://github.com/Tamschi/unquote/workflows/CI/badge.svg?branch=unstable)](https://github.com/Tamschi/unquote/actions?query=workflow%3ACI+branch%3Aunstable) -![Crates.io - License](https://img.shields.io/crates/l/unquote/0.0.6) +![Crates.io - License](https://img.shields.io/crates/l/unquote/0.0.7) [![GitHub](https://img.shields.io/static/v1?logo=GitHub&label=&message=%20&color=grey)](https://github.com/Tamschi/unquote) [![open issues](https://img.shields.io/github/issues-raw/Tamschi/unquote)](https://github.com/Tamschi/unquote/issues) @@ -96,8 +96,8 @@ fn main() -> Result<(), Box> { | Span Captures | | |-|-| | `#'span`⁴ | ✔ | -| `#^'span`⁴ | ✔ | -| `#$'span`⁴ | ✔ | +| `#^'span`⁴ | | +| `#$'span`⁴ | | | Positional Bindings...?⁵ | | |-|-| diff --git a/src/lib.rs b/src/lib.rs index eb9edc8..8644230 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/unquote/0.0.6")] +#![doc(html_root_url = "https://docs.rs/unquote/0.0.7")] #![warn(clippy::pedantic)] #[cfg(doctest)] @@ -40,7 +40,7 @@ macro_rules! grammar_todo { return Err(Error::new_spanned( $token, format_args!("Not yet implemented: {}", $name), - )); + )) }; } @@ -56,7 +56,6 @@ fn unquote_outer(input: ParseStream) -> Result { let declare_up_front = declare_up_front.into_iter(); Ok(quote_spanned!(Span::mixed_site()=> let #input_ident = #parse_stream; - let mut prev_span = #input_ident.cursor().span(); #(let #declare_up_front;)* #output )) @@ -82,11 +81,9 @@ fn unquote_inner( .unwrap_or_else(|_| Err(Error::new(group.span_close(), "Unexpected end of undelimited group")))?, }, TokenTree::Ident(ident) => { - let message = Literal::string(&format!("Expected `{}`", ident.to_string())); + let message = Literal::string(&format!("Expected `{ident}`")); hygienic_spanned! {ident.span()=> - if #input_ident.call(::parse_any)? - != syn::parse::Parser::parse2(::parse_any, quote!(#ident)).unwrap() - { + if #input_ident.call(::parse_any)? != stringify!(#ident) { return Err(syn::Error::new(#input_ident.cursor().span(), #message)); } } @@ -116,7 +113,6 @@ fn unquote_inner( .unwrap_or_else(|| r#do.span()) => #placeholder = #input_ident.call(#parser_function)?; - prev_span = syn::spanned::Spanned::span(&#placeholder); } } TokenTree::Ident(r#let) if r#let == "let" => { @@ -124,18 +120,16 @@ fn unquote_inner( declare_up_front.insert(placeholder.clone()); hygienic_spanned! {punct.span().join(r#let.span()).and_then(|s| s.join(placeholder.span())).unwrap_or_else(|| r#let.span())=> #placeholder = #input_ident.parse()?; - prev_span = syn::spanned::Spanned::span(&#placeholder); } } TokenTree::Ident(placeholder) => { hygienic_spanned! {punct.span().join(placeholder.span()).unwrap_or_else(|| placeholder.span())=> #placeholder = #input_ident.parse()?; - prev_span = syn::spanned::Spanned::span(&#placeholder); } } TokenTree::Punct(number_sign) if punct.spacing() == Spacing::Joint && number_sign.as_char() == '#' => { hygienic_spanned! {punct.span().join(number_sign.span()).unwrap_or_else(||number_sign.span())=> - prev_span = #input_ident.parse::()?.span; + #input_ident.parse::()?; } } TokenTree::Punct(apostrophe) @@ -148,50 +142,6 @@ fn unquote_inner( #placeholder = #input_ident.span(); } } - TokenTree::Punct(caret) - if punct.spacing() == Spacing::Joint - && caret.as_char() == '^' => - { - let apostrophe: TokenTree= input.parse()?; - match apostrophe { - TokenTree::Punct(apostrophe) - if apostrophe.as_char() == '\'' - &&apostrophe.spacing() == Spacing::Joint => - { - let identifier = input.parse::()?; - let hygienic_identifier = Ident::new(&identifier.to_string(), identifier.span().resolved_at(Span::mixed_site())); - if !declare_up_front.insert(hygienic_identifier.clone()) { - return Err(Error::new(identifier.span(), format_args!("Duplicate Span start: `{}`", identifier))); - } - hygienic_spanned!(punct.span().join(identifier.span()).unwrap_or_else(|| identifier.span())=> - #hygienic_identifier = #input_ident.cursor().span(); - ) - } - other => { - return Err(Error::new_spanned(other, "Expected span identifier written as lifetime.")); - } - } - } - TokenTree::Punct(dollar) - if punct.spacing() == Spacing::Joint && dollar.as_char() == '$' => - { - let apostrophe: TokenTree = input.parse()?; - match apostrophe { - TokenTree::Punct(apostrophe) - if apostrophe.as_char() == '\'' - && apostrophe.spacing() == Spacing::Joint => - { - let identifier = input.parse::()?; - let hygienic_identifier = Ident::new(&identifier.to_string(), identifier.span().resolved_at(Span::mixed_site())); - hygienic_spanned!(punct.span().join(identifier.span()).unwrap_or_else(|| identifier.span())=> - #identifier = #hygienic_identifier.join(prev_span).unwrap_or(#hygienic_identifier); - ) - } - other => { - return Err(Error::new_spanned(other, "Expected span identifier written as lifetime.")); - } - } - } other => { return Err(Error::new_spanned( other, @@ -202,17 +152,15 @@ fn unquote_inner( } _char => hygienic_spanned! {punct.span()=> //TODO: Spacing - prev_span = #input_ident.parse::()?.span; + #input_ident.parse::()?; }, }, TokenTree::Literal(literal) => { - let message = Literal::string(&format!("Expected `{}`", literal.to_string())); + let message = Literal::string(&format!("Expected `{literal}`")); hygienic_spanned! {literal.span()=> let parsed = #input_ident.parse::()?; if parsed != syn::parse2(quote!(#literal)).unwrap() { return Err(syn::Error::new(#input_ident.cursor().span(), #message)); - } else { - prev_span = parsed.span(); } } } diff --git a/tests/quote_unquote.rs b/tests/quote_unquote.rs index 0cde48d..e9dcbec 100644 --- a/tests/quote_unquote.rs +++ b/tests/quote_unquote.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_late_init)] + use call2_for_syn::{call2_allow_incomplete, call2_strict}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; @@ -107,21 +109,6 @@ fn number_sign_escape() -> Result<()> { .unwrap() } -//TODO: Test more thoroughly which spans are captured! -#[test] -fn span_range() -> Result<()> { - let tokens = quote!(.); - - let _: Span = call2_strict(tokens, |input| { - let span; - unquote!(input, #^'span . #$'span); - Result::Ok(span) - }) - .unwrap()?; - - Ok(()) -} - #[derive(Debug)] struct Attributes(Vec); impl Attributes {