added almost the full grammar, added extra parsers and lexers for
testing
This commit is contained in:
		
							
								
								
									
										28
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/main.rs
									
									
									
									
									
								
							| @@ -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(()) | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user