summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/DiceLangConsole.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-09 16:02:10 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-09 16:02:10 -0300
commitf028ea6dc555fc5192a96b00b8e96e90dbf6de55 (patch)
tree4b2a28ecbeb30095b50e6e9e8ac8b98fa8ddc79e /dice-lang/src/bjc/dicelang/DiceLangConsole.java
parentbe4675f9512060aa85b1e0a4f223208b51b55812 (diff)
TODO tagging
Diffstat (limited to 'dice-lang/src/bjc/dicelang/DiceLangConsole.java')
-rw-r--r--dice-lang/src/bjc/dicelang/DiceLangConsole.java44
1 files changed, 23 insertions, 21 deletions
diff --git a/dice-lang/src/bjc/dicelang/DiceLangConsole.java b/dice-lang/src/bjc/dicelang/DiceLangConsole.java
index ebf9b59..296874f 100644
--- a/dice-lang/src/bjc/dicelang/DiceLangConsole.java
+++ b/dice-lang/src/bjc/dicelang/DiceLangConsole.java
@@ -43,9 +43,7 @@ public class DiceLangConsole {
Terminal.setupTerminal();
}
- /**
- * Run the console.
- */
+ /** Run the console. */
public void run() {
/* Set up console. */
try {
@@ -55,6 +53,7 @@ public class DiceLangConsole {
return;
}
+ /* Print greeting. */
System.out.println("dice-lang v0.2");
String comm = null;
@@ -67,6 +66,10 @@ public class DiceLangConsole {
}
/* Run commands. */
+ /* @NOTE
+ * Should switch this to a do-while loop to reduce code
+ * duplication.
+ */
while (!comm.equals("quit") && !comm.equals("exit")) {
if (comm.startsWith("pragma")) {
/* Run pragmas. */
@@ -94,6 +97,7 @@ public class DiceLangConsole {
commandNumber += 1;
}
+ /* Read the next command. */
try {
comm = read.readLine(String.format("(%d) dice-lang> ", commandNumber));
} catch (final IOException ioex) {
@@ -103,6 +107,7 @@ public class DiceLangConsole {
}
}
+ /* Handle running pragmas. */
private boolean handlePragma(final String pragma) {
if (eng.debugMode) {
System.out.println("\tRaw pragma: " + pragma);
@@ -119,32 +124,29 @@ public class DiceLangConsole {
pragmaName = pragma.substring(0, firstIndex);
}
+ /* Run pragmas. */
/*
- * Run pragmas.
+ * @TODO 10/09/17 Ben Culkin :PragmaRefactor
+ * Swap to using something that makes it easier to add
+ * pragmas.
*/
switch (pragmaName) {
case "debug":
System.out.println("\tDebug mode is now " + eng.toggleDebug());
break;
-
case "postfix":
System.out.println("\tPostfix mode is now " + eng.togglePostfix());
break;
-
case "prefix":
System.out.println("\tPrefix mode is now " + eng.togglePrefix());
break;
-
case "stepeval":
System.out.println("\tStepeval mode is now" + eng.toggleStepEval());
break;
-
case "define":
return defineMode(pragma.substring(7));
-
case "help":
return helpMode(pragma.substring(5));
-
default:
Errors.inst.printError(EK_CONS_INVPRAG, pragma);
return false;
@@ -155,36 +157,30 @@ public class DiceLangConsole {
/* Run a help mode. */
private static boolean helpMode(final String pragma) {
+ /* Get the help topic. */
switch (pragma.trim()) {
case "help":
System.out.println("\tGet help on pragmas");
break;
-
case "debug":
System.out.println("\tToggle debug mode. (Output stage results)");
break;
-
case "postfix":
System.out.println("\tToggle postfix mode. (Don't shunt tokens)");
break;
-
case "prefix":
System.out.println("\tToggle prefix mode. (Reverse token order instead of shunting)");
break;
-
case "stepeval":
System.out.println("\tToggle stepeval mode. (Print out evaluation progress)");
break;
-
case "define":
System.out.println("\tAdd a macro rewrite directive.");
System.out.println("\tdefine <priority> <type> <recursion> <guard> <circular> <patterns>...");
break;
-
default:
System.out.println("\tNo help available for pragma " + pragma);
}
-
/* Help always works */
return true;
}
@@ -226,48 +222,51 @@ public class DiceLangConsole {
return false;
}
+ /* Get the priority and define type. */
final int priority = Integer.parseInt(defineText.substring(0, firstIndex));
final String defineType = defineText.substring(firstIndex + 1, secondIndex);
Define.Type type;
boolean subMode = false;
+ /* Parse the define type. */
switch (defineType) {
case "line":
type = Define.Type.LINE;
break;
-
case "token":
type = Define.Type.TOKEN;
break;
-
case "subline":
type = Define.Type.LINE;
subMode = true;
break;
-
case "subtoken":
type = Define.Type.TOKEN;
subMode = true;
break;
-
default:
Errors.inst.printError(EK_CONS_INVDEFINE, "(unknown type)");
return false;
}
+ /* Do we want this to be a recursive pattern? */
final boolean doRecur = defineText.substring(secondIndex + 1, thirdIndex)
.equalsIgnoreCase("true");
+ /* Do we want this pattern to have a guard? */
final boolean hasGuard = defineText.substring(thirdIndex + 1, fourthIndex)
.equalsIgnoreCase("true");
+ /* Do we want this pattern to use circular replacements. */
final boolean isCircular = defineText.substring(thirdIndex + 1, fourthIndex)
.equalsIgnoreCase("true");
+ /* The part of the string that contains patterns. */
final String pats = defineText.substring(fifthIndex + 1).trim();
final Matcher patMatcher = slashPattern.matcher(pats);
String guardPattern = null;
if (hasGuard) {
+ /* Grab the guard pattern. */
if (!patMatcher.find()) {
Errors.inst.printError(EK_CONS_INVDEFINE, "(no guard pattern)");
return false;
@@ -277,6 +276,7 @@ public class DiceLangConsole {
}
if (!patMatcher.find()) {
+ /* Grab the search pattern. */
Errors.inst.printError(EK_CONS_INVDEFINE, "(no search pattern)");
return false;
}
@@ -285,6 +285,7 @@ public class DiceLangConsole {
final List<String> replacePatterns = new LinkedList<>();
while (patMatcher.find()) {
+ /* Grab the replacer patterns. */
replacePatterns.add(patMatcher.group(1));
}
@@ -296,6 +297,7 @@ public class DiceLangConsole {
return false;
}
+ /* Add the define to the proper place. */
if (type == Define.Type.LINE) {
eng.addLineDefine(dfn);
} else {