aboutsummaryrefslogtreecommitdiff
path: root/neb
diff options
context:
space:
mode:
Diffstat (limited to 'neb')
-rw-r--r--neb/exceptions.py4
-rw-r--r--neb/parser.py8
2 files changed, 11 insertions, 1 deletions
diff --git a/neb/exceptions.py b/neb/exceptions.py
index 8bbe000..cc0f915 100644
--- a/neb/exceptions.py
+++ b/neb/exceptions.py
@@ -11,3 +11,7 @@ class InterpretPanic(NebPanic):
class LexError(NebPanic):
def __init__(self, message, line):
super().__init__(f"line {line}: {message}")
+
+class ParseError(NebPanic):
+ def __init__(self, message, line):
+ super().__init__(f"line {line}: {message}")
diff --git a/neb/parser.py b/neb/parser.py
index 5352ee5..08ab0be 100644
--- a/neb/parser.py
+++ b/neb/parser.py
@@ -1,4 +1,6 @@
from .structs import *
+from .exceptions import ParseError
+
def parseExpression(token, prev, tokens):
idx = 0
@@ -6,6 +8,8 @@ def parseExpression(token, prev, tokens):
prev = token
while tokens[idx].type_ != TokenType.CLOSE_PAREN:
token = tokens[idx]
+ if token.type_ == TokenType.EOF:
+ raise ParseError("uneven parens: not enough closing!", token.line)
inc = 1
if token.type_ == TokenType.OPEN_PAREN:
expr, inc = parseExpression(token, prev, tokens[idx+1:])
@@ -49,7 +53,9 @@ def parse(tokens):
while tokens[idx].type_ != TokenType.EOF:
token = tokens[idx]
counter = 1
- if token.type_ == TokenType.OPEN_PAREN:
+ if token.type_ == TokenType.CLOSE_PAREN:
+ raise ParseError("uneven parens: too many closing!", token.line)
+ elif token.type_ == TokenType.OPEN_PAREN:
expr, counter = parseExpression(token, prev, tokens[idx+1:])
exprs.append(expr)
elif token.type_ in (TokenType.FALSE, TokenType.TRUE, TokenType.STRING, TokenType.INT, TokenType.FLOAT):