mirror of
https://github.com/fluencelabs/lalrpop
synced 2025-04-01 07:51:03 +00:00
25 lines
650 B
Rust
25 lines
650 B
Rust
#[macro_use] extern crate lalrpop_util;
|
|
|
|
pub mod lexer;
|
|
pub mod ast;
|
|
pub mod eval;
|
|
|
|
lalrpop_mod!(pub parser);
|
|
|
|
pub fn compile(input: &str) -> Result<ast::Program, String> {
|
|
match parser::ProgramParser::new().parse(lexer::Lexer::new(input)) {
|
|
Ok(s) => Ok(ast::Program::new(s)),
|
|
Err(e) => Err(format!("{:?}", e)),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn parse_simple() {
|
|
let input = lexer::Lexer::new("\n\n\n");
|
|
let program = parser::ProgramParser::new().parse(input).expect("Oh no");
|
|
match (program.len(), program.first()) {
|
|
(1, Some(&ast::Stmt::Exit)) => (),
|
|
other => panic!("Well that didn't work: {:?}", other),
|
|
}
|
|
}
|