xenon_parser/
lib.rs

1use lexer::LexerIter;
2use node::Program;
3use parser::Parser;
4
5mod lexer;
6mod parser;
7pub mod node;
8
9pub fn parse(code: &str) -> Program {
10    let tokens: LexerIter = lexer::lex_tokens(code);  // Lex tokens from the source code
11
12    let tokvec: Vec<_> = tokens.collect(); // Collect tokens into a Vec
13    let mut parser = Parser::new(&tokvec); // Pass the slice of tokens to the parser
14    
15    let program = parser.parse();  // Parse the tokens (assuming `parse` is implemented)
16    return program
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*; // Import everything from the parent module
22
23    #[test]
24    fn test_program_parsing() {
25        let code = r#"
26            use example.library;
27
28            namespace Program {
29                fn main() {
30                    float i = 0 + 123 * 48 / 18 % 3;
31                    i = 0 * 12 - 3 / 12;
32                    core.io.writeLn("Hello World");
33                    if (i == 0) {
34                        core.io.writeLn("It's 2!");
35                    }
36                    while (i == 0) {
37                        i = i + 1;
38                    }
39                }
40            }
41        "#;
42
43        let program = parse(code); // Use the parse function
44
45        println!("{:#?}", program);
46    }
47}