diff options
| author | 2024-02-24 13:04:40 +0800 | |
|---|---|---|
| committer | 2024-02-24 13:04:40 +0800 | |
| commit | 57b2835ecc6c9b30920e929985b9d7cafcb7c457 (patch) | |
| tree | df0c1221d4766365c231e8bd02e6d8e7bdb63420 /nivis-python/parsers.py | |
| parent | 45e2f3631bc8d13dacba57e705c7591e7e707b2a (diff) | |
| download | TRPGNivis-57b2835ecc6c9b30920e929985b9d7cafcb7c457.tar.gz TRPGNivis-57b2835ecc6c9b30920e929985b9d7cafcb7c457.zip | |
chore(project): add ruff deps
chore(lint): format code with ruff
chore(project): add tool.ruff format section
Diffstat (limited to 'nivis-python/parsers.py')
| -rw-r--r-- | nivis-python/parsers.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/nivis-python/parsers.py b/nivis-python/parsers.py index f68f95f..08c3a2c 100644 --- a/nivis-python/parsers.py +++ b/nivis-python/parsers.py @@ -1,7 +1,8 @@ from psi.lexer import Lexer, Token -__all__ = ['Parser'] +__all__ = ["Parser"] + class Parser: """ @@ -51,12 +52,12 @@ class Parser: The result of the parsing. """ token = self.current_token - if token.value == '?': - self.eat('?') + if token.value == "?": + self.eat("?") condition = self.parse_condition() - self.eat(':') + self.eat(":") if condition: result = self.parse_reply() @@ -73,7 +74,7 @@ class Parser: The result of the parsing. """ variable = self.parse_variable() - self.eat('==') + self.eat("==") value = self.parse_value() return variable == value @@ -86,7 +87,7 @@ class Parser: The result of the parsing. """ token = self.current_token - self.eat('IDENTIFIER') + self.eat("IDENTIFIER") return token.value def parse_value(self): @@ -100,11 +101,11 @@ class Parser: Exception: Raised when an invalid value is encountered. """ token = self.current_token - if token.type == 'INTEGER': - self.eat('INTEGER') + if token.type == "INTEGER": + self.eat("INTEGER") return token.value else: - raise Exception(f'Invalid value: {token.value}') + raise Exception(f"Invalid value: {token.value}") def parse_reply(self): """ @@ -116,12 +117,12 @@ class Parser: Raises: Exception: Raised when an invalid reply is encountered. """ - self.eat('reply') - self.eat(':') + self.eat("reply") + self.eat(":") token = self.current_token - if token.type != 'SEPARATOR': - raise Exception(f'Invalid reply: {token.value}') + if token.type != "SEPARATOR": + raise Exception(f"Invalid reply: {token.value}") return token.value @@ -141,4 +142,4 @@ class Parser: if self.current_token.type == expected_type: self.current_token = next(self.tokens) else: - raise Exception(f'Unexpected token: {self.current_token.value}') + raise Exception(f"Unexpected token: {self.current_token.value}") |
