diff options
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; |
