From 461bfbbdc565b18b9027efe9f0dcaa61026d5b7d Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Wed, 22 Apr 2026 14:09:01 +0200 Subject: [PATCH] :goat: INVOCA error message --- cent | 2 ++ centvrion/parser.py | 8 +++++++- tests.py | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cent b/cent index 594e6a2..8371069 100755 --- a/cent +++ b/cent @@ -42,6 +42,8 @@ def main(): pos = e.source_pos char = program_text[pos.idx] if pos.idx < len(program_text) else "?" sys.exit(f"CENTVRION error: Invalid character {char!r} at line {pos.lineno}, column {pos.colno}") + except SyntaxError as e: + sys.exit(f"CENTVRION error: {e}") if isinstance(program, Program): if args["-i"]: diff --git a/centvrion/parser.py b/centvrion/parser.py index b757ad3..dbc0dfd 100644 --- a/centvrion/parser.py +++ b/centvrion/parser.py @@ -408,7 +408,13 @@ class Parser(): @self.pg.error def error_handle(token): - raise SyntaxError(f"{token.name}, {token.value}, {token.source_pos}") + pos = token.source_pos + loc = f" at line {pos.lineno}, column {pos.colno}" if pos else "" + if token.name == "SYMBOL_LPARENS": + raise SyntaxError( + f"Unexpected '('{loc}. To call a function, use INVOCA: INVOCA func (args)" + ) + raise SyntaxError(f"Unexpected token '{token.value}'{loc}") parser = self.pg.build() return parser.parse(tokens_input) # type: ignore diff --git a/tests.py b/tests.py index b7a7fa1..897a44d 100644 --- a/tests.py +++ b/tests.py @@ -685,6 +685,8 @@ error_tests = [ ("INVOCA f ()", CentvrionError), # undefined function ("DESIGNA VT III", SyntaxError), # parse error: missing id after DESIGNA ("DESIGNA x III", SyntaxError), # parse error: missing VT + ("DEFINI f () VT { REDI(I) }\nf()", SyntaxError), # function call without INVOCA (no args) + ("DEFINI f (x) VT { REDI(x) }\nf(I)", SyntaxError), # function call without INVOCA (with args) ("DIC(M + M + M + M)", CentvrionError), # output > 3999 without MAGNVM ("IIII", CentvrionError), # invalid Roman numeral in source ("FORTVITVS_NVMERVS(I, X)", CentvrionError), # requires FORS module