diff options
| author | EVE <EVE@EVE-PC> | 2017-03-13 16:41:45 -0400 |
|---|---|---|
| committer | EVE <EVE@EVE-PC> | 2017-03-13 16:41:45 -0400 |
| commit | 01136c6796e21f023713e026674576d8e623462d (patch) | |
| tree | e77886fe0e0adaf3c0430fba9ce248ef83f74fe4 /dice-lang/src/bjc/dicelang/DiceLangConsole.java | |
| parent | 870d769cfc152171d27b2331a7c590d0b307ad48 (diff) | |
Formatting
Diffstat (limited to 'dice-lang/src/bjc/dicelang/DiceLangConsole.java')
| -rw-r--r-- | dice-lang/src/bjc/dicelang/DiceLangConsole.java | 219 |
1 files changed, 110 insertions, 109 deletions
diff --git a/dice-lang/src/bjc/dicelang/DiceLangConsole.java b/dice-lang/src/bjc/dicelang/DiceLangConsole.java index ff6fe45..1b91746 100644 --- a/dice-lang/src/bjc/dicelang/DiceLangConsole.java +++ b/dice-lang/src/bjc/dicelang/DiceLangConsole.java @@ -23,7 +23,8 @@ public class DiceLangConsole { eng = new DiceLangEngine(); - if(!CLIArgsParser.parseArgs(args, eng)) System.exit(1); + if (!CLIArgsParser.parseArgs(args, eng)) + System.exit(1); Terminal.setupTerminal(); } @@ -31,7 +32,7 @@ public class DiceLangConsole { public void run() { try { read = new ConsoleReader(); - } catch(IOException ioex) { + } catch (IOException ioex) { System.out.println("ERROR: Console init failed"); return; } @@ -47,19 +48,23 @@ public class DiceLangConsole { return; } - while(!comm.equals("quit") && !comm.equals("exit")) { - if(comm.startsWith("pragma")) { + while (!comm.equals("quit") && !comm.equals("exit")) { + if (comm.startsWith("pragma")) { boolean success = handlePragma(comm.substring(7)); - if(success) System.out.println("Pragma completed succesfully"); - else System.out.println("Pragma execution failed"); + if (success) + System.out.println("Pragma completed succesfully"); + else + System.out.println("Pragma execution failed"); } else { System.out.printf("\tRaw command: %s\n", comm); boolean success = eng.runCommand(comm); - if(success) System.out.println("Command completed succesfully"); - else System.out.println("Command execution failed"); + if (success) + System.out.println("Command completed succesfully"); + else + System.out.println("Command execution failed"); commandNumber += 1; } @@ -78,60 +83,60 @@ public class DiceLangConsole { String pragmaName = null; int firstIndex = pragma.indexOf(' '); - if(firstIndex == -1) { + if (firstIndex == -1) { pragmaName = pragma; } else { pragmaName = pragma.substring(0, firstIndex); } - 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; + 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; } return true; } - + private boolean helpMode(String pragma) { - 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); + 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 @@ -139,43 +144,41 @@ public class DiceLangConsole { } /* - * Matches slash-delimited strings - * (like /text/ or /text\/text/) - * Uses the "normal* (special normal*)*" pattern style - * recommended in 'Mastering regular expressions' - * Here, the normal is 'anything but a forward or backslash' - * (in regex, thats '[^/\\]') and the special is 'an escaped forward slash' - * (in regex, thats '\\\\/') + * Matches slash-delimited strings (like /text/ or /text\/text/) Uses + * the "normal* (special normal*)*" pattern style recommended in + * 'Mastering regular expressions' Here, the normal is 'anything but a + * forward or backslash' (in regex, thats '[^/\\]') and the special is + * 'an escaped forward slash' (in regex, thats '\\\\/') * - * Then, we just follow the pattern, escape it for java strings, and - * add the enclosing slashes + * Then, we just follow the pattern, escape it for java strings, and add + * the enclosing slashes */ private Pattern slashPattern = Pattern.compile("/((?:\\\\.|[^/\\\\])*)/"); private boolean defineMode(String defineText) { - int firstIndex = defineText.indexOf(' '); - int secondIndex = defineText.indexOf(' ', firstIndex + 1); - int thirdIndex = defineText.indexOf(' ', secondIndex + 1); - int fourthIndex = defineText.indexOf(' ', thirdIndex + 1); - int fifthIndex = defineText.indexOf(' ', fourthIndex + 1); - int sixthIndex = defineText.indexOf(' ', fifthIndex + 1); - - if(firstIndex == -1) { + int firstIndex = defineText.indexOf(' '); + int secondIndex = defineText.indexOf(' ', firstIndex + 1); + int thirdIndex = defineText.indexOf(' ', secondIndex + 1); + int fourthIndex = defineText.indexOf(' ', thirdIndex + 1); + int fifthIndex = defineText.indexOf(' ', fourthIndex + 1); + int sixthIndex = defineText.indexOf(' ', fifthIndex + 1); + + if (firstIndex == -1) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no priority)"); return false; - } else if(secondIndex == -1) { + } else if (secondIndex == -1) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no define type)"); return false; - } else if(thirdIndex == -1) { + } else if (thirdIndex == -1) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no recursion type)"); return false; - } else if(fourthIndex == -1) { + } else if (fourthIndex == -1) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no guard type)"); return false; - } else if(fifthIndex == -1) { + } else if (fifthIndex == -1) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no circularity)"); return false; - } else if(sixthIndex == -1) { + } else if (sixthIndex == -1) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no patterns)"); return false; } @@ -185,42 +188,39 @@ public class DiceLangConsole { String defineType = defineText.substring(firstIndex + 1, secondIndex); Define.Type type; - boolean subMode = false; - - 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; + boolean subMode = false; + + 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; } - boolean doRecur = defineText.substring(secondIndex + 1, thirdIndex) - .equalsIgnoreCase("true"); - boolean hasGuard = defineText.substring(thirdIndex + 1, fourthIndex) - .equalsIgnoreCase("true"); - boolean isCircular = defineText.substring(thirdIndex + 1, fourthIndex) - .equalsIgnoreCase("true"); + boolean doRecur = defineText.substring(secondIndex + 1, thirdIndex).equalsIgnoreCase("true"); + boolean hasGuard = defineText.substring(thirdIndex + 1, fourthIndex).equalsIgnoreCase("true"); + boolean isCircular = defineText.substring(thirdIndex + 1, fourthIndex).equalsIgnoreCase("true"); String pats = defineText.substring(fifthIndex + 1).trim(); Matcher patMatcher = slashPattern.matcher(pats); String guardPattern = null; - if(hasGuard) { - if(!patMatcher.find()) { + if (hasGuard) { + if (!patMatcher.find()) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no guard pattern)"); return false; } @@ -228,7 +228,7 @@ public class DiceLangConsole { guardPattern = patMatcher.group(1); } - if(!patMatcher.find()) { + if (!patMatcher.find()) { Errors.inst.printError(EK_CONS_INVDEFINE, "(no search pattern)"); return false; } @@ -236,16 +236,17 @@ public class DiceLangConsole { String searchPattern = patMatcher.group(1); List<String> replacePatterns = new LinkedList<>(); - while(patMatcher.find()) { + while (patMatcher.find()) { replacePatterns.add(patMatcher.group(1)); } - Define dfn = new Define(priority, subMode, doRecur, isCircular, - guardPattern, searchPattern, replacePatterns); - - if(dfn.inError) return false; + Define dfn = new Define(priority, subMode, doRecur, isCircular, guardPattern, searchPattern, + replacePatterns); + + if (dfn.inError) + return false; - if(type == Define.Type.LINE) { + if (type == Define.Type.LINE) { eng.addLineDefine(dfn); } else { eng.addTokenDefine(dfn); |
