summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/dicelang/scl/Errors.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-05-28 13:42:11 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2018-05-28 14:04:31 -0300
commit7ac470c22e9e179daf0a10579a9f9e347cf6f94f (patch)
tree52088fe954f23db0167120b29f0b3ec8b6828d7a /src/main/java/bjc/dicelang/scl/Errors.java
Move SCL into new project
SCL is now independant of dicelang, and thus deserving of its own repo.
Diffstat (limited to 'src/main/java/bjc/dicelang/scl/Errors.java')
-rw-r--r--src/main/java/bjc/dicelang/scl/Errors.java149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/main/java/bjc/dicelang/scl/Errors.java b/src/main/java/bjc/dicelang/scl/Errors.java
new file mode 100644
index 0000000..8d3faff
--- /dev/null
+++ b/src/main/java/bjc/dicelang/scl/Errors.java
@@ -0,0 +1,149 @@
+package bjc.dicelang.scl;
+
+/**
+ * Repository for error messages.
+ *
+ *
+ * @author EVE
+ */
+/*
+ * @TODO 10/08/17 Ben Culkin :ErrorRefactor
+ *
+ * This way of handling error messages is not easy to deal with. Something else
+ * needs to be done, but I'm not sure what at the moment.
+ *
+ *
+ */
+public class Errors {
+ /**
+ * The types of error message.
+ *
+ * @author EVE
+ *
+ */
+ public static enum ErrorKey {
+ /* Stream Errors */
+ /**
+ * Attempted to switch to a non-existant stream
+ */
+ EK_STRM_NONEX,
+ /**
+ * Can't delete the last stream
+ */
+ EK_STRM_LAST,
+ /**
+ * Unknown stream command
+ */
+ EK_STRM_INVCOM,
+ /* SCL Errors */
+ /**
+ * Unknown SCL token
+ */
+ EK_SCL_INVTOKEN,
+ /**
+ * Mismatched quote in SCL command
+ */
+ EK_SCL_MMQUOTE,
+ /**
+ * Stack underflow in SCL command
+ */
+ EK_SCL_SUNDERFLOW,
+ /**
+ * Unknown word in SCL command
+ */
+ EK_SCL_UNWORD,
+ /**
+ * Invalid argument to SCL command
+ */
+ EK_SCL_INVARG,
+ }
+
+ /**
+ * The mode for the type of error messages to print out.
+ *
+ * @author EVE
+ *
+ */
+ public static enum ErrorMode {
+ /**
+ * Output error messages for wizards.
+ */
+ WIZARD,
+ /**
+ * Output error messages for developers.
+ */
+ DEV
+ }
+
+ private ErrorMode mode;
+
+ /**
+ * Print an error.
+ *
+ * @param key
+ * The key of the error.
+ *
+ * @param args
+ * The arguments for the error.
+ */
+ public void printError(final ErrorKey key, final String... args) {
+ switch(mode) {
+ case WIZARD:
+ System.out.println("\t? " + key.ordinal());
+ break;
+
+ case DEV:
+ devError(key, args);
+ break;
+
+ default:
+ System.out.println("\tERROR ERROR: Unknown error mode " + mode);
+ }
+ }
+
+ private static void devError(final ErrorKey key, final String[] args) {
+ switch(key) {
+ case EK_STRM_NONEX:
+ System.out.printf("\tERROR: Attempted to switch to non-existent stream\n");
+ break;
+
+ case EK_STRM_LAST:
+ System.out.printf("\tERROR: Cannot delete last stream\n");
+ break;
+
+ case EK_STRM_INVCOM:
+ System.out.printf("\tERROR: Unknown stream control command %s\n", args[0]);
+ break;
+
+ case EK_SCL_INVTOKEN:
+ System.out.printf("\tERROR: Unknown SCL token %s\n", args[0]);
+ break;
+
+ case EK_SCL_MMQUOTE:
+ System.out.printf("\tERROR: Mismatched delimiter in SCL command\n");
+ break;
+
+ case EK_SCL_SUNDERFLOW:
+ System.out.printf("\tERROR: Not enough items in stack for word %s\n", args[0]);
+ break;
+
+ case EK_SCL_UNWORD:
+ System.out.printf("\tERROR: Unknown word %s\n", args[0]);
+ break;
+
+ default:
+ System.out.printf("\tERROR ERROR: Unknown error key %s\n", key);
+ }
+ }
+
+ /**
+ * The instance of the errors.
+ */
+ public final static Errors inst;
+
+ static {
+ inst = new Errors();
+
+ inst.mode = ErrorMode.DEV;
+ }
+}