From 6a6dd97c52eeeedaed3a7d0c826fb96db5cf1c0b Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Fri, 1 Feb 2019 14:22:47 +0200 Subject: [PATCH] VisitError now allows explicit access to previous exception (Issue #314) --- lark/exceptions.py | 7 ++++++- lark/visitors.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lark/exceptions.py b/lark/exceptions.py index 9a4e9a0..2534ee4 100644 --- a/lark/exceptions.py +++ b/lark/exceptions.py @@ -87,5 +87,10 @@ class UnexpectedToken(ParseError, UnexpectedInput): super(UnexpectedToken, self).__init__(message) class VisitError(Exception): - pass + def __init__(self, tree, orig_exc): + self.tree = tree + self.orig_exc = orig_exc + + message = 'Error trying to process rule "%s":\n\n%s' % (tree.data, orig_exc) + super(VisitError, self).__init__(message) ###} diff --git a/lark/visitors.py b/lark/visitors.py index ed43c26..f89d942 100644 --- a/lark/visitors.py +++ b/lark/visitors.py @@ -43,7 +43,7 @@ class Transformer: except GrammarError: raise except Exception as e: - raise VisitError('Error trying to process rule "%s":\n\n%s' % (tree.data, e)) + raise VisitError(tree, e) def _transform_children(self, children): for c in children: