🐐 INVOCA error message
This commit is contained in:
2
cent
2
cent
@@ -42,6 +42,8 @@ def main():
|
|||||||
pos = e.source_pos
|
pos = e.source_pos
|
||||||
char = program_text[pos.idx] if pos.idx < len(program_text) else "?"
|
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}")
|
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 isinstance(program, Program):
|
||||||
if args["-i"]:
|
if args["-i"]:
|
||||||
|
|||||||
@@ -408,7 +408,13 @@ class Parser():
|
|||||||
|
|
||||||
@self.pg.error
|
@self.pg.error
|
||||||
def error_handle(token):
|
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()
|
parser = self.pg.build()
|
||||||
return parser.parse(tokens_input) # type: ignore
|
return parser.parse(tokens_input) # type: ignore
|
||||||
|
|||||||
2
tests.py
2
tests.py
@@ -685,6 +685,8 @@ error_tests = [
|
|||||||
("INVOCA f ()", CentvrionError), # undefined function
|
("INVOCA f ()", CentvrionError), # undefined function
|
||||||
("DESIGNA VT III", SyntaxError), # parse error: missing id after DESIGNA
|
("DESIGNA VT III", SyntaxError), # parse error: missing id after DESIGNA
|
||||||
("DESIGNA x III", SyntaxError), # parse error: missing VT
|
("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
|
("DIC(M + M + M + M)", CentvrionError), # output > 3999 without MAGNVM
|
||||||
("IIII", CentvrionError), # invalid Roman numeral in source
|
("IIII", CentvrionError), # invalid Roman numeral in source
|
||||||
("FORTVITVS_NVMERVS(I, X)", CentvrionError), # requires FORS module
|
("FORTVITVS_NVMERVS(I, X)", CentvrionError), # requires FORS module
|
||||||
|
|||||||
Reference in New Issue
Block a user