summaryrefslogtreecommitdiff
path: root/base/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main')
-rw-r--r--base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java1
-rw-r--r--base/src/main/java/bjc/utils/cli/objects/DefineCLI.java32
-rw-r--r--base/src/main/java/bjc/utils/esodata/SingleTape.java3
-rw-r--r--base/src/main/java/bjc/utils/graph/AdjacencyMap.java2
-rw-r--r--base/src/main/java/bjc/utils/graph/Graph.java2
-rw-r--r--base/src/main/java/bjc/utils/ioutils/CLFormatter.java420
-rw-r--r--base/src/main/java/bjc/utils/ioutils/CLParameters.java41
-rw-r--r--base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java1
-rw-r--r--base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java1
-rw-r--r--base/src/main/java/bjc/utils/parserutils/StringDescaper.java17
-rw-r--r--base/src/main/java/bjc/utils/parserutils/TokenUtils.java2
11 files changed, 270 insertions, 252 deletions
diff --git a/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java b/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java
index 2edea08..94ee726 100644
--- a/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java
+++ b/base/src/main/java/bjc/utils/cli/objects/BlockReaderCLI.java
@@ -12,7 +12,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import bjc.utils.ioutils.Prompter;
import bjc.utils.ioutils.blocks.*;
import static bjc.utils.cli.objects.Command.CommandStatus;
diff --git a/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java b/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java
index 5763a83..280afd0 100644
--- a/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java
+++ b/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java
@@ -35,9 +35,8 @@ public class DefineCLI {
this(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
}
- public DefineState(Map<String, UnaryOperator<String>> defines,
- Map<String, String> strings, Map<String, String> formats,
- Map<String, Pattern> patterns) {
+ public DefineState(Map<String, UnaryOperator<String>> defines, Map<String, String> strings,
+ Map<String, String> formats, Map<String, Pattern> patterns) {
this.defines = defines;
this.strings = strings;
@@ -55,22 +54,26 @@ public class DefineCLI {
public static void main(String[] args) {
DefineCLI defin = new DefineCLI();
+
+ try (Scanner scn = new Scanner(System.in)) {
+ defin.run(scn, "console", true);
+ }
}
/**
* Run the CLI on an input source.
*
* @param input
- * The place to read input from.
+ * The place to read input from.
* @param ioSource
- * The name of the place to read input from.
+ * The name of the place to read input from.
* @param interactive
- * Whether or not the source is interactive
+ * Whether or not the source is interactive
*/
public void run(Scanner input, String ioSource, boolean interactive) {
int lno = 0;
- while(input.hasNextLine()) {
- if(interactive)
+ while (input.hasNextLine()) {
+ if (interactive)
System.out.printf("define-conf(%d)>", lno);
String ln = input.nextLine();
@@ -78,7 +81,8 @@ public class DefineCLI {
lno += 1;
Command com = Command.fromString(ln, lno, ioSource);
- if(com == null) continue;
+ if (com == null)
+ continue;
handleCommand(com, interactive);
}
@@ -87,7 +91,7 @@ public class DefineCLI {
}
public void handleCommand(Command com, boolean interactive) {
- switch(com.nameCommand) {
+ switch (com.nameCommand) {
case "def-string":
default:
LOGGER.severe(com.error("Unknown command %s\n", com.nameCommand));
@@ -99,14 +103,14 @@ public class DefineCLI {
String remn = com.remnCommand;
int idx = remn.indexOf(' ');
- if(idx == -1) {
+ if (idx == -1) {
LOGGER.warning(com.warn("Binding empty string to name '%s'\n", remn));
idx = remn.length();
}
String name = remn.substring(0, idx);
String strang = remn.substring(idx);
- if(stat.strings.containsKey(name)) {
+ if (stat.strings.containsKey(name)) {
LOGGER.warning(com.warn("Shadowing string '%s'\n", name));
}
@@ -119,14 +123,14 @@ public class DefineCLI {
String remn = com.remnCommand;
int idx = remn.indexOf(' ');
- if(idx == -1) {
+ if (idx == -1) {
LOGGER.warning(com.warn("Binding empty format to name '%s'\n", remn));
idx = remn.length();
}
String name = remn.substring(0, idx);
String fmt = remn.substring(idx);
- if(stat.formats.containsKey(name)) {
+ if (stat.formats.containsKey(name)) {
LOGGER.warning(com.warn("Shadowing format '%s'\n", name));
}
diff --git a/base/src/main/java/bjc/utils/esodata/SingleTape.java b/base/src/main/java/bjc/utils/esodata/SingleTape.java
index c7bf6ee..ae9b746 100644
--- a/base/src/main/java/bjc/utils/esodata/SingleTape.java
+++ b/base/src/main/java/bjc/utils/esodata/SingleTape.java
@@ -36,10 +36,11 @@ public class SingleTape<T> implements Tape<T> {
* Create a new tape with the specified contents that doesn't
* autoextend.
*/
+ @SafeVarargs
public SingleTape(T... vals) {
autoExtend = false;
- backing = new ArrayList(vals.length);
+ backing = new ArrayList<>(vals.length);
for(T val : vals) {
backing.add(val);
diff --git a/base/src/main/java/bjc/utils/graph/AdjacencyMap.java b/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
index 58ce107..1598b25 100644
--- a/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
+++ b/base/src/main/java/bjc/utils/graph/AdjacencyMap.java
@@ -100,7 +100,7 @@ public class AdjacencyMap<T> {
} catch (final NumberFormatException nfex) {
String msg = String.format("%d is not a valid weight.", part);
- final InputMismatchException imex = new InputMismatchException();
+ final InputMismatchException imex = new InputMismatchException(msg);
imex.initCause(nfex);
throw imex;
diff --git a/base/src/main/java/bjc/utils/graph/Graph.java b/base/src/main/java/bjc/utils/graph/Graph.java
index 3e03919..d00dbae 100644
--- a/base/src/main/java/bjc/utils/graph/Graph.java
+++ b/base/src/main/java/bjc/utils/graph/Graph.java
@@ -260,7 +260,7 @@ public class Graph<T> {
if (!backing.containsKey(target)) {
String msg = String.format("vertex %s does not exist", target);
- throw new NoSuchElementException();
+ throw new NoSuchElementException(msg);
}
backing.get(source).remove(target);
diff --git a/base/src/main/java/bjc/utils/ioutils/CLFormatter.java b/base/src/main/java/bjc/utils/ioutils/CLFormatter.java
index eefd532..1f65607 100644
--- a/base/src/main/java/bjc/utils/ioutils/CLFormatter.java
+++ b/base/src/main/java/bjc/utils/ioutils/CLFormatter.java
@@ -9,12 +9,11 @@ import java.util.UnknownFormatConversionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import bjc.utils.PropertyDB;
import bjc.utils.esodata.Tape;
import bjc.utils.esodata.SingleTape;
import static bjc.utils.PropertyDB.applyFormat;
-import static bjc.utils.PropertyDB.getCompiledRegex;
+
import static bjc.utils.PropertyDB.getRegex;
public class CLFormatter {
@@ -23,15 +22,15 @@ public class CLFormatter {
public final boolean colonMod;
public CLModifiers(boolean at, boolean colon) {
- atMod = at;
+ atMod = at;
colonMod = colon;
}
public static CLModifiers fromString(String modString) {
- boolean atMod = false;
+ boolean atMod = false;
boolean colonMod = false;
- if(modString != null) {
- atMod = modString.contains("@");
+ if (modString != null) {
+ atMod = modString.contains("@");
colonMod = modString.contains(":");
}
@@ -40,6 +39,8 @@ public class CLFormatter {
}
public static class EscapeException extends RuntimeException {
+ private static final long serialVersionUID = -4552821131068559005L;
+
public final boolean endIteration;
public EscapeException() {
@@ -59,16 +60,17 @@ public class CLFormatter {
public void format();
}
- private static final String prefixParam = getRegex("clFormatPrefix");
+ private static final String prefixParam = getRegex("clFormatPrefix");
private static final Pattern pPrefixParam = Pattern.compile(prefixParam);
- private static final String formatMod = getRegex("clFormatModifier");
+ private static final String formatMod = getRegex("clFormatModifier");
private static final String prefixList = applyFormat("delimSeparatedList", prefixParam, ",");
private static final String directiveName = getRegex("clFormatName");
- private static final String formatDirective = applyFormat("clFormatDirective", prefixList, formatMod, directiveName);
+ private static final String formatDirective = applyFormat("clFormatDirective", prefixList, formatMod,
+ directiveName);
private static final Pattern pFormatDirective = Pattern.compile(formatDirective);
private Map<String, Directive> extraDirectives;
@@ -77,15 +79,16 @@ public class CLFormatter {
extraDirectives = new HashMap<>();
}
- private void checkItem(Object itm, char directive) {
- if(itm == null)
- throw new IllegalArgumentException(String.format("No argument provided for %c directive", directive));
+ private static void checkItem(Object itm, char directive) {
+ if (itm == null)
+ throw new IllegalArgumentException(
+ String.format("No argument provided for %c directive", directive));
}
public String formatString(String format, Object... params) {
StringBuffer sb = new StringBuffer();
/* Put the parameters where we can easily handle them. */
- Tape<Object> tParams = new SingleTape(params);
+ Tape<Object> tParams = new SingleTape<>(params);
doFormatString(format, sb, tParams);
@@ -95,124 +98,123 @@ public class CLFormatter {
private void doFormatString(String format, StringBuffer sb, Tape<Object> tParams) {
Matcher dirMatcher = pFormatDirective.matcher(format);
- while(dirMatcher.find()) {
+ while (dirMatcher.find()) {
dirMatcher.appendReplacement(sb, "");
- String dirName = dirMatcher.group("name");
- String dirFunc = dirMatcher.group("funcname");
- String dirMods = dirMatcher.group("modifiers");
+ String dirName = dirMatcher.group("name");
+ String dirFunc = dirMatcher.group("funcname");
+ String dirMods = dirMatcher.group("modifiers");
String dirParams = dirMatcher.group("params");
CLParameters arrParams = CLParameters.fromDirective(dirParams.split("(?<!'),"), tParams);
- CLModifiers mods = CLModifiers.fromString(dirMods);
+ CLModifiers mods = CLModifiers.fromString(dirMods);
Object item = tParams.item();
- if(dirName == null && dirFunc != null) {
+ if (dirName == null && dirFunc != null) {
/*
* @TODO implement user-called functions.
*/
continue;
}
- switch(dirName) {
- case "A":
- checkItem(item, 'A');
- handleAestheticDirective(sb, item, mods, arrParams);
- tParams.right();
- break;
- case "B":
- checkItem(item, 'B');
- if(!(item instanceof Number)) {
- throw new IllegalFormatConversionException('B', item.getClass());
- }
- handleNumberDirective(sb, mods, arrParams, -1, ((Number)item).longValue(), 2);
- tParams.right();
- break;
- case "C":
- checkItem(item, 'C');
- handleCDirective(sb, item, mods);
- tParams.right();
- break;
- case "D":
- checkItem(item, 'D');
- if(!(item instanceof Number)) {
- throw new IllegalFormatConversionException('D', item.getClass());
- }
- handleNumberDirective(sb, mods, arrParams, -1, ((Number)item).longValue(), 10);
- tParams.right();
- break;
- case "O":
- checkItem(item, 'O');
- if(!(item instanceof Number)) {
- throw new IllegalFormatConversionException('O', item.getClass());
- }
- handleNumberDirective(sb, mods, arrParams, -1, ((Number)item).longValue(), 8);
- tParams.right();
- break;
- case "R":
- checkItem(item, 'R');
- handleRadixDirective(sb, mods, arrParams, item);
- tParams.right();
- break;
- case "X":
- checkItem(item, 'X');
- if(!(item instanceof Number)) {
- throw new IllegalFormatConversionException('X', item.getClass());
- }
- handleNumberDirective(sb, mods, arrParams, -1, ((Number)item).longValue(), 16);
- tParams.right();
- break;
- case "&":
- handleFreshlineDirective(sb, arrParams);
- break;
- case "%":
- handleLiteralDirective(sb, arrParams, "\n", '%');
- break;
- case "|":
- handleLiteralDirective(sb, arrParams, "\f", '|');
- break;
- case "~":
- handleLiteralDirective(sb, arrParams, "~", '~');
- break;
- case "*":
- handleGotoDirective(mods, arrParams, tParams);
- break;
- case "^":
- handleEscapeDirective(mods, arrParams, tParams);
- break;
- case "[":
- handleConditionalDirective(sb, mods, arrParams, tParams, dirMatcher);
- break;
- case "]":
- throw new IllegalArgumentException("Found conditional-end outside of conditional.");
- case ";":
- throw new IllegalArgumentException("Found conditional-seperator outside of conditional.");
- case "T":
- case "<":
- case ">":
- /* @TODO
- * Figure out how to implement
- * tabulation/justification in a
- * reasonable manner.
- */
- throw new IllegalArgumentException("Layout-control directives aren't implemented yet.");
- case "F":
- case "E":
- case "G":
- case "$":
- /* @TODO implement floating point directives. */
- throw new IllegalArgumentException("Floating-point directives aren't implemented yet.");
- case "S":
- case "W":
- /* @TODO
- * figure out if we want to implement
- * someting for these directives instead
- * of punting.
- * */
- throw new IllegalArgumentException("S and W aren't implemented. Use A instead");
- default:
- String msg = String.format("Unknown format directive '%s'", dirName);
- throw new UnknownFormatConversionException(msg);
+ switch (dirName) {
+ case "A":
+ checkItem(item, 'A');
+ handleAestheticDirective(sb, item, mods, arrParams);
+ tParams.right();
+ break;
+ case "B":
+ checkItem(item, 'B');
+ if (!(item instanceof Number)) {
+ throw new IllegalFormatConversionException('B', item.getClass());
+ }
+ handleNumberDirective(sb, mods, arrParams, -1, ((Number) item).longValue(), 2);
+ tParams.right();
+ break;
+ case "C":
+ checkItem(item, 'C');
+ handleCDirective(sb, item, mods);
+ tParams.right();
+ break;
+ case "D":
+ checkItem(item, 'D');
+ if (!(item instanceof Number)) {
+ throw new IllegalFormatConversionException('D', item.getClass());
+ }
+ handleNumberDirective(sb, mods, arrParams, -1, ((Number) item).longValue(), 10);
+ tParams.right();
+ break;
+ case "O":
+ checkItem(item, 'O');
+ if (!(item instanceof Number)) {
+ throw new IllegalFormatConversionException('O', item.getClass());
+ }
+ handleNumberDirective(sb, mods, arrParams, -1, ((Number) item).longValue(), 8);
+ tParams.right();
+ break;
+ case "R":
+ checkItem(item, 'R');
+ handleRadixDirective(sb, mods, arrParams, item);
+ tParams.right();
+ break;
+ case "X":
+ checkItem(item, 'X');
+ if (!(item instanceof Number)) {
+ throw new IllegalFormatConversionException('X', item.getClass());
+ }
+ handleNumberDirective(sb, mods, arrParams, -1, ((Number) item).longValue(), 16);
+ tParams.right();
+ break;
+ case "&":
+ handleFreshlineDirective(sb, arrParams);
+ break;
+ case "%":
+ handleLiteralDirective(sb, arrParams, "\n", '%');
+ break;
+ case "|":
+ handleLiteralDirective(sb, arrParams, "\f", '|');
+ break;
+ case "~":
+ handleLiteralDirective(sb, arrParams, "~", '~');
+ break;
+ case "*":
+ handleGotoDirective(mods, arrParams, tParams);
+ break;
+ case "^":
+ handleEscapeDirective(mods, arrParams, tParams);
+ break;
+ case "[":
+ handleConditionalDirective(sb, mods, arrParams, tParams, dirMatcher);
+ break;
+ case "]":
+ throw new IllegalArgumentException("Found conditional-end outside of conditional.");
+ case ";":
+ throw new IllegalArgumentException(
+ "Found conditional-seperator outside of conditional.");
+ case "T":
+ case "<":
+ case ">":
+ /*
+ * @TODO Figure out how to implement tabulation/justification in a reasonable
+ * manner.
+ */
+ throw new IllegalArgumentException("Layout-control directives aren't implemented yet.");
+ case "F":
+ case "E":
+ case "G":
+ case "$":
+ /* @TODO implement floating point directives. */
+ throw new IllegalArgumentException("Floating-point directives aren't implemented yet.");
+ case "S":
+ case "W":
+ /*
+ * @TODO figure out if we want to implement someting for these directives
+ * instead of punting.
+ */
+ throw new IllegalArgumentException("S and W aren't implemented. Use A instead");
+ default:
+ String msg = String.format("Unknown format directive '%s'", dirName);
+ throw new UnknownFormatConversionException(msg);
}
}
@@ -220,14 +222,14 @@ public class CLFormatter {
}
private void handleCDirective(StringBuffer buff, Object parm, CLModifiers mods) {
- if(!(parm instanceof Character)) {
+ if (!(parm instanceof Character)) {
throw new IllegalFormatConversionException('C', parm.getClass());
}
char ch = (Character) parm;
int codepoint = (int) ch;
- if(mods.colonMod) {
+ if (mods.colonMod) {
/*
* Colon mod means print Unicode character name.
*/
@@ -237,58 +239,59 @@ public class CLFormatter {
}
}
- private void handleFreshlineDirective(StringBuffer buff, CLParameters params) {
+ private void handleFreshlineDirective(StringBuffer buff, CLParameters params) {
int nTimes = 1;
- if(params.length() > 1) {
+ if (params.length() > 1) {
nTimes = params.getInt(0, "occurance count", '&');
}
- if(buff.charAt(buff.length() - 1) == '\n') nTimes -= 1;
+ if (buff.charAt(buff.length() - 1) == '\n')
+ nTimes -= 1;
- for(int i = 0; i < nTimes; i++) {
+ for (int i = 0; i < nTimes; i++) {
buff.append("\n");
}
}
- private void handleLiteralDirective(StringBuffer buff, CLParameters params, String lit, char directive) {
+ private void handleLiteralDirective(StringBuffer buff, CLParameters params, String lit, char directive) {
int nTimes = 1;
- if(params.length() > 1) {
+ if (params.length() > 1) {
nTimes = params.getInt(0, "occurance count", directive);
}
- for(int i = 0; i < nTimes; i++) {
+ for (int i = 0; i < nTimes; i++) {
buff.append(lit);
}
}
- private void handleNumberDirective(StringBuffer buff, CLModifiers mods, CLParameters params, int argidx, long val, int radix) {
+ private void handleNumberDirective(StringBuffer buff, CLModifiers mods, CLParameters params, int argidx,
+ long val, int radix) {
/*
- * Initialize the two padding related parameters, and
- * then fill them in from the directive parameters if
- * they are present.
+ * Initialize the two padding related parameters, and then fill them in from the
+ * directive parameters if they are present.
*/
- int mincol = 0;
+ int mincol = 0;
char padchar = ' ';
- if(params.length() > (argidx + 2)) {
+ if (params.length() > (argidx + 2)) {
mincol = params.getIntDefault(argidx + 1, "minimum column count", 'R', 0);
}
- if(params.length() > (argidx + 3)) {
+ if (params.length() > (argidx + 3)) {
padchar = params.getCharDefault(argidx + 2, "padding character", 'R', ' ');
}
- if(mods.colonMod) {
+ if (mods.colonMod) {
/*
- * We're doing commas, so check if the two
- * comma-related parameters were supplied.
+ * We're doing commas, so check if the two comma-related parameters were
+ * supplied.
*/
- int commaInterval = 0;
- char commaChar = ',';
- if(params.length() > (argidx + 3)) {
+ int commaInterval = 0;
+ char commaChar = ',';
+ if (params.length() > (argidx + 3)) {
commaChar = params.getCharDefault((argidx + 3), "comma character", 'R', ' ');
}
- if(params.length() > (argidx + 4)) {
+ if (params.length() > (argidx + 4)) {
commaInterval = params.getIntDefault((argidx + 4), "comma interval", 'R', 0);
}
@@ -299,26 +302,27 @@ public class CLFormatter {
}
private void handleRadixDirective(StringBuffer buff, CLModifiers mods, CLParameters params, Object arg) {
- if(!(arg instanceof Number)) {
+ if (!(arg instanceof Number)) {
throw new IllegalFormatConversionException('R', arg.getClass());
}
/*
* @TODO see if this is the way we want to do this.
*/
- long val = ((Number)arg).longValue();
+ long val = ((Number) arg).longValue();
- if(params.length() == 0) {
- if(mods.atMod) {
- buff.append(NumberUtils.toRoman((Long)val, mods.colonMod));
- } else if(mods.colonMod) {
+ if (params.length() == 0) {
+ if (mods.atMod) {
+ buff.append(NumberUtils.toRoman((Long) val, mods.colonMod));
+ } else if (mods.colonMod) {
buff.append(NumberUtils.toOrdinal(val));
} else {
buff.append(NumberUtils.toCardinal(val));
}
} else {
- if(params.length() < 1)
- throw new IllegalArgumentException("R directive requires at least one parameter, the radix");
+ if (params.length() < 1)
+ throw new IllegalArgumentException(
+ "R directive requires at least one parameter, the radix");
int radix = params.getInt(0, "radix", 'R');
@@ -330,27 +334,28 @@ public class CLFormatter {
int mincol = 0, colinc = 1, minpad = 0;
char padchar = ' ';
- if(params.length() > 1) {
+ if (params.length() > 1) {
mincol = params.getIntDefault(0, "minimum column count", 'A', 0);
}
- if(params.length() < 4) {
- throw new IllegalArgumentException("Must provide either zero, one or four arguments to A directive");
+ if (params.length() < 4) {
+ throw new IllegalArgumentException(
+ "Must provide either zero, one or four arguments to A directive");
}
- colinc = params.getIntDefault(1, "padding increment", 'A', 1);
- minpad = params.getIntDefault(2, "minimum amount of padding", 'A', 0);
+ colinc = params.getIntDefault(1, "padding increment", 'A', 1);
+ minpad = params.getIntDefault(2, "minimum amount of padding", 'A', 0);
padchar = params.getCharDefault(3, "padding character", 'A', ' ');
StringBuilder work = new StringBuilder();
- if(mods.atMod) {
- for(int i = 0; i < minpad; i++) {
+ if (mods.atMod) {
+ for (int i = 0; i < minpad; i++) {
work.append(padchar);
}
- for(int i = work.length(); i < mincol; i++) {
- for(int k = 0; k < colinc; k++) {
+ for (int i = work.length(); i < mincol; i++) {
+ for (int k = 0; k < colinc; k++) {
work.append(padchar);
}
}
@@ -358,13 +363,13 @@ public class CLFormatter {
work.append(item.toString());
- if(!mods.atMod) {
- for(int i = 0; i < minpad; i++) {
+ if (!mods.atMod) {
+ for (int i = 0; i < minpad; i++) {
work.append(padchar);
}
- for(int i = work.length(); i < mincol; i++) {
- for(int k = 0; k < colinc; k++) {
+ for (int i = work.length(); i < mincol; i++) {
+ for (int k = 0; k < colinc; k++) {
work.append(padchar);
}
}
@@ -372,16 +377,16 @@ public class CLFormatter {
}
private void handleGotoDirective(CLModifiers mods, CLParameters params, Tape<Object> formatParams) {
- if(mods.colonMod) {
+ if (mods.colonMod) {
int num = 1;
- if(params.length() > 1) {
+ if (params.length() > 1) {
num = params.getIntDefault(0, "number of arguments backward", '*', 1);
}
formatParams.left(num);
- } else if(mods.atMod) {
+ } else if (mods.atMod) {
int num = 0;
- if(params.length() > 1) {
+ if (params.length() > 1) {
num = params.getIntDefault(0, "argument index", '*', 0);
}
@@ -389,7 +394,7 @@ public class CLFormatter {
formatParams.right(num);
} else {
int num = 1;
- if(params.length() > 1) {
+ if (params.length() > 1) {
num = params.getIntDefault(0, "number of arguments forward", '*', 1);
}
@@ -397,43 +402,44 @@ public class CLFormatter {
}
}
- private void handleConditionalDirective(StringBuffer sb, CLModifiers mods, CLParameters arrParams, Tape<Object> formatParams, Matcher dirMatcher) {
+ private void handleConditionalDirective(StringBuffer sb, CLModifiers mods, CLParameters arrParams,
+ Tape<Object> formatParams, Matcher dirMatcher) {
StringBuffer condBody = new StringBuffer();
- List<String> clauses = new ArrayList<>();
- String defClause = null;
- boolean isDefault = false;
+ List<String> clauses = new ArrayList<>();
+ String defClause = null;
+ boolean isDefault = false;
- while(dirMatcher.find()) {
+ while (dirMatcher.find()) {
/* Process a list of clauses. */
String dirName = dirMatcher.group("name");
String dirMods = dirMatcher.group("modifiers");
- if(dirName != null) {
+ if (dirName != null) {
/* Append everything up to this directive. */
dirMatcher.appendReplacement(condBody, "");
- if(dirName.equals("]")) {
+ if (dirName.equals("]")) {
/* End the conditional. */
String clause = condBody.toString();
- if(isDefault) {
+ if (isDefault) {
defClause = clause;
} else {
clauses.add(clause);
}
break;
- } else if(dirName.equals(";")) {
+ } else if (dirName.equals(";")) {
/* End the clause. */
String clause = condBody.toString();
- if(isDefault) {
+ if (isDefault) {
defClause = clause;
} else {
clauses.add(clause);
}
/* Mark the next clause as the default. */
- if(dirMods.contains(":")) {
+ if (dirMods.contains(":")) {
isDefault = true;
}
} else {
@@ -444,51 +450,54 @@ public class CLFormatter {
}
Object par = formatParams.item();
- if(mods.colonMod) {
+ if (mods.colonMod) {
formatParams.right();
- if(par == null) {
+ if (par == null) {
throw new IllegalArgumentException("No parameter provided for [ directive.");
- } else if(!(par instanceof Boolean)) {
+ } else if (!(par instanceof Boolean)) {
throw new IllegalFormatConversionException('[', par.getClass());
}
- boolean res = (Boolean)par;
+ boolean res = (Boolean) par;
String fmt;
- if(res) fmt = clauses.get(1);
- else fmt = clauses.get(0);
+ if (res)
+ fmt = clauses.get(1);
+ else
+ fmt = clauses.get(0);
doFormatString(fmt, sb, formatParams);
- } else if(mods.atMod) {
- if(par == null) {
+ } else if (mods.atMod) {
+ if (par == null) {
throw new IllegalArgumentException("No parameter provided for [ directive.");
- } else if(!(par instanceof Boolean)) {
+ } else if (!(par instanceof Boolean)) {
throw new IllegalFormatConversionException('[', par.getClass());
}
- boolean res = (Boolean)par;
+ boolean res = (Boolean) par;
- if(res) {
+ if (res) {
doFormatString(clauses.get(0), sb, formatParams);
} else {
formatParams.right();
}
} else {
int res;
- if(arrParams.length() > 1) {
+ if (arrParams.length() > 1) {
res = arrParams.getInt(0, "conditional choice", '[');
} else {
- if(par == null) {
+ if (par == null) {
throw new IllegalArgumentException("No parameter provided for [ directive.");
- } else if(!(par instanceof Number)) {
+ } else if (!(par instanceof Number)) {
throw new IllegalFormatConversionException('[', par.getClass());
}
- res = ((Number)par).intValue();
+ res = ((Number) par).intValue();
formatParams.right();
}
- if(res < 0 || res > clauses.size()) {
- if(defClause != null) doFormatString(defClause, sb, formatParams);
+ if (res < 0 || res > clauses.size()) {
+ if (defClause != null)
+ doFormatString(defClause, sb, formatParams);
} else {
doFormatString(clauses.get(res), sb, formatParams);
}
@@ -499,33 +508,34 @@ public class CLFormatter {
private void handleEscapeDirective(CLModifiers mods, CLParameters params, Tape<Object> formatParams) {
boolean shouldExit;
- switch(params.length()) {
+ switch (params.length()) {
case 0:
shouldExit = formatParams.size() == 0;
break;
case 1:
- int num = params.getInt(0, "condition count", '^');
+ int num = params.getInt(0, "condition count", '^');
shouldExit = num == 0;
break;
case 2:
- int left = params.getInt(0, "left-hand condition", '^');
- int right = params.getInt(1, "right-hand condition", '^');
+ int left = params.getInt(0, "left-hand condition", '^');
+ int right = params.getInt(1, "right-hand condition", '^');
shouldExit = left == right;
break;
case 3:
default:
- int low = params.getInt(0, "lower-bound condition", '^');
- int mid = params.getInt(1, "interval condition", '^');
- int high = params.getInt(2, "upper-bound condition", '^');
+ int low = params.getInt(0, "lower-bound condition", '^');
+ int mid = params.getInt(1, "interval condition", '^');
+ int high = params.getInt(2, "upper-bound condition", '^');
shouldExit = (low <= mid) && (mid <= high);
break;
}
/* At negates it. */
- if(mods.atMod) shouldExit = !shouldExit;
+ if (mods.atMod)
+ shouldExit = !shouldExit;
- if(shouldExit) throw new EscapeException(mods.colonMod);
+ if (shouldExit)
+ throw new EscapeException(mods.colonMod);
}
-
}
diff --git a/base/src/main/java/bjc/utils/ioutils/CLParameters.java b/base/src/main/java/bjc/utils/ioutils/CLParameters.java
index e4bb6fb..9d0c9c6 100644
--- a/base/src/main/java/bjc/utils/ioutils/CLParameters.java
+++ b/base/src/main/java/bjc/utils/ioutils/CLParameters.java
@@ -27,36 +27,42 @@ public class CLParameters {
* Mostly, this just fills in V and # parameters.
*
* @param params
- * The parameters of the directive.
+ * The parameters of the directive.
* @param dirParams
- * The parameters of the format string.
+ * The parameters of the format string.
*
* @return A set of CL parameters.
*/
public static CLParameters fromDirective(String[] params, Tape<Object> dirParams) {
List<String> parameters = new ArrayList<>();
- for(String param : params) {
- if(param.equalsIgnoreCase("V")) {
+ for (String param : params) {
+ if (param.equalsIgnoreCase("V")) {
Object par = dirParams.item();
boolean succ = dirParams.right();
- if(par == null) {
- throw new IllegalArgumentException("Expected a format parameter for V inline parameter");
+ if (!succ) {
+ throw new IllegalStateException("Couldn't advance tape for parameter");
}
- if(par instanceof Number) {
- int val = ((Number)par).intValue();
-
+ if (par == null) {
+ throw new IllegalArgumentException(
+ "Expected a format parameter for V inline parameter");
+ }
+
+ if (par instanceof Number) {
+ int val = ((Number) par).intValue();
+
parameters.add(Integer.toString(val));
- } else if(par instanceof Character) {
- char ch = ((Character)par);
+ } else if (par instanceof Character) {
+ char ch = ((Character) par);
parameters.add(Character.toString(ch));
} else {
- throw new IllegalArgumentException("Incorrect type of parameter for V inline parameter");
+ throw new IllegalArgumentException(
+ "Incorrect type of parameter for V inline parameter");
}
- } else if(param.equals("#")) {
+ } else if (param.equals("#")) {
parameters.add(Integer.toString(dirParams.position()));
} else {
parameters.add(param);
@@ -67,7 +73,7 @@ public class CLParameters {
}
public char getCharDefault(int idx, String paramName, char directive, char def) {
- if(!params[idx].equals("")) {
+ if (!params[idx].equals("")) {
return getChar(idx, paramName, directive);
}
@@ -77,15 +83,16 @@ public class CLParameters {
public char getChar(int idx, String paramName, char directive) {
String param = params[idx];
- if(!param.startsWith("'")) {
- throw new IllegalArgumentException(String.format("Invalid %s %s to %c directive", paramName, param, directive));
+ if (!param.startsWith("'")) {
+ throw new IllegalArgumentException(
+ String.format("Invalid %s %s to %c directive", paramName, param, directive));
}
return param.charAt(1);
}
public int getIntDefault(int idx, String paramName, char directive, int def) {
- if(!params[idx].equals("")) {
+ if (!params[idx].equals("")) {
}
diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java
index f4d8439..16d2e44 100644
--- a/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java
+++ b/base/src/main/java/bjc/utils/ioutils/blocks/FlatMappedBlockReader.java
@@ -5,7 +5,6 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
-import java.util.function.UnaryOperator;
/**
* A block reader that supports applying a flatmap operation to blocks.
diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java
index 734bde8..7985de2 100644
--- a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java
+++ b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java
@@ -1,7 +1,6 @@
package bjc.utils.ioutils.blocks;
import java.io.IOException;
-import java.io.LineNumberReader;
import java.io.Reader;
import java.util.NoSuchElementException;
import java.util.Scanner;
diff --git a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java
index 096656a..cb6c86f 100644
--- a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java
+++ b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java
@@ -10,8 +10,6 @@ import java.util.regex.PatternSyntaxException;
import static java.util.Map.Entry;
-import static bjc.utils.PropertyDB.applyFormat;
-import static bjc.utils.PropertyDB.getCompiledRegex;
import static bjc.utils.PropertyDB.getRegex;
public class StringDescaper {
@@ -30,10 +28,11 @@ public class StringDescaper {
private String rEscapeString;
private Pattern escapePatt;
- private static String rDoubleQuoteString = applyFormat("doubleQuotes", getRegex("nonStringEscape"), rPossibleEscapeString);
- private static Pattern doubleQuotePatt = Pattern.compile(rDoubleQuoteString);
+ // These should be used for something, but I don't recall what
+ //private static String rDoubleQuoteString = applyFormat("doubleQuotes", getRegex("nonStringEscape"), rPossibleEscapeString);
+ //private static Pattern doubleQuotePatt = Pattern.compile(rDoubleQuoteString);
- private static Pattern quotePatt = getCompiledRegex("unescapedQuote");
+ //private static Pattern quotePatt = getCompiledRegex("unescapedQuote");
private Map<String, String> literalEscapes;
private Map<Pattern, UnaryOperator<String>> specialEscapes;
@@ -55,10 +54,6 @@ public class StringDescaper {
}
public void addSpecialEscape(String escape, UnaryOperator<String> val) {
- if(specialEscapes.containsKey(escape)) {
- LOGGER.warning(String.format("Shadowing special escape '%s'\n", escape));
- }
-
/*
* Make sure this special escape is a valid regex.
*/
@@ -74,6 +69,10 @@ public class StringDescaper {
throw psex;
}
+
+ if(specialEscapes.containsKey(patt)) {
+ LOGGER.warning(String.format("Shadowing special escape '%s'\n", escape));
+ }
specialEscapes.put(patt, val);
}
diff --git a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java
index 67c1e5a..cb9ab7b 100644
--- a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java
+++ b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java
@@ -56,7 +56,7 @@ public class TokenUtils {
private static Pattern quotePatt = getCompiledRegex("unescapedQuote");
- private static Pattern intLitPattern = getCompiledRegex("intLiteral");
+ //private static Pattern intLitPattern = getCompiledRegex("intLiteral");
/**
* Remove double quoted strings from a string.