From ed03d565ea6bf539646289090d2587adfa6ee6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 30 Dec 2022 23:50:33 +0100 Subject: [PATCH] Parser - Created structure --- src/main.rs | 9 ++++++++- src/parser.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/parser.rs diff --git a/src/main.rs b/src/main.rs index fe00d16..8cc4cc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod ast; mod errors; +mod parser; mod scanner; mod tokens; @@ -10,16 +11,22 @@ use std::{ }; use errors::ErrorHandler; +use parser::Parser; use scanner::Scanner; /// Execute a script. fn run(source: String) -> ErrorHandler { let mut error_handler = ErrorHandler::default(); + let scanner = Scanner::new(source); let tokens = scanner.scan_tokens(&mut error_handler); - for token in tokens { + + for token in tokens.iter() { println!("{:#?}", token); } + + let _parser = Parser::new(tokens); + error_handler } diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..aa28eef --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,12 @@ +use crate::tokens::Token; + +#[derive(Debug)] +pub struct Parser { + tokens: Vec, +} + +impl Parser { + pub fn new(tokens: Vec) -> Self { + Self { tokens } + } +}