From bf80781f719f2d76ac7882eef9f1aa9e41f0ecfb Mon Sep 17 00:00:00 2001 From: YannAhlgrim Date: Wed, 3 Jun 2026 16:50:41 +0200 Subject: [PATCH] print out error message and add peek error --- src/parser/mod.rs | 5 +++-- src/repl/mod.rs | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 23b1346..749f06a 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -117,7 +117,7 @@ impl Parser { self.peek_token = self.lexer.next_token(); } - fn parse_program(&mut self) -> ast::Program { + pub fn parse_program(&mut self) -> ast::Program { let mut program = ast::Program { statements: Vec::new(), }; @@ -151,6 +151,7 @@ impl Parser { self.next_token(); true } else { + self.peek_error(t); false } } @@ -439,7 +440,7 @@ impl Parser { Some(args) } - fn errors(&self) -> &Vec { + pub fn errors(&self) -> &Vec { &self.errors } diff --git a/src/repl/mod.rs b/src/repl/mod.rs index 3bb7b54..e3eb801 100644 --- a/src/repl/mod.rs +++ b/src/repl/mod.rs @@ -1,7 +1,6 @@ use crate::ast::NodeTrait; use crate::lexer::new; use crate::parser::Parser; -use crate::parser::ParserTrait; use crate::parser::new_parser; const PROMPT: &str = ">> "; @@ -21,6 +20,11 @@ pub fn start_repl() { let lexer = new(input.to_string()); let mut parser: Parser = new_parser(lexer); let program = parser.parse_program(); + + for err in parser.errors() { + eprintln!("ERROR: {}", err); + } + println!("{}", program.string()); } }