syn icon indicating copy to clipboard operation
syn copied to clipboard

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

Open uzytkownik opened this issue 1 year ago • 0 comments

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

uzytkownik avatar Feb 05 '24 01:02 uzytkownik