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

@@ -2,7 +2,7 @@ use crate::errors::CLIArgumentError;
use lrlex::lrlex_mod;
use lrpar::lrpar_mod;
use std::error::Error;
use std::fmt::{Display, format};
use std::fmt::Display;
use std::io;
use std::io::ErrorKind::InvalidInput;
@@ -11,8 +11,8 @@ mod errors;
mod optimising;
mod tests;
lrlex_mod!("grammar.l");
lrpar_mod!("grammar.y");
lrlex_mod!("lexers/fudge.l");
lrpar_mod!("parsers/fudge.y");
fn main() -> Result<(), Box<dyn Error>> {
let src_path = std::env::args()
@@ -20,13 +20,25 @@ fn main() -> Result<(), Box<dyn Error>> {
.ok_or(Box::new(CLIArgumentError("Source File Not Provided")))?;
let src_string = std::fs::read_to_string(&src_path)?;
let lexerdef = grammar_l::lexerdef();
let lexer_def = fudge_l::lexerdef();
let lexer = lexerdef.lexer((src_string.as_str()));
let (res, errs) = grammar_y::parse(&lexer);
if let Some(Ok(res)) = res {
println!("{:#?}", res);
let lexer = lexer_def.lexer(src_string.as_str());
let (res, errs) = fudge_y::parse(&lexer);
match (res, errs) {
(Some(Ok(res)), _) => {
println!("Parsed succesfully:");
println!("{:#?}", res);
},
(Some(Err(e)), _) => {
println!("Parsing failed:");
println!("{:#?}", e);
}
(_, vec) => {
println!("LexParseErrors encountered:");
println!("{:#?}", vec);
}
}
Ok(())
}