scarpet v1.2
This commit is contained in:
1 parent
723f863d98
commit
885f579d6c
34 files changed
+8786
-18
No files matched your search
@@ -0,0 +1,9 @@
|
||||
package carpet.script.exception;
|
||||
|
||||
public class CarpetExpressionException extends ExpressionException
|
||||
{
|
||||
public CarpetExpressionException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package carpet.script.exception;
|
||||
|
||||
import carpet.script.Expression;
|
||||
import carpet.script.Fluff;
|
||||
import carpet.script.Tokenizer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static carpet.script.ExpressionInspector.Expression_getExpressionSnippet;
|
||||
import static carpet.script.ExpressionInspector.Expression_getName;
|
||||
|
||||
/* The expression evaluators exception class. */
|
||||
public class ExpressionException extends RuntimeException
|
||||
{
|
||||
public ExpressionException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
private static Fluff.TriFunction<Expression, Tokenizer.Token, String, List<String>> errorMaker = (expr, token, errmessage) ->
|
||||
{
|
||||
|
||||
List<String> snippet = Expression_getExpressionSnippet(token, expr);
|
||||
List<String> errMsg = new ArrayList<>(snippet);
|
||||
if (snippet.size() != 1)
|
||||
{
|
||||
errmessage+= " at line "+(token.lineno+1)+", pos "+(token.linepos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
errmessage += " at pos "+(token.pos+1);
|
||||
}
|
||||
if (Expression_getName(expr) != null)
|
||||
{
|
||||
errmessage += " ("+Expression_getName(expr)+")";
|
||||
}
|
||||
errMsg.add(errmessage);
|
||||
return errMsg;
|
||||
};
|
||||
public static Fluff.TriFunction<Expression, Tokenizer.Token, String, List<String>> errorSnooper = null;
|
||||
|
||||
static String makeMessage(Expression e, Tokenizer.Token t, String message) throws ExpressionException
|
||||
{
|
||||
if (errorSnooper != null)
|
||||
{
|
||||
List<String> alternative = errorSnooper.apply(e, t, message);
|
||||
if (alternative!= null)
|
||||
{
|
||||
return String.join("\n", alternative);
|
||||
}
|
||||
}
|
||||
return String.join("\n", errorMaker.apply(e, t, message));
|
||||
}
|
||||
|
||||
public ExpressionException(Expression e, Tokenizer.Token t, String message)
|
||||
{
|
||||
super(makeMessage(e, t, message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package carpet.script.exception;
|
||||
|
||||
/* The internal expression evaluators exception class. */
|
||||
public class InternalExpressionException extends ExpressionException
|
||||
{
|
||||
public InternalExpressionException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user