summaryrefslogtreecommitdiff
path: root/projects/hackc/parser.py
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-29 20:40:35 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-29 20:40:35 +0800
commit7f54baf2668a58f2908f8242b2fbafc65a7f684a (patch)
tree1b5123dba6112c5bcb3cb9967339ca3c5edf9a5a /projects/hackc/parser.py
parent51e1667e716ea8c6b20f37cdec1f99eef55eccd6 (diff)
hackc: exit on invalid token
Diffstat (limited to 'projects/hackc/parser.py')
-rw-r--r--projects/hackc/parser.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/projects/hackc/parser.py b/projects/hackc/parser.py
index c3056d7..400b096 100644
--- a/projects/hackc/parser.py
+++ b/projects/hackc/parser.py
@@ -1,4 +1,5 @@
from .tokens import Token
+from .utils import *
KEYWORDS = [
"class",
@@ -83,3 +84,9 @@ class Parser:
if token is not None:
self.tokens.append(token)
pos += token.length()
+ else:
+ # invalid token
+ print_err(f"{self._fp}:{line_no + 1}")
+ print_err(line)
+ print_err(" " * pos + f"^ Invalid token")
+ exit(EXIT_CODE_INVALID_TOKEN)