sprite-rs/src/parse/mod.rs

48 lines
1.3 KiB
Rust

// Copyright (c) 2022 Marceline Cramer
// SPDX-License-Identifier: GPL-3.0-or-later
pub mod ast;
pub mod lexer;
pub mod pest;
pub mod rd;
pub trait BuildAst<'a> {
fn build_source_ast(source: &'a str) -> ast::Ast<'a>;
}
#[cfg(test)]
mod tests {
use super::*;
fn parse_with<T: BuildAst<'static>>(source: &'static str) {
let ast = T::build_source_ast(source);
println!("{:#?}", ast);
}
macro_rules! parse_test {
($name:ident, $parser:ty, $file:expr) => {
#[test]
fn $name() {
parse_with::<$parser>(include_str!($file));
}
};
}
macro_rules! test_parser {
($name:ident, $parser:ty) => {
mod $name {
use super::parse_with;
parse_test!(function, $parser, "../test/function.fae");
parse_test!(interface, $parser, "../test/interface.fae");
parse_test!(example, $parser, "../test/example.fae");
parse_test!(clock, $parser, "../test/clock.fae");
parse_test!(mandelbrot_scalar, $parser, "../test/mandelbrot_scalar.fae");
}
};
}
test_parser!(rd, crate::parse::rd::RecursiveDescent);
test_parser!(pest, crate::parse::pest::PestParser);
}