From 904d5c443145e9819441334936e8f6bc11ba4d6f Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 2 Oct 2019 03:38:18 -0700 Subject: [PATCH] Add "production" line to parse debug output And also add a .next() in the parser that should've been there --- schala-lang/language/src/parsing.rs | 1 + schala-lang/language/src/schala.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index c591827..b6a457c 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -825,6 +825,7 @@ impl Parser { let lhs = self.prefix_expr()?; let ref next = self.token_handler.peek_kind(); Ok(if let Some(op) = BinOp::from_sigil_token(next) { + self.token_handler.next(); Discriminator::BinOp(lhs, op) } else { Discriminator::Simple(lhs) diff --git a/schala-lang/language/src/schala.rs b/schala-lang/language/src/schala.rs index 5d9d137..9d5bc51 100644 --- a/schala-lang/language/src/schala.rs +++ b/schala-lang/language/src/schala.rs @@ -127,12 +127,18 @@ fn format_parse_error(error: parsing::ParseError, handle: &mut Schala) -> String let line_num_digits = format!("{}", line_num).chars().count(); let space_padding = " ".repeat(line_num_digits); + let production = match error.production_name { + Some(n) => format!("\n(from production \"{}\")", n), + None => "".to_string() + }; + format!(r#" -{error_msg} +{error_msg}{production} {space_padding} | {line_num} | {} {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, production=production +) } fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut PassDebugArtifact>) -> Result {