#![feature(proc_macro_hygiene)] use parze::prelude::*; #[derive(Clone, Debug, PartialEq)] enum Instr { Add, Sub, Left, Right, In, Out, Loop(Vec), } #[test] #[allow(unused_variables)] fn simple() { parsers! { sym: Parser = { '+' } or: Parser = { '+' | '-' } then: Parser = { '+' & '-' } repeat_at_least_once: Parser = { ('+' & '-')+ } repeater_4: Parser = { '+'* } mapper: Parser = { '+' => { |c| format!("{}", c) } } bf: Parser = { ( '+' -> { Instr::Add } | '-' -> { Instr::Sub } | '<' -> { Instr::Left } | '>' -> { Instr::Right } | ',' -> { Instr::In } | '.' -> { Instr::Out } | '[' -& bf &- ']' => { |i| Instr::Loop(i) } )* } } bf.parse(&"++[,>>]++-".chars().collect::>()).unwrap(); }