diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index d7cba68..1a2da05 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -156,8 +156,11 @@ class MismatchedContainerError(BootstraparseError): """ def __init__(self, token): # FUTURE : Add file name to error self.token = token - self.line = token.line_number - super().__init__(f"Could not process {token.label} at line {token.line_number}.") + if token: + self.line = token.line_number + else: + self.line = None + super().__init__(f"Could not process {token.label} at line {self.line}.") class LonelyOptionalError(BootstraparseError): @@ -166,9 +169,13 @@ class LonelyOptionalError(BootstraparseError): """ def __init__(self, token, last_in_pile): self.token = token + if token: + self.line = token.line_number + else: + self.line = None if last_in_pile: - super().__init__(f"Could not match token {token} at line {token.line_number} with " + super().__init__(f"Could not match token {token} at line {self.line} with " f"last element in pile {last_in_pile} at line {last_in_pile.line_number} (not a container).") else: - super().__init__(f"Could not match token {token} at line {token.line_number} " + super().__init__(f"Could not match token {token} at line {self.line} " f"as there was nothing in the pile.") diff --git a/src/bootstraparse/modules/export.py b/src/bootstraparse/modules/export.py index 75628d7..aa06b76 100644 --- a/src/bootstraparse/modules/export.py +++ b/src/bootstraparse/modules/export.py @@ -8,6 +8,7 @@ # import rich import rich +from io import StringIO from bootstraparse.modules import config, pathresolver, error_mngr, context_mngr from collections import namedtuple @@ -244,7 +245,6 @@ class ContextConverter: if __name__ == '__main__': # pragma: no cover from bootstraparse.modules import parser - from io import StringIO io_string = StringIO( """<