iowo/crates/lang/src/parser/grammar.rs

35 lines
680 B
Rust
Raw Normal View History

2024-04-24 21:09:55 +02:00
use std::fmt::Debug;
2024-04-24 11:07:38 +02:00
use crate::parser::syntax_kind::SyntaxKind::*;
2024-04-24 21:09:55 +02:00
use super::{
input::Input,
output::Output,
syntax_kind::{self, lex},
Parser,
};
2024-04-24 11:07:38 +02:00
mod expression;
pub fn source_file(p: &mut Parser) {
2024-04-24 19:55:16 +02:00
let root = p.start("root");
2024-04-24 11:07:38 +02:00
expression::expression(p);
p.eat_succeeding_ws();
root.complete(p, ROOT);
}
2024-04-24 21:09:55 +02:00
fn check_parser(input: &str, parser_fn: fn(&mut Parser), output: &str) {
let toks = lex(input);
let mut parser = Parser::new(Input::new(&toks));
parser_fn(&mut parser);
let p_out = dbg!(parser.finish());
let o = Output::from_parser_output(toks, p_out);
let s = format!("{o:?}");
assert_eq!(&s, output);
}