Macro syn::input_end [] [src]

macro_rules! input_end {
    ($i:expr,) => { ... };
}

Parse nothing and succeed only if the end of the enclosing block has been reached.

The enclosing block may be the full input if we are parsing at the top level, or the surrounding parenthesis/bracket/brace if we are parsing within those.

  • Syntax: input_end!()
  • Output: ()
#[macro_use]
extern crate syn;

use syn::Expr;
use syn::synom::Synom;

/// Parses any Rust expression followed either by a semicolon or by the end
/// of the input.
///
/// For example `many0!(syn!(TerminatedExpr))` would successfully parse the
/// following input into three expressions.
///
///     1 + 1; second.two(); third!()
///
/// Similarly within a block, `braced!(many0!(syn!(TerminatedExpr)))` would
/// successfully parse three expressions.
///
///     { 1 + 1; second.two(); third!() }
struct TerminatedExpr {
    expr: Expr,
    semi_token: Option<Token![;]>,
}

impl Synom for TerminatedExpr {
    named!(parse -> Self, do_parse!(
        expr: syn!(Expr) >>
        semi_token: alt!(
            input_end!() => { |_| None }
            |
            punct!(;) => { Some }
        ) >>
        (TerminatedExpr {
            expr,
            semi_token,
        })
    ));
}

This macro is available if Syn is built with the "parsing" feature.