ParseError always has token now

This commit is contained in:
greg 2019-01-08 01:04:46 -08:00
parent 09e2d8579d
commit ab8e24a276
3 changed files with 11 additions and 25 deletions

View File

@ -32,13 +32,7 @@ impl Fold for RecursiveDescentFn {
if self.parse_level != 0 { if self.parse_level != 0 {
self.parse_level -= 1; self.parse_level -= 1;
} }
match result { result
Err(ParseError { token: None, msg }) => {
let next_token_after_parse = self.token_handler.peek();
Err(ParseError { token: Some(next_token_after_parse), msg })
},
_ => result
}
} }
}; };
i.block = Box::new(new_block); i.block = Box::new(new_block);

View File

@ -135,10 +135,8 @@ fn parsing(input: Vec<tokenizing::Token>, handle: &mut Schala, comp: Option<&mut
} }
fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String { fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String {
//TODO make token no longer be Optoinal let line_num = error.token.offset.0;
if let Some(tok) = error.token { let ch = error.token.offset.1;
let line_num = tok.offset.0;
let ch = tok.offset.1;
let line_from_program = handle.source_reference.get_line(line_num); let line_from_program = handle.source_reference.get_line(line_num);
let location_pointer = format!("{}^", " ".repeat(ch)); let location_pointer = format!("{}^", " ".repeat(ch));
@ -151,9 +149,6 @@ fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String
{line_num} | {} {line_num} | {}
{space_padding} | {} {space_padding} | {}
"#, line_from_program, location_pointer, error_msg=error.msg, space_padding=space_padding, line_num=line_num) "#, line_from_program, location_pointer, error_msg=error.msg, space_padding=space_padding, line_num=line_num)
} else {
format!("{}", error.msg)
}
} }
fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> { fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut UnfinishedComputation>) -> Result<ast::AST, String> {

View File

@ -13,15 +13,12 @@ use crate::builtin::{BinOp, PrefixOp};
#[derive(Debug)] #[derive(Debug)]
pub struct ParseError { pub struct ParseError {
pub msg: String, pub msg: String,
pub token: Option<Token> pub token: Token
} }
impl ParseError { impl ParseError {
fn new_with_token<T>(msg: &str, t: Token) -> ParseResult<T>{ fn new_with_token<T>(msg: &str, token: Token) -> ParseResult<T>{
Err(ParseError { Err(ParseError { msg: msg.to_string(), token })
msg: msg.to_string(),
token: Some(t)
})
} }
} }