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

Open
uzytkownik opened this issue Feb 5, 2024 · 0 comments

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()?)
    }
});
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

1 participant