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

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

View File

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

View File

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