Macro wast::custom_reserved

source ·
macro_rules! custom_reserved {
    ($name:ident) => { ... };
    ($name:ident = $rsv:expr) => { ... };
}
Expand description

A macro for defining custom reserved symbols.

This is like custom_keyword! but for reserved symbols (Token::Reserved) instead of keywords (Token::Keyword).

use wast::parser::{Parser, Result, Parse};

// Define a custom reserved symbol, the "spaceship" operator: `<=>`.
wast::custom_reserved!(spaceship = "<=>");

/// A "three-way comparison" like `(<=> a b)` that returns -1 if `a` is less
/// than `b`, 0 if they're equal, and 1 if `a` is greater than `b`.
struct ThreeWayComparison<'a> {
    lhs: wast::core::Expression<'a>,
    rhs: wast::core::Expression<'a>,
}

impl<'a> Parse<'a> for ThreeWayComparison<'a> {
    fn parse(parser: Parser<'a>) -> Result<Self> {
        parser.parse::<spaceship>()?;
        let lhs = parser.parse()?;
        let rhs = parser.parse()?;
        Ok(ThreeWayComparison { lhs, rhs })
    }
}