added almost the full grammar, added extra parsers and lexers for

testing
This commit is contained in:
2025-10-25 11:39:07 +02:00
parent 4c08803a54
commit a0a6a15be3
17 changed files with 369 additions and 118 deletions

View File

@@ -1,16 +0,0 @@
//
//
// #[test]
// fn identifiers() {
// use crate::expressions::IdentifierParser as IdentParser;
// assert!(IdentParser::new().parse("a").is_ok());
// assert!(IdentParser::new().parse("_").is_ok());
// assert!(IdentParser::new().parse("a_a_a_").is_ok());
// assert!(IdentParser::new().parse("_0").is_ok());
// assert!(IdentParser::new().parse("_a").is_ok());
// assert!(IdentParser::new().parse("__").is_ok());
//
// assert!(IdentParser::new().parse("0").is_err());
// assert!(IdentParser::new().parse("0123456").is_err());
// assert!(IdentParser::new().parse("0aaaa").is_err());
// }

View File

@@ -1,10 +1,12 @@
use lrlex::lrlex_mod;
use lrpar::lrpar_mod;
use crate::ast::{Expression, Literal};
use crate::ast::{Expression, Literal, Program};
lrlex_mod!("grammar.l");
lrpar_mod!("grammar.y");
lrlex_mod!("lexers/fudge.l");
lrpar_mod!("parsers/fudge.y");
lrlex_mod!("lexers/expr_only.l");
lrpar_mod!("parsers/expr_only.y");
macro_rules! test_literal_list {
@@ -19,10 +21,10 @@ macro_rules! test_literal_list {
};
}
fn parse_str(input: &str) -> Result<Expression, ()> {
let lexerdef = grammar_l::lexerdef();
fn parse_expr(input: &str) -> Result<Expression, ()> {
let lexerdef = expr_only_l::lexerdef();
let lexer = lexerdef.lexer(&input);
let (res, errs) = grammar_y::parse(&lexer);
let (res, errs) = expr_only_y::parse(&lexer);
if let Some(parsed_res) = res {
parsed_res
} else {
@@ -30,13 +32,9 @@ fn parse_str(input: &str) -> Result<Expression, ()> {
}
}
#[test]
fn test_int_literal() {
let lexer = grammar_l::lexerdef();
let valid_ints = vec!["1", "1", "100000000000000000", "1234567890", "1234567890"];
let invalid_ints = vec!["01", "AAAAAAAAAAAAAAA", "-1"];
let matches_parsed_int = |s: &str| match parse_str(s) {
let matches_parsed_int = |s: &str| match parse_expr(s) {
Ok(i) => matches!(i, Expression::Lit(Literal::Int(_))),
Err(_) => false,
};

View File

@@ -1,2 +1 @@
mod expressions;
mod literals;