Skip to content

Commit

Permalink
Merge branch 'develop' into unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamschi committed Aug 26, 2023
2 parents 7c4fae7 + 1bde1df commit 8b7c1f6
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion .github/workflows/audit_at_midnight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/audit_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deny_warnings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust_auto_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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
components: rustfmt
- 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'
Expand Down
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"recommendations": [
"bungcip.better-toml",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"editorconfig.editorconfig",
"matklad.rust-analyzer",
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

<!-- markdownlint-disable no-trailing-punctuation -->

## 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
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "unquote"
version = "0.0.6"
version = "0.0.7"
authors = ["Tamme Schichler <tamme@schichler.dev>"]
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"
Expand All @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -96,8 +96,8 @@ fn main() -> Result<(), Box<dyn Error>> {
| Span Captures | |
|-|-|
| `#'span`||
| `#^'span`| |
| `#$'span`| |
| `#^'span`| |
| `#$'span`| |

| Positional Bindings...?⁵ | |
|-|-|
Expand Down
66 changes: 7 additions & 59 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -40,7 +40,7 @@ macro_rules! grammar_todo {
return Err(Error::new_spanned(
$token,
format_args!("Not yet implemented: {}", $name),
));
))
};
}

Expand All @@ -56,7 +56,6 @@ fn unquote_outer(input: ParseStream) -> Result<TokenStream> {
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
))
Expand All @@ -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(<syn::Ident as syn::ext::IdentExt>::parse_any)?
!= syn::parse::Parser::parse2(<syn::Ident as syn::ext::IdentExt>::parse_any, quote!(#ident)).unwrap()
{
if #input_ident.call(<syn::Ident as syn::ext::IdentExt>::parse_any)? != stringify!(#ident) {
return Err(syn::Error::new(#input_ident.cursor().span(), #message));
}
}
Expand Down Expand Up @@ -116,26 +113,23 @@ 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" => {
let placeholder: Ident = input.parse()?;
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::<syn::Token![#]>()?.span;
#input_ident.parse::<syn::Token![#]>()?;
}
}
TokenTree::Punct(apostrophe)
Expand All @@ -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::<Ident>()?;
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::<Ident>()?;
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,
Expand All @@ -202,17 +152,15 @@ fn unquote_inner(
}
_char => hygienic_spanned! {punct.span()=>
//TODO: Spacing
prev_span = #input_ident.parse::<syn::Token![#punct]>()?.span;
#input_ident.parse::<syn::Token![#punct]>()?;
},
},
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::<syn::Lit>()?;
if parsed != syn::parse2(quote!(#literal)).unwrap() {
return Err(syn::Error::new(#input_ident.cursor().span(), #message));
} else {
prev_span = parsed.span();
}
}
}
Expand Down
17 changes: 2 additions & 15 deletions tests/quote_unquote.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<Attribute>);
impl Attributes {
Expand Down

0 comments on commit 8b7c1f6

Please sign in to comment.