parser now bubbles errors instead of unit type

llvm added to dependencies
This commit is contained in:
2025-10-28 12:28:50 +01:00
parent a0a6a15be3
commit 934d961be8
15 changed files with 132 additions and 67 deletions

View File

@@ -1,6 +1,7 @@
use lrlex::lrlex_mod;
use lrpar::lrpar_mod;
use crate::ast::errors::ParsingError;
use crate::ast::{Expression, Literal, Program};
lrlex_mod!("lexers/fudge.l");
@@ -21,19 +22,14 @@ macro_rules! test_literal_list {
};
}
fn parse_expr(input: &str) -> Result<Expression, ()> {
fn parse_expr(input: &str) -> Result<Expression, ParsingError> {
let lexerdef = expr_only_l::lexerdef();
let lexer = lexerdef.lexer(&input);
let (res, errs) = expr_only_y::parse(&lexer);
if let Some(parsed_res) = res {
parsed_res
} else {
Err(())
}
res.expect("REASON")
}
#[test]
fn test_int_literal() {
let matches_parsed_int = |s: &str| match parse_expr(s) {
Ok(i) => matches!(i, Expression::Lit(Literal::Int(_))),
Err(_) => false,