summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/parserutils')
-rw-r--r--base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java3
-rw-r--r--base/src/main/java/bjc/utils/parserutils/IPrecedent.java2
-rw-r--r--base/src/main/java/bjc/utils/parserutils/ParserException.java6
-rw-r--r--base/src/main/java/bjc/utils/parserutils/ShuntingYard.java56
-rw-r--r--base/src/main/java/bjc/utils/parserutils/StringDescaper.java63
-rw-r--r--base/src/main/java/bjc/utils/parserutils/TokenTransformer.java16
-rw-r--r--base/src/main/java/bjc/utils/parserutils/TokenUtils.java40
-rw-r--r--base/src/main/java/bjc/utils/parserutils/TreeConstructor.java28
-rw-r--r--base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java4
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java2
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java147
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java2
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java8
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/SequenceCharacteristics.java32
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java65
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java4
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/ChainTokenSplitter.java4
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java22
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java17
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java4
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/SimpleTokenSplitter.java9
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitter.java2
-rw-r--r--base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java4
23 files changed, 277 insertions, 263 deletions
diff --git a/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java b/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java
index a885808..e045222 100644
--- a/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java
+++ b/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java
@@ -36,7 +36,8 @@ class DoubleMatcher {
* Floating point components.
*/
private static final String rFPLeader = getRegex("fpLeader");
- private static final String rFPNum = applyFormat("fpNumber", rSimpleIntDec, rSimpleDec, rHexString);
+ private static final String rFPNum = applyFormat("fpNumber", rSimpleIntDec, rSimpleDec,
+ rHexString);
/*
* Full double.
diff --git a/base/src/main/java/bjc/utils/parserutils/IPrecedent.java b/base/src/main/java/bjc/utils/parserutils/IPrecedent.java
index aa366cf..0deab5d 100644
--- a/base/src/main/java/bjc/utils/parserutils/IPrecedent.java
+++ b/base/src/main/java/bjc/utils/parserutils/IPrecedent.java
@@ -12,7 +12,7 @@ public interface IPrecedent {
* Create a new object with set precedence
*
* @param precedence
- * The precedence of the object to handle
+ * The precedence of the object to handle
* @return A new object with set precedence
*/
public static IPrecedent newSimplePrecedent(final int precedence) {
diff --git a/base/src/main/java/bjc/utils/parserutils/ParserException.java b/base/src/main/java/bjc/utils/parserutils/ParserException.java
index ae33aba..72e8ac4 100644
--- a/base/src/main/java/bjc/utils/parserutils/ParserException.java
+++ b/base/src/main/java/bjc/utils/parserutils/ParserException.java
@@ -16,7 +16,7 @@ public class ParserException extends Exception {
* Create a new exception with the provided message.
*
* @param msg
- * The message for the exception.
+ * The message for the exception.
*/
public ParserException(final String msg) {
super(msg);
@@ -26,9 +26,9 @@ public class ParserException extends Exception {
* Create a new exception with the provided message and cause.
*
* @param msg
- * The message for the exception.
+ * The message for the exception.
* @param cause
- * The cause of the exception.
+ * The cause of the exception.
*/
public ParserException(final String msg, final Exception cause) {
super(msg, cause);
diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
index a1b5feb..a0b1249 100644
--- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
+++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java
@@ -17,7 +17,7 @@ import bjc.utils.funcutils.StringUtils;
* @author ben
*
* @param <TokenType>
- * The type of tokens being shunted.
+ * The type of tokens being shunted.
*/
public class ShuntingYard<TokenType> {
/**
@@ -77,11 +77,12 @@ public class ShuntingYard<TokenType> {
/*
* Handle operators
*/
- if (operators.containsKey(token)) {
- /*
- * Pop operators while there isn't a higher precedence one
+ if(operators.containsKey(token)) {
+ /*
+ * Pop operators while there isn't a higher
+ * precedence one
*/
- while (!stack.isEmpty() && isHigherPrec(token, stack.peek())) {
+ while(!stack.isEmpty() && isHigherPrec(token, stack.peek())) {
output.add(transformer.apply(stack.pop()));
}
@@ -89,21 +90,23 @@ public class ShuntingYard<TokenType> {
* Put this operator onto the stack
*/
stack.push(token);
- } else if (StringUtils.containsOnly(token, "\\(")) {
+ } else if(StringUtils.containsOnly(token, "\\(")) {
/*
- * Handle groups of parenthesis for multiple nesting levels
+ * Handle groups of parenthesis for multiple
+ * nesting levels
*/
stack.push(token);
- } else if (StringUtils.containsOnly(token, "\\)")) {
+ } else if(StringUtils.containsOnly(token, "\\)")) {
/*
- * Handle groups of parenthesis for multiple nesting levels
+ * Handle groups of parenthesis for multiple
+ * nesting levels
*/
final String swappedToken = token.replace(')', '(');
/*
* Remove tokens up to a matching parenthesis
*/
- while (!stack.peek().equals(swappedToken)) {
+ while(!stack.peek().equals(swappedToken)) {
output.add(transformer.apply(stack.pop()));
}
@@ -129,8 +132,7 @@ public class ShuntingYard<TokenType> {
* Create a new shunting yard with a default set of operators.
*
* @param configureBasics
- * Whether or not basic math operators should be
- * provided.
+ * Whether or not basic math operators should be provided.
*/
public ShuntingYard(final boolean configureBasics) {
operators = new FunctionalMap<>();
@@ -138,7 +140,7 @@ public class ShuntingYard<TokenType> {
/*
* Add basic operators if we're configured to do so
*/
- if (configureBasics) {
+ if(configureBasics) {
operators.put("+", Operator.ADD);
operators.put("-", Operator.SUBTRACT);
operators.put("*", Operator.MULTIPLY);
@@ -150,10 +152,10 @@ public class ShuntingYard<TokenType> {
* Add an operator to the list of shuntable operators.
*
* @param operator
- * The token representing the operator.
+ * The token representing the operator.
*
* @param precedence
- * The precedence of the operator to add.
+ * The precedence of the operator to add.
*/
public void addOp(final String operator, final int precedence) {
/*
@@ -168,18 +170,18 @@ public class ShuntingYard<TokenType> {
* Add an operator to the list of shuntable operators.
*
* @param operator
- * The token representing the operator.
+ * The token representing the operator.
*
* @param precedence
- * The precedence of the operator.
+ * The precedence of the operator.
*/
public void addOp(final String operator, final IPrecedent precedence) {
/*
* Complain about trying to add an incorrect operator
*/
- if (operator == null)
+ if(operator == null)
throw new NullPointerException("Operator must not be null");
- else if (precedence == null) throw new NullPointerException("Precedence must not be null");
+ else if(precedence == null) throw new NullPointerException("Precedence must not be null");
/*
* Add the operator to the ones we handle
@@ -196,7 +198,7 @@ public class ShuntingYard<TokenType> {
/*
* If it doesn't, the left is higher precedence.
*/
- if (!exists) return false;
+ if(!exists) return false;
/*
* Get the precedence of operators
@@ -214,10 +216,10 @@ public class ShuntingYard<TokenType> {
* Transform a string of tokens from infix notation to postfix.
*
* @param input
- * The string to transform.
+ * The string to transform.
*
* @param transformer
- * The function to use to transform strings to tokens.
+ * The function to use to transform strings to tokens.
*
* @return A list of tokens in postfix notation.
*/
@@ -225,9 +227,9 @@ public class ShuntingYard<TokenType> {
/*
* Check our input
*/
- if (input == null)
+ if(input == null)
throw new NullPointerException("Input must not be null");
- else if (transformer == null) throw new NullPointerException("Transformer must not be null");
+ else if(transformer == null) throw new NullPointerException("Transformer must not be null");
/*
* Here's what we're handing back
@@ -258,14 +260,14 @@ public class ShuntingYard<TokenType> {
* Remove an operator from the list of shuntable operators.
*
* @param operator
- * The token representing the operator. If null, remove
- * all operators.
+ * The token representing the operator. If null, remove all
+ * operators.
*/
public void removeOp(final String operator) {
/*
* Check if we want to remove all operators
*/
- if (operator == null) {
+ if(operator == null) {
operators = new FunctionalMap<>();
} else {
operators.remove(operator);
diff --git a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java
index cb6c86f..59f4760 100644
--- a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java
+++ b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java
@@ -18,15 +18,15 @@ public class StringDescaper {
/*
* Patterns and pattern parts.
*/
- private static String rPossibleEscapeString = getRegex("possibleStringEscape");
- private static Pattern possibleEscapePatt = Pattern.compile(rPossibleEscapeString);
+ private static String rPossibleEscapeString = getRegex("possibleStringEscape");
+ private static Pattern possibleEscapePatt = Pattern.compile(rPossibleEscapeString);
- private static String rShortEscape = getRegex("shortFormStringEscape");
- private static String rOctalEscape = getRegex("octalStringEscape");
- private static String rUnicodeEscape = getRegex("unicodeStringEscape");
+ private static String rShortEscape = getRegex("shortFormStringEscape");
+ private static String rOctalEscape = getRegex("octalStringEscape");
+ private static String rUnicodeEscape = getRegex("unicodeStringEscape");
- private String rEscapeString;
- private Pattern escapePatt;
+ private String rEscapeString;
+ private Pattern escapePatt;
// These should be used for something, but I don't recall what
//private static String rDoubleQuoteString = applyFormat("doubleQuotes", getRegex("nonStringEscape"), rPossibleEscapeString);
@@ -34,15 +34,15 @@ public class StringDescaper {
//private static Pattern quotePatt = getCompiledRegex("unescapedQuote");
- private Map<String, String> literalEscapes;
- private Map<Pattern, UnaryOperator<String>> specialEscapes;
-
+ private Map<String, String> literalEscapes;
+ private Map<Pattern, UnaryOperator<String>> specialEscapes;
+
public StringDescaper() {
literalEscapes = new HashMap<>();
specialEscapes = new HashMap<>();
rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)");
- escapePatt = Pattern.compile(rEscapeString);
+ escapePatt = Pattern.compile(rEscapeString);
}
public void addLiteralEscape(String escape, String val) {
@@ -61,7 +61,7 @@ public class StringDescaper {
Pattern patt = null;
try {
patt = Pattern.compile(escape);
- } catch (PatternSyntaxException psex) {
+ } catch(PatternSyntaxException psex) {
String msg = String.format("Invalid special escape '%s'", escape);
IllegalArgumentException iaex = new IllegalArgumentException(msg);
@@ -69,7 +69,7 @@ public class StringDescaper {
throw psex;
}
-
+
if(specialEscapes.containsKey(patt)) {
LOGGER.warning(String.format("Shadowing special escape '%s'\n", escape));
}
@@ -93,24 +93,25 @@ public class StringDescaper {
}
/*
- * Convert user-defined escapes to a regex for matching.
- * We don't need a bar before %4 because the string has it.
+ * Convert user-defined escapes to a regex for matching. We
+ * don't need a bar before %4 because the string has it.
*/
- rEscapeString = String.format("\\(%1$s|%2$s|%3$s%4$s)", rShortEscape, rOctalEscape, rUnicodeEscape, work.toString());
- escapePatt = Pattern.compile(rEscapeString);
+ rEscapeString = String.format("\\(%1$s|%2$s|%3$s%4$s)", rShortEscape, rOctalEscape, rUnicodeEscape,
+ work.toString());
+ escapePatt = Pattern.compile(rEscapeString);
}
/**
* Replace escape characters with their actual equivalents.
*
* @param inp
- * The string to replace escape sequences in.
+ * The string to replace escape sequences in.
*
* @return The string with escape sequences replaced by their equivalent
* characters.
*/
public String descapeString(final String inp) {
- if (inp == null) {
+ if(inp == null) {
throw new NullPointerException("Input to descapeString must not be null");
}
@@ -121,13 +122,14 @@ public class StringDescaper {
final Matcher possibleEscapeFinder = possibleEscapePatt.matcher(inp);
final Matcher escapeFinder = escapePatt.matcher(inp);
- while (possibleEscapeFinder.find()) {
- if (!escapeFinder.find()) {
+ while(possibleEscapeFinder.find()) {
+ if(!escapeFinder.find()) {
/*
- * Found a possible escape that isn't actually an
- * escape.
+ * Found a possible escape that isn't actually
+ * an escape.
*/
- final String msg = String.format("Illegal escape sequence '%s' at position %d of string '%s'",
+ final String msg = String.format(
+ "Illegal escape sequence '%s' at position %d of string '%s'",
possibleEscapeFinder.group(), possibleEscapeFinder.start(), inp);
throw new IllegalArgumentException(msg);
}
@@ -138,7 +140,7 @@ public class StringDescaper {
* Convert the escape to a string.
*/
String escapeRep = "";
- switch (escapeSeq) {
+ switch(escapeSeq) {
case "\\b":
escapeRep = "\b";
break;
@@ -168,7 +170,7 @@ public class StringDescaper {
escapeRep = "\\";
break;
default:
- if (escapeSeq.startsWith("u")) {
+ if(escapeSeq.startsWith("u")) {
escapeRep = handleUnicodeEscape(escapeSeq.substring(1));
} else if(escapeSeq.startsWith("O")) {
escapeRep = handleOctalEscape(escapeSeq.substring(1));
@@ -203,7 +205,7 @@ public class StringDescaper {
final int codepoint = Integer.parseInt(seq, 16);
return new String(Character.toChars(codepoint));
- } catch (final IllegalArgumentException iaex) {
+ } catch(final IllegalArgumentException iaex) {
final String msg = String.format("'%s' is not a valid Unicode escape sequence'", seq);
final IllegalArgumentException reiaex = new IllegalArgumentException(msg);
@@ -221,14 +223,15 @@ public class StringDescaper {
try {
final int codepoint = Integer.parseInt(seq, 8);
- if (codepoint > 255) {
- final String msg = String.format("'%d' is outside the range of octal escapes', codepoint");
+ if(codepoint > 255) {
+ final String msg = String
+ .format("'%d' is outside the range of octal escapes', codepoint");
throw new IllegalArgumentException(msg);
}
return new String(Character.toChars(codepoint));
- } catch (final IllegalArgumentException iaex) {
+ } catch(final IllegalArgumentException iaex) {
final String msg = String.format("'%s' is not a valid octal escape sequence'", seq);
final IllegalArgumentException reiaex = new IllegalArgumentException(msg);
diff --git a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java
index 30ccc5a..5a37596 100644
--- a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java
+++ b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java
@@ -30,7 +30,8 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> {
@Override
public ConstructorState<TokenType> apply(final ConstructorState<TokenType> pair) {
/*
- * Replace the current AST with the result of handling an operator
+ * Replace the current AST with the result of handling
+ * an operator
*/
return new ConstructorState<>(pair.bindLeft(queuedASTs -> {
return handleOperator(queuedASTs);
@@ -46,13 +47,14 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> {
/*
* Handle special operators
*/
- if (isSpecialOperator.test(element)) {
+ if(isSpecialOperator.test(element)) {
newAST = handleSpecialOperator.apply(element).apply(queuedASTs);
} else {
/*
- * Error if we don't have enough for a binary operator
+ * Error if we don't have enough for a binary
+ * operator
*/
- if (queuedASTs.size() < 2) {
+ if(queuedASTs.size() < 2) {
final String msg = String.format(
"Attempted to parse binary operator without enough operands\n\tProblem operator is: %s\n\tPossible operand is: %s",
element.toString(), queuedASTs.peek().toString());
@@ -108,7 +110,7 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> {
/*
* Handle operators
*/
- if (operatorPredicate.test(element)) {
+ if(operatorPredicate.test(element)) {
initialState.transform(new OperatorHandler(element));
} else {
final ITree<TokenType> newAST = new Tree<>(element);
@@ -118,7 +120,9 @@ final class TokenTransformer<TokenType> implements Consumer<TokenType> {
*/
initialState.transform(pair -> {
/*
- * Transform the pair, ignoring the current AST in favor of the one consisting of the current element
+ * Transform the pair, ignoring the current AST
+ * in favor of the one consisting of the current
+ * element
*/
return new ConstructorState<>(pair.bindLeft(queue -> {
queue.push(newAST);
diff --git a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java
index cb9ab7b..2a6c0fd 100644
--- a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java
+++ b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java
@@ -64,13 +64,13 @@ public class TokenUtils {
* Splits a string around instances of java-style double-quoted strings.
*
* @param inp
- * The string to split.
+ * The string to split.
*
* @return An list containing alternating bits of the string and the
* embedded double-quoted strings that separated them.
*/
public static List<String> removeDQuotedStrings(final String inp) {
- if (inp == null) throw new NullPointerException("inp must not be null");
+ if(inp == null) throw new NullPointerException("inp must not be null");
/*
* What we need for piece-by-piece string building
@@ -84,7 +84,7 @@ public class TokenUtils {
final Matcher mt = doubleQuotePatt.matcher(inp);
final Matcher corr = quotePatt.matcher(inp);
- if (corr.find() && !corr.find()) {
+ if(corr.find() && !corr.find()) {
/*
* There's a unmatched opening quote with no strings.
*/
@@ -95,7 +95,7 @@ public class TokenUtils {
throw new IllegalArgumentException(msg);
}
- while (mt.find()) {
+ while(mt.find()) {
/*
* Remove the string until the quoted string.
*/
@@ -120,7 +120,7 @@ public class TokenUtils {
mt.appendTail(work);
final String tail = work.toString();
- if (tail.contains("\"")) {
+ if(tail.contains("\"")) {
/*
* There's a unmatched opening quote with at least one
* string.
@@ -135,7 +135,7 @@ public class TokenUtils {
/*
* Only add an empty tail if the string was empty.
*/
- if (!tail.equals("") || res.isEmpty()) {
+ if(!tail.equals("") || res.isEmpty()) {
res.add(tail);
}
@@ -146,13 +146,13 @@ public class TokenUtils {
* Replace escape characters with their actual equivalents.
*
* @param inp
- * The string to replace escape sequences in.
+ * The string to replace escape sequences in.
*
* @return The string with escape sequences replaced by their equivalent
* characters.
*/
public static String descapeString(final String inp) {
- if (inp == null) throw new NullPointerException("inp must not be null");
+ if(inp == null) throw new NullPointerException("inp must not be null");
/*
* Prepare the buffer and escape finder.
@@ -161,11 +161,11 @@ public class TokenUtils {
final Matcher possibleEscapeFinder = possibleEscapePatt.matcher(inp);
final Matcher escapeFinder = escapePatt.matcher(inp);
- while (possibleEscapeFinder.find()) {
- if (!escapeFinder.find()) {
+ while(possibleEscapeFinder.find()) {
+ if(!escapeFinder.find()) {
/*
- * Found a possible escape that isn't actually an
- * escape.
+ * Found a possible escape that isn't actually
+ * an escape.
*/
final String msg = String.format("Illegal escape sequence '%s' at position %d",
possibleEscapeFinder.group(), possibleEscapeFinder.start());
@@ -179,7 +179,7 @@ public class TokenUtils {
* Convert the escape to a string.
*/
String escapeRep = "";
- switch (escapeSeq) {
+ switch(escapeSeq) {
case "\\b":
escapeRep = "\b";
break;
@@ -209,7 +209,7 @@ public class TokenUtils {
escapeRep = "\\";
break;
default:
- if (escapeSeq.startsWith("u")) {
+ if(escapeSeq.startsWith("u")) {
escapeRep = handleUnicodeEscape(escapeSeq.substring(1));
} else {
escapeRep = handleOctalEscape(escapeSeq);
@@ -232,7 +232,7 @@ public class TokenUtils {
final int codepoint = Integer.parseInt(seq, 16);
return new String(Character.toChars(codepoint));
- } catch (final IllegalArgumentException iaex) {
+ } catch(final IllegalArgumentException iaex) {
final String msg = String.format("'%s' is not a valid Unicode escape sequence'", seq);
final IllegalArgumentException reiaex = new IllegalArgumentException(msg);
@@ -250,7 +250,7 @@ public class TokenUtils {
try {
final int codepoint = Integer.parseInt(seq, 8);
- if (codepoint > 255) {
+ if(codepoint > 255) {
final String msg = String
.format("'%d' is outside the range of octal escapes', codepoint");
@@ -258,7 +258,7 @@ public class TokenUtils {
}
return new String(Character.toChars(codepoint));
- } catch (final IllegalArgumentException iaex) {
+ } catch(final IllegalArgumentException iaex) {
final String msg = String.format("'%s' is not a valid octal escape sequence'", seq);
final IllegalArgumentException reiaex = new IllegalArgumentException(msg);
@@ -274,7 +274,7 @@ public class TokenUtils {
* by {@link Double#parseDouble(String)}.
*
* @param inp
- * The string to check.
+ * The string to check.
* @return Whether the string is a valid double or not.
*/
public static boolean isDouble(final String inp) {
@@ -289,14 +289,14 @@ public class TokenUtils {
* integers will still cause errors.
*
* @param inp
- * The input to check.
+ * The input to check.
* @return Whether the string is a valid integer or not.
*/
public static boolean isInt(final String inp) {
try {
Integer.parseInt(inp);
return true;
- } catch (NumberFormatException nfex) {
+ } catch(NumberFormatException nfex) {
return false;
}
}
diff --git a/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java b/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java
index 90141ef..7bff43e 100644
--- a/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java
+++ b/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java
@@ -23,7 +23,7 @@ public class TreeConstructor {
* Alias interface for special operator types.
*
* @param <TokenType>
- * The token type of the tree.
+ * The token type of the tree.
*/
public interface QueueFlattener<TokenType> extends Function<Deque<ITree<TokenType>>, ITree<TokenType>> {
@@ -48,12 +48,11 @@ public class TreeConstructor {
* Only binary operators are accepted.
*
* @param <TokenType>
- * The elements of the parse tree
+ * The elements of the parse tree
* @param tokens
- * The list of tokens to build a tree from
+ * The list of tokens to build a tree from
* @param isOperator
- * The predicate to use to determine if something is a
- * operator
+ * The predicate to use to determine if something is a operator
* @return A AST from the expression
*/
public static <TokenType> ITree<TokenType> constructTree(final IList<TokenType> tokens,
@@ -71,21 +70,20 @@ public class TreeConstructor {
* parameters to handle non-binary operators.
*
* @param <TokenType>
- * The elements of the parse tree.
+ * The elements of the parse tree.
*
* @param tokens
- * The list of tokens to build a tree from.
+ * The list of tokens to build a tree from.
*
* @param isOperator
- * The predicate to use to determine if something is a
- * operator.
+ * The predicate to use to determine if something is a operator.
*
* @param isSpecialOperator
- * The predicate to use to determine if an operator needs
- * special handling.
+ * The predicate to use to determine if an operator needs special
+ * handling.
*
* @param handleSpecialOperator
- * The function to use to handle special case operators.
+ * The function to use to handle special case operators.
*
* @return A AST from the expression
*
@@ -96,11 +94,11 @@ public class TreeConstructor {
/*
* Make sure our parameters are valid
*/
- if (tokens == null)
+ if(tokens == null)
throw new NullPointerException("Tokens must not be null");
- else if (isOperator == null)
+ else if(isOperator == null)
throw new NullPointerException("Operator predicate must not be null");
- else if (isSpecialOperator == null)
+ else if(isSpecialOperator == null)
throw new NullPointerException("Special operator determiner must not be null");
/*
diff --git a/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java b/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java
index 42866c2..5d206bd 100644
--- a/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java
+++ b/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java
@@ -5,8 +5,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SimpleDefine implements UnaryOperator<String> {
- private Pattern patt;
- private String repl;
+ private Pattern patt;
+ private String repl;
public SimpleDefine(Pattern pattern, String replace) {
patt = pattern;
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java
index 071afb4..4172d32 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java
@@ -13,7 +13,7 @@ public class DelimiterException extends RuntimeException {
* Create a new generic delimiter exception.
*
* @param res
- * The reason for this exception.
+ * The reason for this exception.
*/
public DelimiterException(final String res) {
super(res);
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
index 73c3473..5d020a6 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
@@ -24,7 +24,7 @@ import bjc.utils.funcdata.IList;
* @author EVE
*
* @param <T>
- * The type of items in the sequence.
+ * The type of items in the sequence.
*/
public class DelimiterGroup<T> {
/**
@@ -47,17 +47,17 @@ public class DelimiterGroup<T> {
/*
* The token that opened the group, and any opening parameters.
*/
- private final T opener;
- private final T[] params;
+ private final T opener;
+ private final T[] params;
/**
* Create a new instance of a delimiter group.
*
* @param open
- * The item that opened this group.
+ * The item that opened this group.
*
* @param parms
- * Any parameters from the opener.
+ * Any parameters from the opener.
*/
public OpenGroup(final T open, final T[] parms) {
opener = open;
@@ -72,7 +72,7 @@ public class DelimiterGroup<T> {
* Add an item to this group instance.
*
* @param itm
- * The item to add to this group instance.
+ * The item to add to this group instance.
*/
public void addItem(final ITree<T> itm) {
currentGroup.add(itm);
@@ -82,33 +82,33 @@ public class DelimiterGroup<T> {
* Mark a subgroup.
*
* @param marker
- * The item that indicated this subgroup.
+ * The item that indicated this subgroup.
*
* @param chars
- * The characteristics for building the tree.
+ * The characteristics for building the tree.
*/
public void markSubgroup(final T marker, final SequenceCharacteristics<T> chars) {
/*
* Add all of the contents to the subgroup.
*/
final ITree<T> subgroupContents = new Tree<>(chars.contents);
- for (final ITree<T> itm : currentGroup) {
+ for(final ITree<T> itm : currentGroup) {
subgroupContents.addChild(itm);
}
/*
* Handle subordinate sub-groups.
*/
- while (!contents.isEmpty()) {
+ while(!contents.isEmpty()) {
final ITree<T> possibleSubordinate = contents.peek();
/*
* Subordinate lower priority subgroups.
*/
- if (possibleSubordinate.getHead().equals(chars.subgroup)) {
+ if(possibleSubordinate.getHead().equals(chars.subgroup)) {
final T otherMarker = possibleSubordinate.getChild(1).getHead();
- if (subgroups.get(marker) > subgroups.get(otherMarker)) {
+ if(subgroups.get(marker) > subgroups.get(otherMarker)) {
subgroupContents.prependChild(contents.pop());
} else {
break;
@@ -129,10 +129,10 @@ public class DelimiterGroup<T> {
* Convert this group into a tree.
*
* @param closer
- * The item that closed this group.
+ * The item that closed this group.
*
* @param chars
- * The characteristics for building the tree.
+ * The characteristics for building the tree.
*
* @return This group as a tree.
*/
@@ -140,20 +140,20 @@ public class DelimiterGroup<T> {
/*
* Mark any implied subgroups.
*/
- if (impliedSubgroups.containsKey(closer)) {
+ if(impliedSubgroups.containsKey(closer)) {
markSubgroup(impliedSubgroups.get(closer), chars);
}
final ITree<T> res = new Tree<>(chars.contents);
/*
- * Add either the contents of the current group,
- * or subgroups if they're their.
+ * Add either the contents of the current group, or
+ * subgroups if they're their.
*/
- if (contents.isEmpty()) {
+ if(contents.isEmpty()) {
currentGroup.forEach(res::addChild);
} else {
- while (!contents.isEmpty()) {
+ while(!contents.isEmpty()) {
res.prependChild(contents.poll());
}
@@ -182,7 +182,7 @@ public class DelimiterGroup<T> {
* Check if a group is excluded at the top level of this group.
*
* @param grupName
- * The group to check.
+ * The group to check.
*
* @return Whether or not the provided group is excluded.
*/
@@ -194,16 +194,16 @@ public class DelimiterGroup<T> {
* Check if the provided delimiter would close this group.
*
* @param del
- * The string to check as a closing delimiter.
+ * The string to check as a closing delimiter.
*
* @return Whether or not the provided delimiter closes this
* group.
*/
public boolean isClosing(final T del) {
- if (closingDelimiters.contains(del)) return true;
+ if(closingDelimiters.contains(del)) return true;
- for (final BiPredicate<T, T[]> pred : predClosers) {
- if (pred.test(del, params)) return true;
+ for(final BiPredicate<T, T[]> pred : predClosers) {
+ if(pred.test(del, params)) return true;
}
return closingDelimiters.contains(del);
@@ -242,7 +242,7 @@ public class DelimiterGroup<T> {
* Checks if a given token marks a subgroup.
*
* @param tok
- * The token to check.
+ * The token to check.
*
* @return Whether or not the token marks a subgroup.
*/
@@ -254,18 +254,18 @@ public class DelimiterGroup<T> {
* Checks if a given token opens a group.
*
* @param marker
- * The token to check.
+ * The token to check.
*
* @return The name of the group T opens, or null if it doesn't
* open one.
*/
public IPair<T, T[]> doesOpen(final T marker) {
- if (openDelimiters.containsKey(marker)) return new Pair<>(openDelimiters.get(marker), null);
+ if(openDelimiters.containsKey(marker)) return new Pair<>(openDelimiters.get(marker), null);
- for (final Function<T, IPair<T, T[]>> pred : predOpeners) {
+ for(final Function<T, IPair<T, T[]>> pred : predOpeners) {
final IPair<T, T[]> par = pred.apply(marker);
- if (par.getLeft() != null) return par;
+ if(par.getLeft() != null) return par;
}
return new Pair<>(null, null);
@@ -341,10 +341,10 @@ public class DelimiterGroup<T> {
* Create a new empty delimiter group.
*
* @param name
- * The name of the delimiter group
+ * The name of the delimiter group
*/
public DelimiterGroup(final T name) {
- if (name == null) throw new NullPointerException("Group name must not be null");
+ if(name == null) throw new NullPointerException("Group name must not be null");
groupName = name;
@@ -367,16 +367,16 @@ public class DelimiterGroup<T> {
* Adds one or more delimiters that close this group.
*
* @param closers
- * Delimiters that close this group.
+ * Delimiters that close this group.
*/
@SafeVarargs
public final void addClosing(final T... closers) {
final List<T> closerList = Arrays.asList(closers);
- for (final T closer : closerList) {
- if (closer == null)
+ for(final T closer : closerList) {
+ if(closer == null)
throw new NullPointerException("Closing delimiter must not be null");
- else if (closer.equals(""))
+ else if(closer.equals(""))
/*
* We can do this because equals works on
* arbitrary objects, not just those of the same
@@ -394,14 +394,14 @@ public class DelimiterGroup<T> {
* group.
*
* @param exclusions
- * The groups forbidden in the top level of this group.
+ * The groups forbidden in the top level of this group.
*/
@SafeVarargs
public final void addTopLevelForbid(final T... exclusions) {
- for (final T exclusion : exclusions) {
- if (exclusion == null)
+ for(final T exclusion : exclusions) {
+ if(exclusion == null)
throw new NullPointerException("Exclusion must not be null");
- else if (exclusion.equals(""))
+ else if(exclusion.equals(""))
/*
* We can do this because equals works on
* arbitrary objects, not just those of the same
@@ -418,14 +418,14 @@ public class DelimiterGroup<T> {
* Adds one or more groups that cannot occur at all in this group.
*
* @param exclusions
- * The groups forbidden inside this group.
+ * The groups forbidden inside this group.
*/
@SafeVarargs
public final void addGroupForbid(final T... exclusions) {
- for (final T exclusion : exclusions) {
- if (exclusion == null)
+ for(final T exclusion : exclusions) {
+ if(exclusion == null)
throw new NullPointerException("Exclusion must not be null");
- else if (exclusion.equals(""))
+ else if(exclusion.equals(""))
/*
* We can do this because equals works on
* arbitrary objects, not just those of the same
@@ -442,13 +442,13 @@ public class DelimiterGroup<T> {
* Adds sub-group markers to this group.
*
* @param subgroup
- * The token to mark a sub-group.
+ * The token to mark a sub-group.
*
* @param priority
- * The priority of this sub-group.
+ * The priority of this sub-group.
*/
public void addSubgroup(final T subgroup, final int priority) {
- if (subgroup == null) throw new NullPointerException("Subgroup marker must not be null");
+ if(subgroup == null) throw new NullPointerException("Subgroup marker must not be null");
subgroups.put(subgroup, priority);
}
@@ -457,14 +457,15 @@ public class DelimiterGroup<T> {
* Adds a marker that opens a group at the top level of this group.
*
* @param opener
- * The marker that opens the group.
+ * The marker that opens the group.
*
* @param group
- * The group opened by the marker.
+ * The group opened by the marker.
*/
public void addOpener(final T opener, final T group) {
- if (opener == null) throw new NullPointerException("Opener must not be null");
- else if (group == null) throw new NullPointerException("Group to open must not be null");
+ if(opener == null)
+ throw new NullPointerException("Opener must not be null");
+ else if(group == null) throw new NullPointerException("Group to open must not be null");
openDelimiters.put(opener, group);
}
@@ -473,14 +474,15 @@ public class DelimiterGroup<T> {
* Adds a marker that opens a group inside of this group.
*
* @param opener
- * The marker that opens the group.
+ * The marker that opens the group.
*
* @param group
- * The group opened by the marker.
+ * The group opened by the marker.
*/
public void addNestedOpener(final T opener, final T group) {
- if (opener == null) throw new NullPointerException("Opener must not be null");
- else if (group == null) throw new NullPointerException("Group to open must not be null");
+ if(opener == null)
+ throw new NullPointerException("Opener must not be null");
+ else if(group == null) throw new NullPointerException("Group to open must not be null");
nestedOpenDelimiters.put(opener, group);
}
@@ -489,16 +491,20 @@ public class DelimiterGroup<T> {
* Mark a closing delimiter as implying a subgroup.
*
* @param closer
- * The closing delimiter.
+ * The closing delimiter.
*
* @param subgroup
- * The subgroup to imply.
+ * The subgroup to imply.
*/
public void implySubgroup(final T closer, final T subgroup) {
- if (closer == null) throw new NullPointerException("Closer must not be null");
- else if (subgroup == null) throw new NullPointerException("Subgroup must not be null");
- else if (!closingDelimiters.contains(closer)) throw new IllegalArgumentException(String.format("No closing delimiter '%s' defined", closer));
- else if (!subgroups.containsKey(subgroup)) throw new IllegalArgumentException(String.format("No subgroup '%s' defined", subgroup));
+ if(closer == null)
+ throw new NullPointerException("Closer must not be null");
+ else if(subgroup == null)
+ throw new NullPointerException("Subgroup must not be null");
+ else if(!closingDelimiters.contains(closer))
+ throw new IllegalArgumentException(String.format("No closing delimiter '%s' defined", closer));
+ else if(!subgroups.containsKey(subgroup))
+ throw new IllegalArgumentException(String.format("No subgroup '%s' defined", subgroup));
impliedSubgroups.put(closer, subgroup);
}
@@ -514,26 +520,26 @@ public class DelimiterGroup<T> {
builder.append("], ");
builder.append("closingDelimiters=[");
- for (final T closer : closingDelimiters) {
+ for(final T closer : closingDelimiters) {
builder.append(closer + ",");
}
builder.deleteCharAt(builder.length() - 1);
builder.append("]");
- if (topLevelExclusions != null && !topLevelExclusions.isEmpty()) {
+ if(topLevelExclusions != null && !topLevelExclusions.isEmpty()) {
builder.append(", ");
builder.append("topLevelExclusions=[");
- for (final T exclusion : topLevelExclusions) {
+ for(final T exclusion : topLevelExclusions) {
builder.append(exclusion + ",");
}
builder.deleteCharAt(builder.length() - 1);
builder.append("]");
}
- if (groupExclusions != null && !groupExclusions.isEmpty()) {
+ if(groupExclusions != null && !groupExclusions.isEmpty()) {
builder.append(", ");
builder.append("groupExclusions=[");
- for (final T exclusion : groupExclusions) {
+ for(final T exclusion : groupExclusions) {
builder.append(exclusion + ",");
}
builder.deleteCharAt(builder.length() - 1);
@@ -549,10 +555,10 @@ public class DelimiterGroup<T> {
* Open an instance of this group.
*
* @param opener
- * The item that opened this group.
+ * The item that opened this group.
*
* @param parms
- * The parameters that opened this group
+ * The parameters that opened this group
*
* @return An opened instance of this group.
*/
@@ -564,8 +570,7 @@ public class DelimiterGroup<T> {
* Adds a predicated opener to the top level of this group.
*
* @param pred
- * The predicate that defines the opener and its
- * parameters.
+ * The predicate that defines the opener and its parameters.
*/
public void addPredOpener(final Function<T, IPair<T, T[]>> pred) {
predOpeners.add(pred);
@@ -575,7 +580,7 @@ public class DelimiterGroup<T> {
* Adds a predicated closer to the top level of this group.
*
* @param pred
- * The predicate that defines the closer.
+ * The predicate that defines the closer.
*/
public void addPredCloser(final BiPredicate<T, T[]> pred) {
predClosers.add(pred);
@@ -585,7 +590,7 @@ public class DelimiterGroup<T> {
* Set whether or not this group starts a new nesting set.
*
* @param forgetful
- * Whether this group starts a new nesting set.
+ * Whether this group starts a new nesting set.
*/
public void setForgetful(final boolean forgetful) {
this.forgetful = forgetful;
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java b/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java
index 4b29949..ac257d1 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java
@@ -15,7 +15,7 @@ public class RegexCloser implements BiPredicate<String, String[]> {
* Create a new regex closer.
*
* @param closer
- * The format string to use for closing.
+ * The format string to use for closing.
*/
public RegexCloser(final String closer) {
rep = closer;
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java b/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java
index ee93b73..15f11e3 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java
@@ -22,10 +22,10 @@ public class RegexOpener implements Function<String, IPair<String, String[]>> {
* Create a new regex opener.
*
* @param groupName
- * The name of the opened group.
+ * The name of the opened group.
*
* @param groupRegex
- * The regex that matches the opener.
+ * The regex that matches the opener.
*/
public RegexOpener(final String groupName, final String groupRegex) {
name = groupName;
@@ -37,12 +37,12 @@ public class RegexOpener implements Function<String, IPair<String, String[]>> {
public IPair<String, String[]> apply(final String str) {
final Matcher m = patt.matcher(str);
- if (m.matches()) {
+ if(m.matches()) {
final int numGroups = m.groupCount();
final String[] parms = new String[numGroups + 1];
- for (int i = 0; i <= numGroups; i++) {
+ for(int i = 0; i <= numGroups; i++) {
parms[i] = m.group(i);
}
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/SequenceCharacteristics.java b/base/src/main/java/bjc/utils/parserutils/delims/SequenceCharacteristics.java
index 882b4c5..9e4c167 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceCharacteristics.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceCharacteristics.java
@@ -6,7 +6,7 @@ package bjc.utils.parserutils.delims;
* @author EVE
*
* @param <T>
- * The type of item in the tree.
+ * The type of item in the tree.
*/
public class SequenceCharacteristics<T> {
/**
@@ -29,11 +29,11 @@ public class SequenceCharacteristics<T> {
* Create a new set of parameters for building a tree.
*
* @param root
- * The root marker.
+ * The root marker.
* @param contents
- * The group/subgroup contents marker.
+ * The group/subgroup contents marker.
* @param subgroup
- * The subgroup marker.
+ * The subgroup marker.
*/
public SequenceCharacteristics(final T root, final T contents, final T subgroup) {
this.root = root;
@@ -55,23 +55,23 @@ public class SequenceCharacteristics<T> {
@Override
public boolean equals(final Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (!(obj instanceof SequenceCharacteristics)) return false;
+ if(this == obj) return true;
+ if(obj == null) return false;
+ if(!(obj instanceof SequenceCharacteristics)) return false;
final SequenceCharacteristics<?> other = (SequenceCharacteristics<?>) obj;
- if (contents == null) {
- if (other.contents != null) return false;
- } else if (!contents.equals(other.contents)) return false;
+ if(contents == null) {
+ if(other.contents != null) return false;
+ } else if(!contents.equals(other.contents)) return false;
- if (root == null) {
- if (other.root != null) return false;
- } else if (!root.equals(other.root)) return false;
+ if(root == null) {
+ if(other.root != null) return false;
+ } else if(!root.equals(other.root)) return false;
- if (subgroup == null) {
- if (other.subgroup != null) return false;
- } else if (!subgroup.equals(other.subgroup)) return false;
+ if(subgroup == null) {
+ if(other.subgroup != null) return false;
+ } else if(!subgroup.equals(other.subgroup)) return false;
return true;
}
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
index ccfaffb..0eddebe 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
@@ -24,7 +24,7 @@ import bjc.utils.funcutils.StringUtils;
* @author EVE
*
* @param <T>
- * The type of items in the sequence.
+ * The type of items in the sequence.
*/
public class SequenceDelimiter<T> {
/*
@@ -63,10 +63,9 @@ public class SequenceDelimiter<T> {
* </pre>
*
* @param chars
- * The parameters on how to mark certain portions of the
- * tree.
+ * The parameters on how to mark certain portions of the tree.
* @param seq
- * The sequence to delimit.
+ * The sequence to delimit.
*
* @return The sequence as a tree that matches its group structure. Each
* node in the tree is either a data node, a subgroup node, or a
@@ -89,14 +88,14 @@ public class SequenceDelimiter<T> {
* recursive tree.
*
* @throws DelimiterException
- * Thrown if something went wrong during sequence
- * delimitation.
+ * Thrown if something went wrong during sequence delimitation.
*
*/
public ITree<T> delimitSequence(final SequenceCharacteristics<T> chars,
@SuppressWarnings("unchecked") final T... seq) throws DelimiterException {
- if (initialGroup == null) throw new NullPointerException("Initial group must be specified.");
- else if (chars == null) throw new NullPointerException("Sequence characteristics must not be null");
+ if(initialGroup == null)
+ throw new NullPointerException("Initial group must be specified.");
+ else if(chars == null) throw new NullPointerException("Sequence characteristics must not be null");
/*
* The stack of opened and not yet closed groups.
@@ -128,7 +127,7 @@ public class SequenceDelimiter<T> {
/*
* Process each member of the sequence.
*/
- for (int i = 0; i < seq.length; i++) {
+ for(int i = 0; i < seq.length; i++) {
final T tok = seq[i];
/*
@@ -137,14 +136,14 @@ public class SequenceDelimiter<T> {
final IPair<T, T[]> possibleOpenPar = groupStack.top().doesOpen(tok);
T possibleOpen = possibleOpenPar.getLeft();
- if (possibleOpen == null) {
+ if(possibleOpen == null) {
/*
* Handle nested openers.
*
* Local openers take priority over nested ones
* if they overlap.
*/
- if (allowedDelimiters.top().containsKey(tok)) {
+ if(allowedDelimiters.top().containsKey(tok)) {
possibleOpen = allowedDelimiters.top().get(tok).iterator().next();
}
}
@@ -152,7 +151,7 @@ public class SequenceDelimiter<T> {
/*
* If we have an opening delimiter, handle it.
*/
- if (possibleOpen != null) {
+ if(possibleOpen != null) {
final DelimiterGroup<T> group = groups.get(possibleOpen);
/*
@@ -163,10 +162,10 @@ public class SequenceDelimiter<T> {
* top-level of this group, as well as nested
* exclusions from all enclosing groups.
*/
- if (isForbidden(groupStack, forbiddenDelimiters, possibleOpen)) {
+ if(isForbidden(groupStack, forbiddenDelimiters, possibleOpen)) {
T forbiddenBy;
- if (whoForbid.containsKey(tok)) {
+ if(whoForbid.containsKey(tok)) {
forbiddenBy = whoForbid.get(tok);
} else {
forbiddenBy = groupStack.top().getName();
@@ -188,7 +187,7 @@ public class SequenceDelimiter<T> {
/*
* Handle 'forgetful' groups that reset nesting
*/
- if (open.isForgetful()) {
+ if(open.isForgetful()) {
allowedDelimiters.push(HashMultimap.create());
forbiddenDelimiters.push(HashMultiset.create());
}
@@ -197,7 +196,7 @@ public class SequenceDelimiter<T> {
* Add the nested opens from this group.
*/
final Multimap<T, T> currentAllowed = allowedDelimiters.top();
- for (final Entry<T, T> opener : open.getNestingOpeners().entrySet()) {
+ for(final Entry<T, T> opener : open.getNestingOpeners().entrySet()) {
currentAllowed.put(opener.getKey(), opener.getValue());
}
@@ -205,12 +204,12 @@ public class SequenceDelimiter<T> {
* Add the nested exclusions from this group
*/
final Multiset<T> currentForbidden = forbiddenDelimiters.top();
- for (final T exclusion : open.getNestingExclusions()) {
+ for(final T exclusion : open.getNestingExclusions()) {
currentForbidden.add(exclusion);
whoForbid.put(exclusion, possibleOpen);
}
- } else if (!groupStack.empty() && groupStack.top().isClosing(tok)) {
+ } else if(!groupStack.empty() && groupStack.top().isClosing(tok)) {
/*
* Close the group.
*/
@@ -222,7 +221,7 @@ public class SequenceDelimiter<T> {
* Remove nested exclusions from this group.
*/
final Multiset<T> currentForbidden = forbiddenDelimiters.top();
- for (final T excludedGroup : closed.getNestingExclusions()) {
+ for(final T excludedGroup : closed.getNestingExclusions()) {
currentForbidden.remove(excludedGroup);
whoForbid.remove(excludedGroup);
@@ -232,18 +231,18 @@ public class SequenceDelimiter<T> {
* Remove the nested opens from this group.
*/
final Multimap<T, T> currentAllowed = allowedDelimiters.top();
- for (final Entry<T, T> closer : closed.getNestingOpeners().entrySet()) {
+ for(final Entry<T, T> closer : closed.getNestingOpeners().entrySet()) {
currentAllowed.remove(closer.getKey(), closer.getValue());
}
/*
* Handle 'forgetful' groups that reset nesting.
*/
- if (closed.isForgetful()) {
+ if(closed.isForgetful()) {
allowedDelimiters.drop();
forbiddenDelimiters.drop();
}
- } else if (!groupStack.empty() && groupStack.top().marksSubgroup(tok)) {
+ } else if(!groupStack.empty() && groupStack.top().marksSubgroup(tok)) {
/*
* Mark a subgroup.
*/
@@ -259,7 +258,7 @@ public class SequenceDelimiter<T> {
/*
* Error if not all groups were closed.
*/
- if (groupStack.size() > 1) {
+ if(groupStack.size() > 1) {
final DelimiterGroup<T>.OpenGroup group = groupStack.top();
final StringBuilder msgBuilder = new StringBuilder();
@@ -294,7 +293,7 @@ public class SequenceDelimiter<T> {
/*
* Check if a delimiter is locally forbidden.
*/
- if (groupStack.empty()) {
+ if(groupStack.empty()) {
localForbid = false;
} else {
localForbid = groupStack.top().excludes(groupName);
@@ -307,10 +306,10 @@ public class SequenceDelimiter<T> {
* Add a delimiter group.
*
* @param group
- * The delimiter group.
+ * The delimiter group.
*/
public void addGroup(final DelimiterGroup<T> group) {
- if (group == null) throw new NullPointerException("Group must not be null");
+ if(group == null) throw new NullPointerException("Group must not be null");
groups.put(group.groupName, group);
}
@@ -319,11 +318,11 @@ public class SequenceDelimiter<T> {
* Creates and adds a delimiter group using the provided settings.
*
* @param openers
- * The tokens that open this group
+ * The tokens that open this group
* @param groupName
- * The name of the group
+ * The name of the group
* @param closers
- * The tokens that close this group
+ * The tokens that close this group
*/
public void addGroup(final T[] openers, final T groupName, @SuppressWarnings("unchecked") final T... closers) {
final DelimiterGroup<T> group = new DelimiterGroup<>(groupName);
@@ -332,7 +331,7 @@ public class SequenceDelimiter<T> {
addGroup(group);
- for (final T open : openers) {
+ for(final T open : openers) {
group.addOpener(open, groupName);
}
}
@@ -343,13 +342,13 @@ public class SequenceDelimiter<T> {
builder.append("SequenceDelimiter [");
- if (groups != null) {
+ if(groups != null) {
builder.append("groups=");
builder.append(groups);
builder.append(",");
}
- if (initialGroup != null) {
+ if(initialGroup != null) {
builder.append("initialGroup=");
builder.append(initialGroup);
}
@@ -363,7 +362,7 @@ public class SequenceDelimiter<T> {
* Set the initial group of this delimiter.
*
* @param initialGroup
- * The initial group of this delimiter.
+ * The initial group of this delimiter.
*/
public void setInitialGroup(final DelimiterGroup<T> initialGroup) {
this.initialGroup = initialGroup;
diff --git a/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java b/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java
index e3eeea5..10c680c 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java
@@ -16,12 +16,12 @@ public class StringDelimiter extends SequenceDelimiter<String> {
* for ease of use for strings.
*
* @param seq
- * The sequence to delimit.
+ * The sequence to delimit.
*
* @return The sequence as a tree.
*
* @throws DelimiterException
- * if something went wrong with delimiting the sequence.
+ * if something went wrong with delimiting the sequence.
*
* @see SequenceDelimiter
*/
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/ChainTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/ChainTokenSplitter.java
index 4736310..db851f0 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/ChainTokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/ChainTokenSplitter.java
@@ -23,7 +23,7 @@ public class ChainTokenSplitter implements TokenSplitter {
* Append a series of splitters to the chain.
*
* @param splitters
- * The splitters to append to the chain.
+ * The splitters to append to the chain.
*/
public void appendSplitters(final TokenSplitter... splitters) {
spliters.addAll(splitters);
@@ -33,7 +33,7 @@ public class ChainTokenSplitter implements TokenSplitter {
* Prepend a series of splitters to the chain.
*
* @param splitters
- * The splitters to append to the chain.
+ * The splitters to append to the chain.
*/
public void prependSplitters(final TokenSplitter... splitters) {
spliters.prependAll(splitters);
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java
index 48ddcb4..556a2b1 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java
@@ -24,7 +24,7 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter {
* Create a new token splitter with blank configuration.
*
* @param keepDelims
- * Whether or not to keep delimiters.
+ * Whether or not to keep delimiters.
*/
public ConfigurableTokenSplitter(final boolean keepDelims) {
super(null, keepDelims);
@@ -43,10 +43,10 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter {
* Simple delimiters match one occurrence of themselves as literals.
*
* @param simpleDelims
- * The simple delimiters to add.
+ * The simple delimiters to add.
*/
public void addSimpleDelimiters(final String... simpleDelims) {
- for (final String simpleDelim : simpleDelims) {
+ for(final String simpleDelim : simpleDelims) {
simpleDelimiters.add(simpleDelim);
}
}
@@ -58,10 +58,10 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter {
* literals.
*
* @param multiDelims
- * The multiple delimiters to add.
+ * The multiple delimiters to add.
*/
public void addMultiDelimiters(final String... multiDelims) {
- for (final String multiDelim : multiDelims) {
+ for(final String multiDelim : multiDelims) {
multipleDelimiters.add(multiDelim);
}
}
@@ -73,10 +73,10 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter {
* expressions.
*
* @param rRawDelims
- * The raw delimiters to add.
+ * The raw delimiters to add.
*/
public void addRawDelimiters(final String... rRawDelims) {
- for (final String rRawDelim : rRawDelims) {
+ for(final String rRawDelim : rRawDelims) {
rRawDelimiters.add(rRawDelim);
}
}
@@ -88,15 +88,15 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter {
public void compile() {
final StringBuilder rPattern = new StringBuilder();
- for (final String rRawDelimiter : rRawDelimiters) {
+ for(final String rRawDelimiter : rRawDelimiters) {
rPattern.append(applyFormat("rawDelim", rRawDelimiter));
}
- for (final String multipleDelimiter : multipleDelimiters) {
+ for(final String multipleDelimiter : multipleDelimiters) {
rPattern.append(applyFormat("multipleDelim", multipleDelimiter));
}
- for (final String simpleDelimiter : simpleDelimiters) {
+ for(final String simpleDelimiter : simpleDelimiters) {
rPattern.append(applyFormat("simpleDelim", simpleDelimiter));
}
@@ -107,7 +107,7 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter {
@Override
public IList<String> split(final String input) {
- if (spliter == null) throw new IllegalStateException("Must compile splitter before use");
+ if(spliter == null) throw new IllegalStateException("Must compile splitter before use");
return super.split(input);
}
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java
index 369e7ae..7edba52 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java
@@ -24,7 +24,7 @@ public class ExcludingTokenSplitter implements TokenSplitter {
* Create a new excluding token splitter.
*
* @param splitter
- * The splitter to apply to non-excluded strings.
+ * The splitter to apply to non-excluded strings.
*/
public ExcludingTokenSplitter(final TokenSplitter splitter) {
spliter = splitter;
@@ -38,10 +38,10 @@ public class ExcludingTokenSplitter implements TokenSplitter {
* Exclude literal strings from splitting.
*
* @param exclusions
- * The strings to exclude from splitting.
+ * The strings to exclude from splitting.
*/
public final void addLiteralExclusions(final String... exclusions) {
- for (final String exclusion : exclusions) {
+ for(final String exclusion : exclusions) {
literalExclusions.add(exclusion);
}
}
@@ -51,21 +51,22 @@ public class ExcludingTokenSplitter implements TokenSplitter {
* splitting.
*
* @param exclusions
- * The predicates to use for exclusions.
+ * The predicates to use for exclusions.
*/
@SafeVarargs
public final void addPredicateExclusion(final Predicate<String>... exclusions) {
- for (final Predicate<String> exclusion : exclusions) {
+ for(final Predicate<String> exclusion : exclusions) {
predExclusions.add(exclusion);
}
}
@Override
public IList<String> split(final String input) {
- if (literalExclusions.contains(input))
+ if(literalExclusions.contains(input))
return new FunctionalList<>(input);
- else if (predExclusions.anyMatch(pred -> pred.test(input)))
+ else if(predExclusions.anyMatch(pred -> pred.test(input)))
return new FunctionalList<>(input);
- else return spliter.split(input);
+ else
+ return spliter.split(input);
}
}
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java
index 5d954e0..87d950b 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java
@@ -20,10 +20,10 @@ public class FilteredTokenSplitter implements TokenSplitter {
* Create a new filtered token splitter.
*
* @param source
- * The splitter to get tokens from.
+ * The splitter to get tokens from.
*
* @param filter
- * The filter to pass tokens through.
+ * The filter to pass tokens through.
*/
public FilteredTokenSplitter(TokenSplitter source, Predicate<String> filter) {
this.source = source;
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/SimpleTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/SimpleTokenSplitter.java
index c357886..c96f72a 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/SimpleTokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/SimpleTokenSplitter.java
@@ -21,10 +21,10 @@ public class SimpleTokenSplitter implements TokenSplitter {
* Create a new simple token splitter.
*
* @param splitter
- * The pattern to split around.
+ * The pattern to split around.
*
* @param keepDelims
- * Whether or not delimiters should be kept.
+ * Whether or not delimiters should be kept.
*/
public SimpleTokenSplitter(final Pattern splitter, final boolean keepDelims) {
spliter = splitter;
@@ -34,9 +34,10 @@ public class SimpleTokenSplitter implements TokenSplitter {
@Override
public IList<String> split(final String input) {
- if (keepDelim)
+ if(keepDelim)
return RegexStringEditor.mapOccurances(input, spliter, ID.id(), ID.id());
- else return RegexStringEditor.mapOccurances(input, spliter, ID.id(), strang -> "");
+ else
+ return RegexStringEditor.mapOccurances(input, spliter, ID.id(), strang -> "");
}
@Override
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitter.java
index ddb28a7..b042b8c 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitter.java
@@ -13,7 +13,7 @@ public interface TokenSplitter {
* Split a string into a list of pieces.
*
* @param input
- * The string to split.
+ * The string to split.
*
* @return The pieces of the string.
*/
diff --git a/base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java b/base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java
index 80490f5..1aa894d 100644
--- a/base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java
+++ b/base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java
@@ -20,10 +20,10 @@ public class TransformTokenSplitter implements TokenSplitter {
* Create a new transforming splitter.
*
* @param source
- * The splitter to use as a source.
+ * The splitter to use as a source.
*
* @param transform
- * The transform to apply to tokens.
+ * The transform to apply to tokens.
*/
public TransformTokenSplitter(TokenSplitter source, UnaryOperator<String> transform) {
this.source = source;