Fix issue where position was retained across Lexer instances

This commit is contained in:
Elara 2024-11-11 14:55:02 -08:00
parent 4098c0e25a
commit fbd62512d1
3 changed files with 6 additions and 9 deletions

View File

@ -16,9 +16,8 @@ class Block(dict):
super().__init__() super().__init__()
class Interp: class Interp:
vars: dict[str, typing.Any] = {}
def __init__(self, stream: typing.TextIO, name: str): def __init__(self, stream: typing.TextIO, name: str):
self.vars: dict[str, typing.Any] = {}
self.parser = parser.Parser(stream, name) self.parser = parser.Parser(stream, name)
def __setitem__(self, key, val): def __setitem__(self, key, val):

View File

@ -34,11 +34,10 @@ class ExpectedError(Exception):
self.expected = expected self.expected = expected
class Lexer: class Lexer:
pos = ast.Position()
prev_pos = ast.Position()
unread = ''
def __init__(self, stream: typing.TextIO, name: str): def __init__(self, stream: typing.TextIO, name: str):
self.pos = pos = ast.Position()
self.prev_pos = ast.Position()
self.unread = ''
self.stream = stream self.stream = stream
self.pos.name = name self.pos.name = name

View File

@ -15,10 +15,9 @@ class ExpectedError(Exception):
self.expected = expected self.expected = expected
class Parser: class Parser:
_prev: tuple[lexer.Token, ast.Position, str] | None = None
def __init__(self, stream: TextIO, name: str): def __init__(self, stream: TextIO, name: str):
self.lexer = lexer.Lexer(stream, name) self.lexer = lexer.Lexer(stream, name)
self._prev: tuple[lexer.Token, ast.Position, str] | None = None
def _scan(self) -> tuple[lexer.Token, ast.Position, str]: def _scan(self) -> tuple[lexer.Token, ast.Position, str]:
if self._prev is not None: if self._prev is not None: