Macro parser

Source
macro_rules! parser {
    ($($pattern:tt)*) => { ... };
}
Expand description

Macro that creates a parser for a given pattern.

See the top-level documentation for more about how to write patterns.

Here’s a formal syntax for patterns:

pattern ::= expr

expr ::= seq
  | seq "=>" rust_expr      -- custom conversion

seq ::= lterm
  | seq lterm               -- concatenated subpatterns

lterm ::= term
  | ident ":" term          -- labeled subpattern

term ::= prim
  | term "*"                -- optional repeating
  | term "+"                -- repeating
  | term "?"                -- optional

prim ::= "(" expr ")"
  | ident "(" expr,* ")"    -- function call
  | ident                   -- named parser (when not followed by `(`)
  | literal                 -- exact char or string
  | "{" expr,* "}"          -- one-of syntax

ident ::= a Rust identifier
expr ::= a Rust expression
literal ::= a Rust literal