print out error message and add peek error
This commit is contained in:
+3
-2
@@ -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<String> {
|
||||
pub fn errors(&self) -> &Vec<String> {
|
||||
&self.errors
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user