aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/com
diff options
context:
space:
mode:
authorjantuomi <jans.tuomi@gmail.com>2016-08-08 14:12:38 +0300
committerjantuomi <jans.tuomi@gmail.com>2016-08-08 14:12:38 +0300
commitb4469f872286f8563ec805ef32798bb9608c29e4 (patch)
tree860928b4ad8ac59183662d3fb866a6408167403d /src/main/com
parent9bfa39305ba8611d2f41e2db7c278edfe6b21257 (diff)
Add MissingTerminatorTokenError
If the token stack doesn't have a terminator token for all variable argument tokens, throw an error.
Diffstat (limited to 'src/main/com')
-rw-r--r--src/main/com/jantuomi/tunkki/core/parser/Parser.java14
-rw-r--r--src/main/com/jantuomi/tunkki/exception/types/MissingTerminatorTokenTunkkiError.java20
-rw-r--r--src/main/com/jantuomi/tunkki/exception/types/TunkkiError.java6
3 files changed, 33 insertions, 7 deletions
diff --git a/src/main/com/jantuomi/tunkki/core/parser/Parser.java b/src/main/com/jantuomi/tunkki/core/parser/Parser.java
index dfcf685..9cb183f 100644
--- a/src/main/com/jantuomi/tunkki/core/parser/Parser.java
+++ b/src/main/com/jantuomi/tunkki/core/parser/Parser.java
@@ -3,8 +3,8 @@ package com.jantuomi.tunkki.core.parser;
import com.jantuomi.tunkki.core.parser.ast.ASTNode;
import com.jantuomi.tunkki.core.parser.tokenizer.token.ArgumentInfo;
import com.jantuomi.tunkki.core.parser.tokenizer.token.Token;
-import com.jantuomi.tunkki.exception.ExceptionManager;
import com.jantuomi.tunkki.exception.types.ExpectedDifferentTokenTunkkiError;
+import com.jantuomi.tunkki.exception.types.MissingTerminatorTokenTunkkiError;
import com.jantuomi.tunkki.exception.types.TunkkiError;
import java.util.ArrayList;
@@ -51,16 +51,18 @@ public class Parser {
This branch is executed if the token has a variable list of arguments
*/
if (argumentInfo.getVarargs()) {
+ boolean foundTerminatorToken = false;
while (stack.size() > 0) {
Token arg = stack.pop();
- if (arg.getTokenType() != argumentInfo.getTerminator()) {
- args.add(arg);
- }
- else {
- args.add(arg);
+ args.add(arg);
+ if (arg.getTokenType() == argumentInfo.getTerminator()) {
+ foundTerminatorToken = true;
break;
}
}
+ if (!foundTerminatorToken) {
+ throw new MissingTerminatorTokenTunkkiError(t.getLine(), t.getText());
+ }
}
/*
If the token has an optional argument type (it is only an argument if
diff --git a/src/main/com/jantuomi/tunkki/exception/types/MissingTerminatorTokenTunkkiError.java b/src/main/com/jantuomi/tunkki/exception/types/MissingTerminatorTokenTunkkiError.java
new file mode 100644
index 0000000..91f862d
--- /dev/null
+++ b/src/main/com/jantuomi/tunkki/exception/types/MissingTerminatorTokenTunkkiError.java
@@ -0,0 +1,20 @@
+package com.jantuomi.tunkki.exception.types;
+
+/**
+ * Created by jan on 8.8.2016.
+ */
+public class MissingTerminatorTokenTunkkiError extends TunkkiError {
+ public MissingTerminatorTokenTunkkiError(int line, String... args) {
+ super(line, args);
+ }
+
+ @Override
+ public String what() {
+ return "Expected terminator token for token %s.";
+ }
+
+ @Override
+ ExceptionType getType() {
+ return ExceptionType.MissingTerminatorTokenError;
+ }
+}
diff --git a/src/main/com/jantuomi/tunkki/exception/types/TunkkiError.java b/src/main/com/jantuomi/tunkki/exception/types/TunkkiError.java
index 023c8a5..dfef1cf 100644
--- a/src/main/com/jantuomi/tunkki/exception/types/TunkkiError.java
+++ b/src/main/com/jantuomi/tunkki/exception/types/TunkkiError.java
@@ -23,7 +23,11 @@ abstract public class TunkkiError extends Exception {
CastError,
DivisionByZeroError,
RecursiveIncludeError,
- OutOfBoundsError, FileNotFoundError, NotAnObjectError, NadaError
+ OutOfBoundsError,
+ FileNotFoundError,
+ NotAnObjectError,
+ MissingTerminatorTokenError,
+ NadaError
}
private int line;