From ab8e24a2761ecc92bd454510a77689312761ab83 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 8 Jan 2019 01:04:46 -0800 Subject: [PATCH] ParseError always has token now --- schala-lang/codegen/src/lib.rs | 8 +------- schala-lang/language/src/lib.rs | 19 +++++++------------ schala-lang/language/src/parsing.rs | 9 +++------ 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/schala-lang/codegen/src/lib.rs b/schala-lang/codegen/src/lib.rs index b4754aa..6883a4d 100644 --- a/schala-lang/codegen/src/lib.rs +++ b/schala-lang/codegen/src/lib.rs @@ -32,13 +32,7 @@ impl Fold for RecursiveDescentFn { if self.parse_level != 0 { self.parse_level -= 1; } - match 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 - } + result } }; i.block = Box::new(new_block); diff --git a/schala-lang/language/src/lib.rs b/schala-lang/language/src/lib.rs index b604630..dc3c71e 100644 --- a/schala-lang/language/src/lib.rs +++ b/schala-lang/language/src/lib.rs @@ -135,25 +135,20 @@ fn parsing(input: Vec, handle: &mut Schala, comp: Option<&mut } fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String { - //TODO make token no longer be Optoinal - if let Some(tok) = error.token { - let line_num = tok.offset.0; - let ch = tok.offset.1; - let line_from_program = handle.source_reference.get_line(line_num); - let location_pointer = format!("{}^", " ".repeat(ch)); + let line_num = error.token.offset.0; + let ch = error.token.offset.1; + let line_from_program = handle.source_reference.get_line(line_num); + let location_pointer = format!("{}^", " ".repeat(ch)); - let line_num_digits = format!("{}", line_num).chars().count(); - let space_padding = " ".repeat(line_num_digits); + let line_num_digits = format!("{}", line_num).chars().count(); + let space_padding = " ".repeat(line_num_digits); - format!(r#" + format!(r#" {error_msg} {space_padding} | {line_num} | {} {space_padding} | {} "#, 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 { diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 41b4cb3..301949b 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -13,15 +13,12 @@ use crate::builtin::{BinOp, PrefixOp}; #[derive(Debug)] pub struct ParseError { pub msg: String, - pub token: Option + pub token: Token } impl ParseError { - fn new_with_token(msg: &str, t: Token) -> ParseResult{ - Err(ParseError { - msg: msg.to_string(), - token: Some(t) - }) + fn new_with_token(msg: &str, token: Token) -> ParseResult{ + Err(ParseError { msg: msg.to_string(), token }) } }