Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose AllowNoSemi, add Stmt::requires_terminator and allow custom function to be passed to Block::parse_within #1587

Closed
uzytkownik opened this issue Feb 5, 2024 · 1 comment

Comments

@uzytkownik
Copy link

I want to write a macro that adds a special type of statement. Currently I need to re-implement the sym functionality.

It would make much easier if AllowNoSemi was exposed or Block::parse_within allowed custom function to be passed:

struct My {
    Stmt(Stmt),
    Custom(Custom),
}

impl RequiresTerminator {
    fn requires_terminator(&self) -> bool {
        match self {
            My::Stmt(stmt) => stmt.requires_terminator(&self),
            My::Custom(my) => my.requires_terminator(&self),
        }
    }
}

let r: Vec<My> = Block::call_within(input, |input| {
    if input.peek(kw::my) {
        My::Custom(input.parse()?)
    } else {
        My::Stmt(input.parse()?)
    }
});
@dtolnay
Copy link
Owner

dtolnay commented Jun 22, 2024

Parsing supersets of Rust syntax (with new statement or expression or item kinds) is not a goal for syn's Rust syntax tree types, so I would prefer not to change the API in the suggested way. I would recommend coming up with a different library that would be better for this use case.

@dtolnay dtolnay closed this as completed Jun 22, 2024
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

No branches or pull requests

2 participants