added almost the full grammar, added extra parsers and lexers for
testing
This commit is contained in:
		| @@ -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()); | ||||
| // } | ||||
| @@ -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, | ||||
|     }; | ||||
|   | ||||
| @@ -1,2 +1 @@ | ||||
| mod expressions; | ||||
| mod literals; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user