operator

Macro operator 

Source
macro_rules! operator {
    ($($(#[$attribute:meta])* $pub:vis $name:ident = $op:literal);*$(;)?) => { ... };
    (@operator $(#[$attribute:meta])* $pub:vis $name:ident = $op:literal) => { ... };
    (@char_at $at:literal $op:literal) => { ... };
}
Expand description

Define types matching operators (punctuation sequences).

operator!{ pub Op = "punct"; ...}

  • A optional pub defines the operators public, default is private
  • Op is the name for the struct to be generated
  • "punct" is up to 4 ASCII punctuation characters

Op::parse() will match the defined operator. It will implement Debug and Clone for operators.

The unsynn! macro supports defining operators by using operator Op = "chars";, the pub specification has to come before operator then.

ยงExample

operator!{
    /// Optional documentation for `<~~`
    WLArrow = "<~~";
    WRArrow = "~~>";
}

let mut tokens = "<~~~~> ~~><~~".to_token_iter();
let wl = WLArrow::parse(&mut tokens).unwrap();
assert_eq!(wl.tokens_to_string(), "<~~");
let wr = WRArrow::parse(&mut tokens).unwrap();
assert_eq!(wr.tokens_to_string(), "~~>");