summaryrefslogtreecommitdiff
path: root/projects/hackc/parser.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-31 17:08:38 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-31 17:08:38 +0800
commit1328887bb78ba034fe3d496ad8029382c1ec678e (patch)
treef3b47fc3abaf9094184deacee3cae47317a2f0bd /projects/hackc/parser.py
parent482eed0ae339e977a618c4ab60525596426cf967 (diff)
hackc: Parser handles IndexError
Diffstat (limited to 'projects/hackc/parser.py')
-rw-r--r--projects/hackc/parser.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/projects/hackc/parser.py b/projects/hackc/parser.py
index 8375d52..188bddc 100644
--- a/projects/hackc/parser.py
+++ b/projects/hackc/parser.py
@@ -102,3 +102,9 @@ class Parser:
print_err(self.lines[err.token.line_no])
print_err(" " * err.token.column + "^ " + err.message)
exit(EXIT_CODE_SYNTAX_ERROR)
+ except IndexError:
+ last_line = self.lines[-1]
+ print_err(f"{self._fp}:{len(self.lines)}")
+ print_err(last_line)
+ print_err(" " * len(last_line) + "^ Unexpected EOF")
+ exit(EXIT_CODE_EOF)