diff options
| author | jantuomi <jans.tuomi@gmail.com> | 2016-07-28 15:03:25 +0300 |
|---|---|---|
| committer | jantuomi <jans.tuomi@gmail.com> | 2016-07-28 15:03:25 +0300 |
| commit | 4b415805f7b6b0ee7c03e69e1f34898dce554c82 (patch) | |
| tree | b3605833ae1fef359b5edf49946cb124fe3eb4c7 /src/main/com | |
| parent | 0af434b287b7d702ab7fb669c4edccb53ba8e06f (diff) | |
Add line number information to certain errors
Diffstat (limited to 'src/main/com')
| -rw-r--r-- | src/main/com/jantuomi/tunkki/core/parser/ast/SymbolNode.java | 16 | ||||
| -rw-r--r-- | src/main/com/jantuomi/tunkki/exception/TunkkiError.java | 12 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/main/com/jantuomi/tunkki/core/parser/ast/SymbolNode.java b/src/main/com/jantuomi/tunkki/core/parser/ast/SymbolNode.java index 9376206..b4996e4 100644 --- a/src/main/com/jantuomi/tunkki/core/parser/ast/SymbolNode.java +++ b/src/main/com/jantuomi/tunkki/core/parser/ast/SymbolNode.java @@ -51,12 +51,22 @@ public class SymbolNode extends ASTNode { } - DataContainer returnValue = State.getInstance().getSymbolValue(name, paramValues); + + DataContainer returnValue; + try { + returnValue = State.getInstance().getSymbolValue(name, paramValues); + } + /* If a TunkkiError is caught, pass it on with line information */ + catch (TunkkiError ex) { + throw new TunkkiError(ex.getType(), getLine(), + ex.getArguments().toArray(new String[ex.getArguments().size()])); + } + if (returnValue != null) { return returnValue; } else { - ExceptionManager.raise(TunkkiError.ExceptionType.UndeclaredSymbolError, source.getLine(), name, - StringUtils.join(paramValues.stream().map(dataContainer -> dataContainer.toString()).collect(Collectors.toList()), ",")); + ExceptionManager.raise(TunkkiError.ExceptionType.UndeclaredSymbolError, getLine(), name, + StringUtils.join(paramValues.stream().map(DataContainer::toString).collect(Collectors.toList()), ",")); return null; } } diff --git a/src/main/com/jantuomi/tunkki/exception/TunkkiError.java b/src/main/com/jantuomi/tunkki/exception/TunkkiError.java index 5de905d..1ffcad3 100644 --- a/src/main/com/jantuomi/tunkki/exception/TunkkiError.java +++ b/src/main/com/jantuomi/tunkki/exception/TunkkiError.java @@ -1,7 +1,9 @@ package com.jantuomi.tunkki.exception; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -35,10 +37,12 @@ public class TunkkiError extends Exception { private ExceptionType exceptionType; private String completeMessage; + private List<String> arguments; public TunkkiError(ExceptionType exceptionType, int line, String... args) { super(exceptionType.toString(), null, false, false); this.exceptionType = exceptionType; + this.arguments = Arrays.asList(args); this.completeMessage = formatMessage(exceptionType.toString() + ": " + what(exceptionType), line, args); } @@ -60,4 +64,12 @@ public class TunkkiError extends Exception { public void printStackTrace() { System.err.println(completeMessage); } + + public ExceptionType getType() { + return exceptionType; + } + + public List<String> getArguments() { + return this.arguments; + } } |
