diff --git a/src/parser/ast/mod.rs b/src/parser/ast/mod.rs index 360e5b0..c29b469 100644 --- a/src/parser/ast/mod.rs +++ b/src/parser/ast/mod.rs @@ -1,6 +1,5 @@ -use super::ParseError; use crate::lexer::Token; -use crate::parser::Parser; +use crate::parser::{ParseError, Parser}; use std::error::Error; pub enum Node { @@ -14,15 +13,6 @@ pub enum StatementType { Ident(Identifier), } -pub trait Statement { - fn parse(&mut Parser) -> Result> - where - Self: Sized; - fn new() -> StatementType - where - Self: Sized; -} - #[derive(Debug, PartialEq)] pub struct LetStatement { name: Identifier, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index a0b465c..ed09eb4 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -3,7 +3,7 @@ mod program; pub use self::program::Program; -use self::ast::{LetStatement, Statement, StatementType}; +use self::ast::{LetStatement, StatementType}; use crate::lexer::{Lexer, Token}; use std::iter::Peekable; @@ -27,17 +27,14 @@ impl<'a> Parser<'a> { Err(_) => None, //TODO: Return appropriate error } } - n @ _ => { - println!("{:?}", n); - None - } + _ => None, } } fn expect_peek(&mut self, token: Token) -> bool { if let Some(v) = self.lexer.peek() { if v == &token { - self.lexer.next(); + self.current_token = self.lexer.next(); true } else { false @@ -53,7 +50,7 @@ impl<'a> Parser<'a> { } #[derive(Debug)] -struct ParseError { +pub struct ParseError { desc: String, } diff --git a/src/parser/program.rs b/src/parser/program.rs index 87ce3bb..f3893c3 100644 --- a/src/parser/program.rs +++ b/src/parser/program.rs @@ -1,5 +1,5 @@ use crate::lexer::{Lexer, Token}; -use crate::parser::ast::{Statement, StatementType}; +use crate::parser::ast::StatementType; use crate::parser::Parser; #[derive(Debug)] @@ -13,7 +13,7 @@ impl Program { let mut parser = Parser::new(lexer); loop { if let Some(token) = parser.lexer.next() { - if token == Token::EOF { + if parser.current_token_is(Token::EOF) { break; } @@ -53,14 +53,12 @@ mod tests { let lexer = Lexer::new(ip); let ast_tree = Program::parse(lexer); - println!("{:?}", ast_tree); if ast_tree.statements.len() != 3 { assert_eq!(ast_tree.statements.len(), 3); } for (out, expected_out) in ast_tree.statements.iter().zip(out.statements.iter()) { assert_eq!(out, expected_out); - println!("out={:?}, expected_out={:?}", out, expected_out); } } } diff --git a/src/repl.rs b/src/repl.rs index ee7a1f1..5a1baf4 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -24,6 +24,6 @@ fn start(mut ip: R, mut out: W) { println!("{:?}", token); } - let parser = Program::parse(tokens); + let _parser = Program::parse(tokens); } }