From fbd62512d184a592b4348c9e66f6f8c27c0c0e21 Mon Sep 17 00:00:00 2001 From: Elara6331 Date: Mon, 11 Nov 2024 14:55:02 -0800 Subject: [PATCH] Fix issue where position was retained across Lexer instances --- hisscl/interp.py | 5 ++--- hisscl/lexer.py | 7 +++---- hisscl/parser.py | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/hisscl/interp.py b/hisscl/interp.py index 2bb4636..ceed11b 100644 --- a/hisscl/interp.py +++ b/hisscl/interp.py @@ -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): diff --git a/hisscl/lexer.py b/hisscl/lexer.py index e46d851..8d32dea 100644 --- a/hisscl/lexer.py +++ b/hisscl/lexer.py @@ -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 diff --git a/hisscl/parser.py b/hisscl/parser.py index bedda17..cd5fa4f 100644 --- a/hisscl/parser.py +++ b/hisscl/parser.py @@ -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: