Crate parse_it

Source
Expand description

§Parse It

A user-friendly, opinionated parser generator for Rust.

§Example

use parse_it::{ParseIt, parse_it};
 
#[derive(Debug, Clone)]
pub enum Instr {
    Left,
    Right,
    Incr,
    Decr,
    Read,
    Write,
    Loop(Vec<Self>),
}
 
parse_it! {
    mod parse {
        use super::Instr;
 
        pub Brainfuck -> Vec<Instr> {
            Primitive* => self,
        }
 
        Primitive -> Instr {
            '<' => Instr::Left,
            '>' => Instr::Right,
            '+' => Instr::Incr,
            '-' => Instr::Decr,
            ',' => Instr::Read,
            '.' => Instr::Write,
            '[' Primitive+ ']' => Instr::Loop(self)
        }
    }
}
 
fn main() {
    let parser = parse::Brainfuck::default();
    let src = "--[>--->->->++>-<<<<<-------]>--.>---------.>--..+++.>----.>+++++++++.<<.+++.------.<-.>>+";
    let instrs = parser.parse(src).unwrap();
    println!("{:?}", instrs);
}

Re-exports§

pub use crate::lexer::CharLexer;
pub use crate::lexer::Lexer;
pub use crate::memo::left_rec;
pub use crate::memo::memorize;
pub use crate::memo::Memo;
pub use crate::parser::Error;
pub use crate::parser::ParserState;

Modules§

lexer
Lexing for the parser.
memo
Memoization and left recursion support.
parser
Basic definitions for working with the parser.

Macros§

parse_it

Traits§

ParseIt
A parser.