From aa9fdadc1fc80148319abdb5b00d3784541ec546 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Fri, 27 May 2022 23:45:29 +0200 Subject: [PATCH] Added the error line --- src/bootstraparse/modules/context_mngr.py | 3 ++- src/bootstraparse/modules/error_mngr.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bootstraparse/modules/context_mngr.py b/src/bootstraparse/modules/context_mngr.py index a5f1d6a..9e32372 100644 --- a/src/bootstraparse/modules/context_mngr.py +++ b/src/bootstraparse/modules/context_mngr.py @@ -325,6 +325,7 @@ class ContextManager: # self.pile = self.parsed_list.copy() line_number = 1 for index, token in enumerate(self.parsed_list): + token.line_number = line_number self.pile.append(token) try: if isinstance(token, syntax.Linebreak): @@ -335,7 +336,7 @@ class ContextManager: elif token.counterpart() in self.matched_elements: self.encapsulate(self._get_matched(token.counterpart()), index) elif isinstance(token, syntax.ClosedSemanticType): - raise MismatchedContainerError(token, line_number) + raise MismatchedContainerError(token) else: self._add_matched(token.label, index) diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index 9110ed7..5bb9953 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -15,7 +15,7 @@ from bootstraparse.modules.tools import __GLk # __GFi, __GFu, __GL # Define the error codes -_ERRORS = ["ParsingError"] +_ERRORS = ["ParsingError", "MismatchedContainerError"] __all__ = _ERRORS+[] @@ -143,4 +143,4 @@ class MismatchedContainerError(Exception): def __init__(self, token, line=-1): # TODO: context_manager needs to pass over line for error handling self.token = token self.line = line - super().__init__(f"Could not process {token.label} in line {line}.") + super().__init__(f"Could not process {token.label} in line {token.line_number}.")