Spaces:
Runtime error
Runtime error
File size: 1,493 Bytes
e4806d5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
from ast_parser.token import Location
class PositionedException(Exception):
"""Base class for exceptions with Location.
Args:
source (str): The source string being tokenized.
location (Location): The Location of the exception.
description (str, optional): An optional description of the
error.
"""
source: str
"""The source string being tokenized."""
location: Location
"""The Location of the error in the source."""
def __init__(
self, source: str, location: Location, description: str | None = None
) -> None:
super().__init__(description)
self.source = source
self.location = location
class LexerException(PositionedException):
"""A LexerException is raised when the Lexer encounters an invalid
character or token.
Args:
source (str): The source string being tokenized.
location (Location): The Location of the exception.
description (str, optional): An optional description of the
error.
"""
class LinterException(PositionedException):
"""A LinterException is raised when the Linter encounters an invalid
token chain.
Args:
source (str): The source string being tokenized.
location (Location): The Location of the exception.
description (str, optional): An optional description of the
error.
"""
__all__ = ("PositionedException", "LexerException", "LinterException")
|