From 28056b1f89101836e09553d0925150269f6a20df Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 1 Oct 2019 21:40:30 -0700 Subject: [PATCH] Add production name in ParseError for debugging --- schala-lang/codegen/src/lib.rs | 5 ++++- schala-lang/language/src/parsing.rs | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/schala-lang/codegen/src/lib.rs b/schala-lang/codegen/src/lib.rs index 6883a4d..c752a9d 100644 --- a/schala-lang/codegen/src/lib.rs +++ b/schala-lang/codegen/src/lib.rs @@ -32,7 +32,10 @@ impl Fold for RecursiveDescentFn { if self.parse_level != 0 { self.parse_level -= 1; } - result + result.map_err(|mut parse_error: ParseError| { + parse_error.production_name = Some(stringify!(#ident).to_string()); + parse_error + }) } }; i.block = Box::new(new_block); diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 3bf1d37..c591827 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -160,13 +160,14 @@ use crate::ast::*; /// Represents a parsing error #[derive(Debug)] pub struct ParseError { + pub production_name: Option, pub msg: String, pub token: Token } impl ParseError { fn new_with_token(msg: M, token: Token) -> ParseResult where M: Into { - Err(ParseError { msg: msg.into(), token }) + Err(ParseError { msg: msg.into(), token, production_name: None }) } }