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! {
#[parser]
mod parse {
use super::Instr;
type Lexer = parse_it::CharLexer;
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::Cursor;pub use crate::lexer::LexerState;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.