From 9e8b77e367b5297293c475d42750dc75ada6ee51 Mon Sep 17 00:00:00 2001 From: Voiris Date: Tue, 17 Feb 2026 22:03:52 +0300 Subject: [PATCH] =?UTF-8?q?fix(parser):=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20EOF=20=D0=BF=D1=80=D0=B8=20=D0=BE=D0=B6?= =?UTF-8?q?=D0=B8=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20=D1=82=D0=BE=D0=BA=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=20`Parser.expect(..)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ранее при проверке ожидаемого токена использовалось условие: ```python if tok and tok.type == token_type: ``` В случае, если tok == None (например, при неожиданном конце файла) исполнялся следующий код: ```python raise SyntaxError(f'Expected {token_type}, got {tok.type}') ``` Из-за того, что tok == None, происходило обращение к артибуту type у None, что приводило к ошибке AttributeError. Это было исправленно путём разделения проверки на None и на совпадения типа токена, а так же добавления ошибки о неожиданном конце файла --- core/parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/parser.py b/core/parser.py index e33062e..f112200 100644 --- a/core/parser.py +++ b/core/parser.py @@ -26,10 +26,14 @@ def advance(self): def expect(self, token_type): tok = self.peek() - if tok and tok.type == token_type: - self.advance() - return tok - raise SyntaxError(f'Expected {token_type}, got {tok.type}') + if tok: + if tok.type == token_type: + self.advance() + return tok + else: + raise SyntaxError(f'Expected {token_type}, got {tok.type}') + else: + raise SyntaxError(f'Unexpected end of file. Expected {token_type}') def parse(self):