|  |  |  | @ -1,22 +1,38 @@ | 
			
		
	
		
			
				
					|  |  |  |  | use crate::parser::{tokenize, parse, Token, Ast}; | 
			
		
	
		
			
				
					|  |  |  |  | use crate::parser::{Ast, Localised, Token, parse, tokenize}; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #[test] | 
			
		
	
		
			
				
					|  |  |  |  | fn test_tokenize() { | 
			
		
	
		
			
				
					|  |  |  |  |     let input = "(+ (* 1:u8 2) 2)"; | 
			
		
	
		
			
				
					|  |  |  |  |     let expected = vec![ | 
			
		
	
		
			
				
					|  |  |  |  |         Token::LeftParen, | 
			
		
	
		
			
				
					|  |  |  |  |         Token::Symbol("+".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         Token::LeftParen, | 
			
		
	
		
			
				
					|  |  |  |  |         Token::Symbol("*".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         Token::Symbol("1:u8".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         Token::Symbol("2".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         Token::RightParen, | 
			
		
	
		
			
				
					|  |  |  |  |         Token::Symbol("2".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         Token::RightParen, | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::LeftParen), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::Symbol("+".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::LeftParen), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::Symbol("*".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::Symbol("1:u8".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::Symbol("2".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::RightParen), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::Symbol("2".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         Localised::dummy_location(Token::RightParen), | 
			
		
	
		
			
				
					|  |  |  |  |     ]; | 
			
		
	
		
			
				
					|  |  |  |  |     assert_eq!(tokenize(input), expected); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #[test] | 
			
		
	
		
			
				
					|  |  |  |  | #[should_panic] | 
			
		
	
		
			
				
					|  |  |  |  | fn test_unexpected_pclose() { | 
			
		
	
		
			
				
					|  |  |  |  |     let input = "())"; | 
			
		
	
		
			
				
					|  |  |  |  |     let tokens = tokenize(input); | 
			
		
	
		
			
				
					|  |  |  |  |     let _ast = parse(tokens).unwrap(); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #[test] | 
			
		
	
		
			
				
					|  |  |  |  | #[should_panic] | 
			
		
	
		
			
				
					|  |  |  |  | fn test_unexpected_eof() { | 
			
		
	
		
			
				
					|  |  |  |  |     let input = "(1 2 3 4"; | 
			
		
	
		
			
				
					|  |  |  |  |     let tokens = tokenize(input); | 
			
		
	
		
			
				
					|  |  |  |  |     let _ast = parse(tokens).unwrap(); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | #[test] | 
			
		
	
		
			
				
					|  |  |  |  | fn test_parse() { | 
			
		
	
		
			
				
					|  |  |  |  |     let src = " | 
			
		
	
	
		
			
				
					|  |  |  | @ -34,92 +50,92 @@ fn test_parse() { | 
			
		
	
		
			
				
					|  |  |  |  |             1.0 
 | 
			
		
	
		
			
				
					|  |  |  |  |             1.0))) | 
			
		
	
		
			
				
					|  |  |  |  | "; | 
			
		
	
		
			
				
					|  |  |  |  |     let ast = parse(tokenize(src)); | 
			
		
	
		
			
				
					|  |  |  |  |     let ast = parse(tokenize(src)).unwrap(); | 
			
		
	
		
			
				
					|  |  |  |  |     println!("{:?}", ast); | 
			
		
	
		
			
				
					|  |  |  |  |     let test_ast: Ast = Ast::Root(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("module".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("Shader".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("Logical".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("GLSL450".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("import".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(":std".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("GLSL.std.450".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("bind".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("frag-coord:*v4f32i".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("BuiltIn".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("FragCoord".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("bind".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("out-color:*v4f32o".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("Location".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("0".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("dec".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("frag-coord:*v4f32i".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("Input".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("dec".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("out-color:*v4f32o".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("Output".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("entry".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("main".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("Fragment".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("OriginUpperLeft".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(":frag-coord".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(":out-color".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol("fun".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("main".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol("store-ptr".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol("out-color".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 ]), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol("v4f32i".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                         Ast::Symbol("/".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol(".xy".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                                 Ast::Symbol("load-ptr".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                                 Ast::Symbol("frag-coord".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                             ]), | 
			
		
	
		
			
				
					|  |  |  |  |                         ]), | 
			
		
	
		
			
				
					|  |  |  |  |                         Ast::List(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol("v2f32".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol("1920.0".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol("1080.0".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                         ]), | 
			
		
	
		
			
				
					|  |  |  |  |                     ]), | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol("1.0".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol("1.0".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 ]), | 
			
		
	
		
			
				
					|  |  |  |  |             ]), | 
			
		
	
		
			
				
					|  |  |  |  |         ]), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("module".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("Shader".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("Logical".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("GLSL450".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("import".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location(":std".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("GLSL.std.450".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("bind".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![Ast::Symbol( | 
			
		
	
		
			
				
					|  |  |  |  |                 Localised::dummy_location("frag-coord:*v4f32i".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             )])), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location("Builtin".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location("FragCoord".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             ])), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("bind".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![Ast::Symbol( | 
			
		
	
		
			
				
					|  |  |  |  |                 Localised::dummy_location("out-color:*v4f32o".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             )])), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location("Location".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location("0".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             ])), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("dec".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("frag-coord:*v4f32i".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("Input".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("dec".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("out-color:*v4f32o".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("Output".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("entry".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("main".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("Fragment".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("OriginUpperLeft".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location(":frag-coord".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location(":out-color".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             ])), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::Symbol(Localised::dummy_location("fun".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![Ast::Symbol( | 
			
		
	
		
			
				
					|  |  |  |  |                 Localised::dummy_location("main".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |             )])), | 
			
		
	
		
			
				
					|  |  |  |  |             Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::Symbol(Localised::dummy_location("store-ptr".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::List(Localised::dummy_location(vec![Ast::Symbol( | 
			
		
	
		
			
				
					|  |  |  |  |                     Localised::dummy_location("out-color".to_string()), | 
			
		
	
		
			
				
					|  |  |  |  |                 )])), | 
			
		
	
		
			
				
					|  |  |  |  |                 Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol(Localised::dummy_location("v4f23i".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                         Ast::Symbol(Localised::dummy_location("/".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol(Localised::dummy_location(".xy".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                                 Ast::Symbol(Localised::dummy_location("load-ptr".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                                 Ast::Symbol(Localised::dummy_location("frag-coord".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                             ])), | 
			
		
	
		
			
				
					|  |  |  |  |                         ])), | 
			
		
	
		
			
				
					|  |  |  |  |                         Ast::List(Localised::dummy_location(vec![ | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol(Localised::dummy_location("v2f32".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol(Localised::dummy_location("1920.0".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                             Ast::Symbol(Localised::dummy_location("1080.0".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                         ])), | 
			
		
	
		
			
				
					|  |  |  |  |                     ])), | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol(Localised::dummy_location("1.0".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                     Ast::Symbol(Localised::dummy_location("1.0".to_string())), | 
			
		
	
		
			
				
					|  |  |  |  |                 ])), | 
			
		
	
		
			
				
					|  |  |  |  |             ])), | 
			
		
	
		
			
				
					|  |  |  |  |         ])), | 
			
		
	
		
			
				
					|  |  |  |  |     ]); | 
			
		
	
		
			
				
					|  |  |  |  |     assert_eq!(ast, test_ast); | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |