Skip to content

Conversation

@tremwil
Copy link
Contributor

@tremwil tremwil commented Feb 2, 2025

Currently, the following use of pattern! does not compile:

use pelite::pattern;
use pelite::pattern::Atom;

macro_rules! forward_pat {
    ($pat:literal) => {
        pattern!($pat)
    }
}

const PAT: &[Atom] = forward_pat("");

This is because macro_rules! capture expressions, like $pat, get wrapped in a TokenTree::Group with no delimiter to preserve the order of operations (see https://doc.rust-lang.org/beta/proc_macro/enum.Delimiter.html#variant.None).

This PR fixes this without adding dependencies on other parsing libraries by first checking if the input is a no-delimiter group, and if so, expanding before trying to match on a TokenTree::Literal.

@CasualX CasualX merged commit dfc2cfd into CasualX:master Feb 8, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants