From d4ca769e542b2489b1e23cfcbdc3a0b7275b87cd Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Mon, 13 Apr 2020 18:40:41 -0400 Subject: Cleanup pass Cleanup pass to uniformize things --- .../java/bjc/utils/parserutils/DoubleMatcher.java | 15 +- .../java/bjc/utils/parserutils/IPrecedent.java | 2 +- .../bjc/utils/parserutils/ParserException.java | 6 +- .../java/bjc/utils/parserutils/ShuntingYard.java | 43 ++--- .../java/bjc/utils/parserutils/StringDescaper.java | 70 ++++---- .../bjc/utils/parserutils/TokenTransformer.java | 56 +++--- .../java/bjc/utils/parserutils/TokenUtils.java | 99 +++++------ .../bjc/utils/parserutils/TreeConstructor.java | 64 ++++--- .../utils/parserutils/defines/IteratedDefine.java | 10 +- .../utils/parserutils/defines/SimpleDefine.java | 4 +- .../parserutils/delims/DelimiterException.java | 2 +- .../utils/parserutils/delims/DelimiterGroup.java | 194 +++++++++++---------- .../bjc/utils/parserutils/delims/RegexCloser.java | 2 +- .../bjc/utils/parserutils/delims/RegexOpener.java | 8 +- .../delims/SequenceCharacteristics.java | 45 +++-- .../parserutils/delims/SequenceDelimiter.java | 138 +++++++-------- .../utils/parserutils/delims/StringDelimiter.java | 8 +- .../parserutils/splitter/ChainTokenSplitter.java | 8 +- .../splitter/ConfigurableTokenSplitter.java | 51 +++--- .../splitter/ExcludingTokenSplitter.java | 17 +- .../splitter/FilteredTokenSplitter.java | 10 +- .../parserutils/splitter/SimpleTokenSplitter.java | 9 +- .../utils/parserutils/splitter/TokenSplitter.java | 2 +- .../utils/parserutils/splitter/TokenSplitters.java | 19 +- .../splitter/TransformTokenSplitter.java | 10 +- 25 files changed, 461 insertions(+), 431 deletions(-) (limited to 'base/src/main/java/bjc/utils/parserutils') diff --git a/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java b/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java index 3618c50..1bf9b24 100644 --- a/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java +++ b/base/src/main/java/bjc/utils/parserutils/DoubleMatcher.java @@ -16,13 +16,16 @@ class DoubleMatcher { */ private static final String rDecDigits = getRegex("fpDigits"); private static final String rHexDigits = getRegex("fpHexDigits"); - private static final String rExponent = applyFormat("fpExponent", getRegex("fpExponent"), rDecDigits); + private static final String rExponent + = applyFormat("fpExponent", getRegex("fpExponent"), rDecDigits); /* * Decimal floating point numbers. */ - private static final String rSimpleDec = applyFormat("fpDecimalDecimal", rDecDigits, rExponent); - private static final String rSimpleIntDec = applyFormat("fpDecimalInteger", rDecDigits, rExponent); + private static final String rSimpleDec + = applyFormat("fpDecimalDecimal", rDecDigits, rExponent); + private static final String rSimpleIntDec + = applyFormat("fpDecimalInteger", rDecDigits, rExponent); /* * Hex floating point numbers. @@ -30,13 +33,15 @@ class DoubleMatcher { private static final String rHexInt = applyFormat("fpHexInteger", rHexDigits); private static final String rHexDec = applyFormat("fpHexDecimal", rHexDigits); private static final String rHexLead = applyFormat("fpHexLeader", rHexInt, rHexDec); - private static final String rHexString = applyFormat("fpHexString", rHexLead, rDecDigits); + private static final String rHexString + = applyFormat("fpHexString", rHexLead, rDecDigits); /* * 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 0deab5d..eb164b3 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 5e53a8b..e17e3c1 100644 --- a/base/src/main/java/bjc/utils/parserutils/ParserException.java +++ b/base/src/main/java/bjc/utils/parserutils/ParserException.java @@ -13,7 +13,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); @@ -23,9 +23,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 bf332f5..2418517 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -16,7 +16,7 @@ import bjc.utils.funcutils.StringUtils; * @author ben * * @param - * The type of tokens being shunted. + * The type of tokens being shunted. */ public class ShuntingYard { /** @@ -65,8 +65,8 @@ public class ShuntingYard { * 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<>(); @@ -86,10 +86,10 @@ public class ShuntingYard { * 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) { /* @@ -104,10 +104,10 @@ public class ShuntingYard { * 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) { /* @@ -115,7 +115,8 @@ public class ShuntingYard { */ 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 @@ -133,7 +134,8 @@ public class ShuntingYard { /* * If it doesn't, the left is higher precedence. */ - if (!exists) return false; + if (!exists) + return false; /* * Get the precedence of operators @@ -151,20 +153,22 @@ public class ShuntingYard { * 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. */ - public IList postfix(final IList input, final Function transformer) { + public IList postfix(final IList input, + final Function transformer) { /* * Check our input */ 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 @@ -182,8 +186,7 @@ public class ShuntingYard { */ if (operators.containsKey(token)) { /* - * Pop operators while there isn't a higher - * precedence one + * Pop operators while there isn't a higher precedence one */ while (!stack.isEmpty() && isHigherPrec(token, stack.peek())) { output.add(transformer.apply(stack.pop())); @@ -195,14 +198,12 @@ public class ShuntingYard { stack.push(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, "\\)")) { /* - * Handle groups of parenthesis for multiple - * nesting levels + * Handle groups of parenthesis for multiple nesting levels */ final String swappedToken = token.replace(')', '('); @@ -236,8 +237,8 @@ public class ShuntingYard { * 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) { /* diff --git a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java index 8d5dda4..0895ad5 100644 --- a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java +++ b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java @@ -12,8 +12,7 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; /** -<<<<<<< Updated upstream - * Customizable string escapes. + * <<<<<<< Updated upstream Customizable string escapes. * * @author Benjamin Culkin */ @@ -46,7 +45,8 @@ public class StringDescaper { specialEscapes = new HashMap<>(); /* Set up the hard-coded escapes. */ - rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)", rShortEscape, rOctalEscape, rUnicodeEscape); + rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)", rShortEscape, rOctalEscape, + rUnicodeEscape); escapePatt = Pattern.compile(rEscapeString); } @@ -54,12 +54,12 @@ public class StringDescaper { * Add a new literal escape. * * @param escape - * The custom escape to add. + * The custom escape to add. * @param val - * The value for the escape. + * The value for the escape. */ public void addLiteralEscape(String escape, String val) { - if(literalEscapes.containsKey(escape)) { + if (literalEscapes.containsKey(escape)) { LOGGER.warning(String.format("Shadowing literal escape '%s'\n", escape)); } @@ -68,11 +68,11 @@ public class StringDescaper { /** * Create a new custom escape. - * + * * @param escape - * The escape to add. + * The escape to add. * @param val - * The implementation of the escape. + * The implementation of the escape. */ public void addSpecialEscape(String escape, UnaryOperator val) { /* @@ -82,7 +82,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); @@ -91,7 +91,7 @@ public class StringDescaper { throw psex; } - if(specialEscapes.containsKey(patt)) { + if (specialEscapes.containsKey(patt)) { LOGGER.warning(String.format("Shadowing special escape '%s'\n", escape)); } @@ -104,24 +104,24 @@ public class StringDescaper { public void compileEscapes() { StringBuilder work = new StringBuilder(); - for(String litEscape : literalEscapes.keySet()) { + for (String litEscape : literalEscapes.keySet()) { work.append("|(?:"); work.append(Pattern.quote(litEscape)); work.append(")"); } - for(Pattern specEscape : specialEscapes.keySet()) { + for (Pattern specEscape : specialEscapes.keySet()) { work.append("|(?:"); work.append(specEscape.toString()); work.append(")"); } /* - * 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()); + rEscapeString = String.format("\\(%1$s|%2$s|%3$s%4$s)", rShortEscape, + rOctalEscape, rUnicodeEscape, work.toString()); escapePatt = Pattern.compile(rEscapeString); } @@ -129,13 +129,13 @@ public class StringDescaper { * 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"); } @@ -147,11 +147,10 @@ public class StringDescaper { final Matcher escapeFinder = escapePatt.matcher(inp); /* Go through each escape. */ - 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'", @@ -165,7 +164,7 @@ public class StringDescaper { * Convert the escape to a string. */ String escapeRep = ""; - switch(escapeSeq) { + switch (escapeSeq) { case "\\b": escapeRep = "\b"; break; @@ -195,22 +194,23 @@ public class StringDescaper { escapeRep = "\\"; break; default: - if(escapeSeq.startsWith("u")) { + if (escapeSeq.startsWith("u")) { /* Handle a unicode escape. */ escapeRep = handleUnicodeEscape(escapeSeq.substring(1)); - } else if(escapeSeq.startsWith("O")) { + } else if (escapeSeq.startsWith("O")) { /* Handle an octal escape. */ escapeRep = handleOctalEscape(escapeSeq.substring(1)); - } else if(literalEscapes.containsKey(escapeSeq)) { + } else if (literalEscapes.containsKey(escapeSeq)) { /* Handle a custom literal escape. */ escapeRep = literalEscapes.get(escapeSeq); } else { /* Handle a custom special escape. */ - for(Entry> ent : specialEscapes.entrySet()) { + for (Entry> ent : specialEscapes + .entrySet()) { Pattern pat = ent.getKey(); Matcher mat = pat.matcher(escapeSeq); - if(mat.matches()) { + if (mat.matches()) { escapeRep = ent.getValue().apply(escapeSeq); break; } @@ -234,8 +234,9 @@ public class StringDescaper { final int codepoint = Integer.parseInt(seq, 16); return new String(Character.toChars(codepoint)); - } catch(final IllegalArgumentException iaex) { - final String msg = String.format("'%s' is not a valid Unicode escape sequence'", seq); + } catch (final IllegalArgumentException iaex) { + final String msg + = String.format("'%s' is not a valid Unicode escape sequence'", seq); final IllegalArgumentException reiaex = new IllegalArgumentException(msg); @@ -252,7 +253,7 @@ public class StringDescaper { 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"); @@ -260,8 +261,9 @@ public class StringDescaper { } return new String(Character.toChars(codepoint)); - } catch(final IllegalArgumentException iaex) { - final String msg = String.format("'%s' is not a valid octal escape sequence'", seq); + } 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 7ad8b91..6cf2da5 100644 --- a/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java +++ b/base/src/main/java/bjc/utils/parserutils/TokenTransformer.java @@ -20,7 +20,8 @@ final class TokenTransformer implements Consumer { /* * Handle operators */ - private final class OperatorHandler implements UnaryOperator> { + private final class OperatorHandler + implements UnaryOperator> { /* The handled element. */ private final TokenType element; @@ -32,14 +33,14 @@ final class TokenTransformer implements Consumer { @Override public ConstructorState apply(final ConstructorState 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 -> handleOperator(queuedASTs))); + return new ConstructorState<>( + pair.bindLeft(queuedASTs -> handleOperator(queuedASTs))); } - private ConstructorState handleOperator(final Deque> queuedASTs) { + private ConstructorState + handleOperator(final Deque> queuedASTs) { /* * The AST we're going to hand back */ @@ -48,14 +49,13 @@ final class TokenTransformer implements Consumer { /* * 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()); @@ -67,7 +67,7 @@ final class TokenTransformer implements Consumer { * Grab the two operands */ final ITree right = queuedASTs.pop(); - final ITree left = queuedASTs.pop(); + final ITree left = queuedASTs.pop(); /* * Create a new AST @@ -94,27 +94,30 @@ final class TokenTransformer implements Consumer { private final Predicate operatorPredicate; /* The predicate for detecting special operators. */ - private final Predicate isSpecialOperator; + private final Predicate isSpecialOperator; /* The function for handling special operators. */ - private final Function> handleSpecialOperator; + private final Function> handleSpecialOperator; /** * Create a new transformer * * @param initialState - * The initial state of the transformer. + * The initial state of the transformer. * * @param operatorPredicate - * The predicate to use to identify operators. + * The predicate to use to identify operators. * * @param isSpecialOperator - * The predicate used to identify special operators. + * The predicate used to identify special + * operators. * * @param handleSpecialOperator - * The function used for handling special operators. + * The function used for handling special + * operators. */ public TokenTransformer(final IHolder> initialState, - final Predicate operatorPredicate, final Predicate isSpecialOperator, + final Predicate operatorPredicate, + final Predicate isSpecialOperator, final Function> handleSpecialOperator) { this.initialState = initialState; this.operatorPredicate = operatorPredicate; @@ -127,7 +130,7 @@ final class TokenTransformer implements Consumer { /* * Handle operators */ - if(operatorPredicate.test(element)) { + if (operatorPredicate.test(element)) { initialState.transform(new OperatorHandler(element)); } else { final ITree newAST = new Tree<>(element); @@ -135,18 +138,11 @@ final class TokenTransformer implements Consumer { /* * Insert the new tree into the AST */ - initialState.transform(pair -> { - /* - * 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); + initialState.transform(pair -> new ConstructorState<>(pair.bindLeft(queue -> { + queue.push(newAST); - return new Pair<>(queue, newAST); - })); - }); + return new Pair<>(queue, newAST); + }))); } } } diff --git a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java index fbffd82..7c3c2ab 100644 --- a/base/src/main/java/bjc/utils/parserutils/TokenUtils.java +++ b/base/src/main/java/bjc/utils/parserutils/TokenUtils.java @@ -21,9 +21,8 @@ import bjc.utils.parserutils.splitter.TokenSplitter; */ public class TokenUtils { /** - * Simple implementation of TokenSplitter for removing double-quoted - * strings. - * + * Simple implementation of TokenSplitter for removing double-quoted strings. + * * @author EVE * */ @@ -39,17 +38,17 @@ public class TokenUtils { */ /* Possible string escapes. */ - 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); /* Non-single char escapes. */ - 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"); /* All string escapes. */ - private static String rEscapeString = applyFormat("stringEscape", - rShortEscape, rOctalEscape, rUnicodeEscape); + private static String rEscapeString + = applyFormat("stringEscape", rShortEscape, rOctalEscape, rUnicodeEscape); private static Pattern escapePatt = Pattern.compile(rEscapeString); @@ -61,7 +60,7 @@ public class TokenUtils { private static Pattern quotePatt = getCompiledRegex("unescapedQuote"); /* This may do something. */ - //private static Pattern intLitPattern = getCompiledRegex("intLiteral"); + // private static Pattern intLitPattern = getCompiledRegex("intLiteral"); /** * Remove double quoted strings from a string. @@ -69,29 +68,29 @@ 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. + * @return An list containing alternating bits of the string and the embedded + * double-quoted strings that separated them. */ public static List removeDQuotedStrings(final String inp) { /* Validate input. */ - 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 */ - StringBuffer work = new StringBuffer(); + StringBuffer work = new StringBuffer(); final List res = new LinkedList<>(); /* * Matcher for proper strings and single quotes. */ - final Matcher mt = doubleQuotePatt.matcher(inp); + 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. */ @@ -110,8 +109,8 @@ public class TokenUtils { mt.appendReplacement(work, ""); /* - * Add the string preceding the double-quoted string and - * the double-quoted string to the list. + * Add the string preceding the double-quoted string and the double-quoted + * string to the list. */ res.add(work.toString()); res.add(mt.group(1)); @@ -128,10 +127,9 @@ 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. + * There's a unmatched opening quote with at least one string. */ final String msg = String.format( "Unclosed string literal '%s'. Opening quote was at position %d", inp, @@ -143,7 +141,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); } @@ -153,34 +151,35 @@ public class TokenUtils { /** * Replace escape characters with their actual equivalents. * - * Use {@link StringDescaper} for customizable escapes. This only handles the ones that are - * built into Java strings. + * Use {@link StringDescaper} for customizable escapes. This only handles the + * ones that are built into Java strings. * * @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) { /* Validate input. */ - 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. */ - final StringBuffer work = new StringBuffer(); + final StringBuffer work = new StringBuffer(); final Matcher possibleEscapeFinder = possibleEscapePatt.matcher(inp); - final Matcher escapeFinder = escapePatt.matcher(inp); + final Matcher escapeFinder = escapePatt.matcher(inp); /* Go through all possible escapes. */ 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", + final String msg = String.format( + "Illegal escape sequence '%s' at position %d", possibleEscapeFinder.group(), possibleEscapeFinder.start()); throw new IllegalArgumentException(msg); @@ -192,7 +191,7 @@ public class TokenUtils { * Convert the escape to a string. */ String escapeRep = ""; - switch(escapeSeq) { + switch (escapeSeq) { case "\\b": escapeRep = "\b"; break; @@ -247,8 +246,9 @@ public class TokenUtils { final int codepoint = Integer.parseInt(seq, 16); return new String(Character.toChars(codepoint)); - } catch(final IllegalArgumentException iaex) { - final String msg = String.format("'%s' is not a valid Unicode escape sequence'", seq); + } catch (final IllegalArgumentException iaex) { + final String msg + = String.format("'%s' is not a valid Unicode escape sequence'", seq); final IllegalArgumentException reiaex = new IllegalArgumentException(msg); @@ -265,7 +265,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"); @@ -273,8 +273,9 @@ public class TokenUtils { } return new String(Character.toChars(codepoint)); - } catch(final IllegalArgumentException iaex) { - final String msg = String.format("'%s' is not a valid octal escape sequence'", seq); + } catch (final IllegalArgumentException iaex) { + final String msg + = String.format("'%s' is not a valid octal escape sequence'", seq); final IllegalArgumentException reiaex = new IllegalArgumentException(msg); @@ -285,11 +286,11 @@ public class TokenUtils { } /** - * Check if a given string would be successfully converted to a double - * by {@link Double#parseDouble(String)}. + * Check if a given string would be successfully converted to a double 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) { @@ -297,21 +298,21 @@ public class TokenUtils { } /** - * Check if a given string would be successfully converted to a integer - * by {@link Integer#parseInt(String)}. + * Check if a given string would be successfully converted to a integer by + * {@link Integer#parseInt(String)}. * - * NOTE: This only checks syntax. Using values out of the range of - * integers will still cause errors. + * NOTE: This only checks syntax. Using values out of the range of 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 1ebc2d5..3c7509b 100644 --- a/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java +++ b/base/src/main/java/bjc/utils/parserutils/TreeConstructor.java @@ -23,21 +23,25 @@ public class TreeConstructor { * Alias interface for special operator types. * * @param - * The token type of the tree. + * The token type of the tree. */ - public interface QueueFlattener extends Function>, ITree> { + public interface QueueFlattener + extends Function>, ITree> { /* * Alias */ } /* Alias for constructor state. */ - static final class ConstructorState extends Pair>, ITree> { - public ConstructorState(final Deque> left, final ITree right) { + static final class ConstructorState + extends Pair>, ITree> { + public ConstructorState(final Deque> left, + final ITree right) { super(left, right); } - public ConstructorState(final IPair>, ITree> par) { + public ConstructorState( + final IPair>, ITree> par) { super(par.getLeft(), par.getRight()); } } @@ -48,19 +52,19 @@ public class TreeConstructor { * Only binary operators are accepted. * * @param - * 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 ITree constructTree(final IList tokens, - final Predicate isOperator) { + public static ITree constructTree( + final IList tokens, final Predicate isOperator) { /* Construct a tree with no special operators */ return constructTree(tokens, isOperator, op -> false, null); } @@ -68,43 +72,47 @@ public class TreeConstructor { /** * Construct a tree from a list of tokens in postfix notation. * - * Only binary operators are accepted by default. Use the last two - * parameters to handle non-binary operators. + * Only binary operators are accepted by default. Use the last two parameters to + * handle non-binary operators. * * @param - * 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. * */ - public static ITree constructTree(final IList tokens, - final Predicate isOperator, final Predicate isSpecialOperator, + public static ITree constructTree( + final IList tokens, final Predicate isOperator, + final Predicate isSpecialOperator, final Function> handleSpecialOperator) { /* * 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) - throw new NullPointerException("Special operator determiner must not be null"); + else if (isSpecialOperator == null) + throw new NullPointerException( + "Special operator determiner must not be null"); - final ConstructorState cstate = new ConstructorState<>( - new LinkedList<>(), null); + final ConstructorState cstate + = new ConstructorState<>(new LinkedList<>(), null); /* Here is the state for the tree construction */ final IHolder> initialState = new Identity<>(cstate); @@ -116,6 +124,6 @@ public class TreeConstructor { tokens.forEach(trans); /* Grab the tree from the state */ - return initialState.unwrap(pair -> pair.getRight()); + return initialState.unwrap(ConstructorState::getRight); } } diff --git a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java index a939971..2dad9c6 100644 --- a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java +++ b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java @@ -22,12 +22,12 @@ public class IteratedDefine implements UnaryOperator { * Create a new iterated define. * * @param pattern - * The pattern to use for matching. + * The pattern to use for matching. * @param circular - * Whether or not to loop through the list of replacers, or just - * repeat the last one. + * Whether or not to loop through the list of replacers, or + * just repeat the last one. * @param replacers - * The set of replacement strings to use. + * The set of replacement strings to use. */ public IteratedDefine(Pattern pattern, boolean circular, String... replacers) { patt = pattern; @@ -40,7 +40,7 @@ public class IteratedDefine implements UnaryOperator { Matcher mat = patt.matcher(ln); StringBuffer sb = new StringBuffer(); - while(mat.find()) { + while (mat.find()) { String repl = repls.next(); mat.appendReplacement(sb, repl); 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 032c33e..b31d937 100644 --- a/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java +++ b/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java @@ -17,9 +17,9 @@ public class SimpleDefine implements UnaryOperator { * Create a new simple define. * * @param pattern - * The pattern to match against. + * The pattern to match against. * @param replace - * The text to use as a replacement. + * The text to use as a replacement. */ 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 427b4cf..9c4d4bc 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java @@ -10,7 +10,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 96830b2..ba61531 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.funcdata.IList; * @author EVE * * @param - * The type of items in the sequence. + * The type of items in the sequence. */ public class DelimiterGroup { /** @@ -54,10 +54,10 @@ public class DelimiterGroup { * 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 { * 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 itm) { currentGroup.add(itm); @@ -82,33 +82,33 @@ public class DelimiterGroup { * 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 chars) { /* * Add all of the contents to the subgroup. */ final ITree subgroupContents = new Tree<>(chars.contents); - for(final ITree itm : currentGroup) { + for (final ITree itm : currentGroup) { subgroupContents.addChild(itm); } /* * Handle subordinate sub-groups. */ - while(!contents.isEmpty()) { + while (!contents.isEmpty()) { final ITree 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; @@ -118,7 +118,8 @@ public class DelimiterGroup { } } - final Tree subgroup = new Tree<>(chars.subgroup, subgroupContents, new Tree<>(marker)); + final Tree subgroup + = new Tree<>(chars.subgroup, subgroupContents, new Tree<>(marker)); contents.push(subgroup); @@ -129,10 +130,10 @@ public class DelimiterGroup { * 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,7 +141,7 @@ public class DelimiterGroup { /* * Mark any implied subgroups. */ - if(impliedSubgroups.containsKey(closer)) { + if (impliedSubgroups.containsKey(closer)) { markSubgroup(impliedSubgroups.get(closer), chars); } @@ -148,13 +149,13 @@ public class DelimiterGroup { final ITree res = new Tree<>(chars.contents); /* - * Add either the contents of the current group, or - * subgroups if they're there. + * Add either the contents of the current group, or subgroups if they're + * there. */ - if(contents.isEmpty()) { + if (contents.isEmpty()) { currentGroup.forEach(res::addChild); } else { - while(!contents.isEmpty()) { + while (!contents.isEmpty()) { res.prependChild(contents.poll()); } @@ -183,7 +184,7 @@ public class DelimiterGroup { * 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. */ @@ -195,16 +196,17 @@ public class DelimiterGroup { * 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. + * @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 pred : predClosers) { - if(pred.test(del, params)) return true; + for (final BiPredicate pred : predClosers) { + if (pred.test(del, params)) + return true; } return closingDelimiters.contains(del); @@ -229,11 +231,9 @@ public class DelimiterGroup { } /** - * Get the groups that are allowed to open anywhere inside this - * group. + * Get the groups that are allowed to open anywhere inside this group. * - * @return The groups allowed to open anywhere inside this - * group. + * @return The groups allowed to open anywhere inside this group. */ public Map getNestingOpeners() { return nestedOpenDelimiters; @@ -243,7 +243,7 @@ public class DelimiterGroup { * 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. */ @@ -255,18 +255,19 @@ public class DelimiterGroup { * 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. + * @return The name of the group T opens, or null if it doesn't open one. */ public IPair 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> pred : predOpeners) { + for (final Function> pred : predOpeners) { final IPair par = pred.apply(marker); - if(par.getLeft() != null) return par; + if (par.getLeft() != null) + return par; } return new Pair<>(null, null); @@ -303,8 +304,7 @@ public class DelimiterGroup { private final Set groupExclusions; /* - * Mapping from sub-group delimiters, to any sub-groups enclosed in - * them. + * Mapping from sub-group delimiters, to any sub-groups enclosed in them. */ private final Map subgroups; @@ -324,10 +324,11 @@ public class DelimiterGroup { * 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; @@ -350,22 +351,22 @@ public class DelimiterGroup { * 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 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 - * type. + * We can do this because equals works on arbitrary objects, not just + * those of the same type. */ - throw new IllegalArgumentException("Empty string is not a valid exclusion"); + throw new IllegalArgumentException( + "Empty string is not a valid exclusion"); } else { closingDelimiters.add(closer); } @@ -373,24 +374,23 @@ public class DelimiterGroup { } /** - * Adds one or more groups that cannot occur in the top level of this - * group. + * Adds one or more groups that cannot occur in the top level of this 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 - * type. + * We can do this because equals works on arbitrary objects, not just + * those of the same type. */ - throw new IllegalArgumentException("Empty string is not a valid exclusion"); + throw new IllegalArgumentException( + "Empty string is not a valid exclusion"); } else { topLevelExclusions.add(exclusion); } @@ -401,20 +401,20 @@ public class DelimiterGroup { * 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 - * type. + * We can do this because equals works on arbitrary objects, not just + * those of the same type. */ - throw new IllegalArgumentException("Empty string is not a valid exclusion"); + throw new IllegalArgumentException( + "Empty string is not a valid exclusion"); } else { groupExclusions.add(exclusion); } @@ -425,13 +425,14 @@ public class DelimiterGroup { * 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); } @@ -440,15 +441,16 @@ public class DelimiterGroup { * 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) + 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"); + else if (group == null) + throw new NullPointerException("Group to open must not be null"); openDelimiters.put(opener, group); } @@ -457,15 +459,15 @@ public class DelimiterGroup { * 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) { + if (opener == null) { throw new NullPointerException("Opener must not be null"); - } else if(group == null) { + } else if (group == null) { throw new NullPointerException("Group to open must not be null"); } @@ -476,20 +478,22 @@ public class DelimiterGroup { * 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) { + if (closer == null) { throw new NullPointerException("Closer must not be null"); - } else if(subgroup == 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)); + } 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); @@ -506,26 +510,26 @@ public class DelimiterGroup { 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); @@ -541,10 +545,10 @@ public class DelimiterGroup { * 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. */ @@ -556,7 +560,7 @@ public class DelimiterGroup { * 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> pred) { predOpeners.add(pred); @@ -566,7 +570,7 @@ public class DelimiterGroup { * 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 pred) { predClosers.add(pred); @@ -576,7 +580,7 @@ public class DelimiterGroup { * 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 a3c831e..8cc08ad 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java @@ -16,7 +16,7 @@ public class RegexCloser implements BiPredicate { * 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 64dc81c..f08201c 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java @@ -23,10 +23,10 @@ public class RegexOpener implements Function> { * 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; @@ -38,12 +38,12 @@ public class RegexOpener implements Function> { public IPair 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 9e4c167..e48e341 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 - * The type of item in the tree. + * The type of item in the tree. */ public class SequenceCharacteristics { /** @@ -29,11 +29,11 @@ public class SequenceCharacteristics { * 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,32 @@ public class SequenceCharacteristics { @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(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 (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 (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 7424770..3e87abe 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 - * The type of items in the sequence. + * The type of items in the sequence. */ public class SequenceDelimiter { /* Mapping from group names to actual groups. */ @@ -39,11 +39,10 @@ public class SequenceDelimiter { } /** - * Convert a linear sequence into a tree that matches the delimiter - * structure. + * Convert a linear sequence into a tree that matches the delimiter structure. * - * Essentially, creates a parse tree of the expression against the - * following grammar while obeying the defined grouping rules. + * Essentially, creates a parse tree of the expression against the following + * grammar while obeying the defined grouping rules. * *
 	 *              → ( |  | )*
@@ -57,39 +56,37 @@ public class SequenceDelimiter {
 	 * 
* * @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 - * group node. + * @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 group node. * - * A data node is a leaf node whose data is the string it - * represents. + * A data node is a leaf node whose data is the string it represents. * - * A subgroup node is a node with two children, and the name of - * the sub-group as its label. The first child is the contents - * of the sub-group, and the second is the marker that started - * the subgroup. The marker is a leaf node labeled with its - * contents, and the contents contains a recursive tree. + * A subgroup node is a node with two children, and the name of the + * sub-group as its label. The first child is the contents of the + * sub-group, and the second is the marker that started the subgroup. + * The marker is a leaf node labeled with its contents, and the contents + * contains a recursive tree. * - * A group node is a node with three children, and the name of - * the group as its label. The first child is the opening - * delimiter, the second is the group contents, and the third is - * the closing delimiter. The delimiters are leaf nodes labeled - * with their contents, while the group node contains a - * recursive tree. + * A group node is a node with three children, and the name of the group + * as its label. The first child is the opening delimiter, the second is + * the group contents, and the third is the closing delimiter. The + * delimiters are leaf nodes labeled with their contents, while the + * group node contains a recursive tree. * * @throws DelimiterException - * Thrown if something went wrong during sequence delimitation. + * Thrown if something went wrong during sequence + * delimitation. * */ public ITree delimitSequence(final SequenceCharacteristics chars, @SuppressWarnings("unchecked") final T... seq) throws DelimiterException { - if(initialGroup == null) { + if (initialGroup == null) { throw new NullPointerException("Initial group must be specified."); - } else if(chars == null) { + } else if (chars == null) { throw new NullPointerException("Sequence characteristics must not be null"); } @@ -113,21 +110,20 @@ public class SequenceDelimiter { /* * 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]; /* Check if this token could open a group. */ final IPair 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. + * 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(); } } @@ -135,59 +131,61 @@ public class SequenceDelimiter { /* * If we have an opening delimiter, handle it. */ - if(possibleOpen != null) { + if (possibleOpen != null) { final DelimiterGroup group = groups.get(possibleOpen); /* - * Error on groups that can't open in this - * context. + * Error on groups that can't open in this context. * - * This means groups that can't occur at the - * top-level of this group, as well as nested - * exclusions from all enclosing groups. + * This means groups that can't occur at the 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(); } - final String ctxList = StringUtils.toEnglishList(groupStack.toArray(), "then"); + final String ctxList + = StringUtils.toEnglishList(groupStack.toArray(), "then"); - final String fmt = "Group '%s' can't be opened in this context. (forbidden by '%s')\nContext Stack: %s"; + final String fmt + = "Group '%s' can't be opened in this context. (forbidden by '%s')\nContext Stack: %s"; - throw new DelimiterException(String.format(fmt, group, forbiddenBy, ctxList)); + throw new DelimiterException( + String.format(fmt, group, forbiddenBy, ctxList)); } /* Add an open group. */ - final DelimiterGroup.OpenGroup open = group.open(tok, possibleOpenPar.getRight()); + final DelimiterGroup.OpenGroup open + = group.open(tok, possibleOpenPar.getRight()); groupStack.push(open); /* * Handle 'forgetful' groups that reset nesting */ - if(open.isForgetful()) { + if (open.isForgetful()) { allowedDelimiters.push(HashMultimap.create()); forbiddenDelimiters.push(HashMultiset.create()); } /* Add the nested opens from this group. */ final Multimap currentAllowed = allowedDelimiters.top(); - for(final Entry opener : open.getNestingOpeners().entrySet()) { + for (final Entry opener : open.getNestingOpeners().entrySet()) { currentAllowed.put(opener.getKey(), opener.getValue()); } /* Add the nested exclusions from this group */ final Multiset 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.isEmpty() && groupStack.top().isClosing(tok)) { + } else if (!groupStack.isEmpty() && groupStack.top().isClosing(tok)) { /* * Close the group. */ @@ -197,7 +195,7 @@ public class SequenceDelimiter { /* Remove nested exclusions from this group. */ final Multiset currentForbidden = forbiddenDelimiters.top(); - for(final T excludedGroup : closed.getNestingExclusions()) { + for (final T excludedGroup : closed.getNestingExclusions()) { currentForbidden.remove(excludedGroup); whoForbid.remove(excludedGroup); @@ -205,18 +203,18 @@ public class SequenceDelimiter { /* Remove the nested opens from this group. */ final Multimap currentAllowed = allowedDelimiters.top(); - for(final Entry closer : closed.getNestingOpeners().entrySet()) { + for (final Entry 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.isEmpty() && groupStack.top().marksSubgroup(tok)) { + } else if (!groupStack.isEmpty() && groupStack.top().marksSubgroup(tok)) { /* * Mark a subgroup. */ @@ -230,17 +228,20 @@ public class SequenceDelimiter { /* * Error if not all groups were closed. */ - if(groupStack.size() > 1) { + if (groupStack.size() > 1) { final DelimiterGroup.OpenGroup group = groupStack.top(); - final String closingDelims = StringUtils.toEnglishList(group.getNestingExclusions().toArray(), - false); + final String closingDelims = StringUtils + .toEnglishList(group.getNestingExclusions().toArray(), false); - final String ctxList = StringUtils.toEnglishList(groupStack.toArray(), "then"); + final String ctxList + = StringUtils.toEnglishList(groupStack.toArray(), "then"); - final String fmt = "Unclosed group '%s'. Expected one of %s to close it.\nOpen groups: %n"; + final String fmt + = "Unclosed group '%s'. Expected one of %s to close it.\nOpen groups: %n"; - throw new DelimiterException(String.format(fmt, group.getName(), closingDelims, ctxList)); + throw new DelimiterException( + String.format(fmt, group.getName(), closingDelims, ctxList)); } return groupStack.pop().toTree(chars.root, chars); @@ -254,7 +255,7 @@ public class SequenceDelimiter { /* * Check if a delimiter is locally forbidden. */ - if(groupStack.isEmpty()) { + if (groupStack.isEmpty()) { localForbid = false; } else { localForbid = groupStack.top().excludes(groupName); @@ -267,10 +268,10 @@ public class SequenceDelimiter { * Add a delimiter group. * * @param group - * The delimiter group. + * The delimiter group. */ public void addGroup(final DelimiterGroup group) { - if(group == null) { + if (group == null) { throw new NullPointerException("Group must not be null"); } @@ -281,20 +282,21 @@ public class SequenceDelimiter { * 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) { + public void addGroup(final T[] openers, final T groupName, + @SuppressWarnings("unchecked") final T... closers) { final DelimiterGroup group = new DelimiterGroup<>(groupName); group.addClosing(closers); addGroup(group); - for(final T open : openers) { + for (final T open : openers) { group.addOpener(open, groupName); } } @@ -305,13 +307,13 @@ public class SequenceDelimiter { 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); } @@ -325,7 +327,7 @@ public class SequenceDelimiter { * 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 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 1f8f166..6035ede 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/StringDelimiter.java @@ -16,16 +16,18 @@ public class StringDelimiter extends SequenceDelimiter { * 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 */ public ITree delimitSequence(final String... seq) throws DelimiterException { - return super.delimitSequence(new SequenceCharacteristics<>("root", "contents", "subgroup"), seq); + return super.delimitSequence( + new SequenceCharacteristics<>("root", "contents", "subgroup"), seq); } } 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 a5a044a..0844b5b 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); @@ -43,8 +43,6 @@ public class ChainTokenSplitter implements TokenSplitter { public IList split(final String input) { final IList initList = new FunctionalList<>(input); - return spliters.reduceAux(initList, (splitter, strangs) -> { - return strangs.flatMap(splitter::split); - }); + return spliters.reduceAux(initList, (splitter, strangs) -> strangs.flatMap(splitter::split)); } } \ No newline at end of file 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 603c214..16c1dc3 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java @@ -16,15 +16,15 @@ import bjc.funcdata.IList; * */ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { - private final Set simpleDelimiters; - private final Set multipleDelimiters; - private final Set rRawDelimiters; + private final Set simpleDelimiters; + private final Set multipleDelimiters; + private final Set rRawDelimiters; /** * 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); @@ -50,7 +50,7 @@ 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) { @@ -61,11 +61,10 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Add a set of multiple delimiters to this splitter. * - * Multiple delimiters match one or more occurrences of themselves as - * literals. + * Multiple delimiters match one or more occurrences of themselves as literals. * * @param multiDelims - * The multiple delimiters to add. + * The multiple delimiters to add. */ public void addMultiDelimiters(final String... multiDelims) { for (final String multiDelim : multiDelims) { @@ -76,11 +75,10 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Add a set of raw delimiters to this splitter. * - * Raw delimiters match one occurrence of themselves as regular - * expressions. + * Raw delimiters match one occurrence of themselves as regular expressions. * * @param rRawDelims - * The raw delimiters to add. + * The raw delimiters to add. */ public void addRawDelimiters(final String... rRawDelims) { for (final String rRawDelim : rRawDelims) { @@ -89,8 +87,8 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { } /** - * Take the configuration and compile it into a regular expression to - * use when splitting. + * Take the configuration and compile it into a regular expression to use when + * splitting. */ public void compile() { final StringBuilder rPattern = new StringBuilder(); @@ -114,22 +112,25 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { @Override public IList 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); } @Override public String toString() { - final String fmt = "ConfigurableTokenSplitter [simpleDelimiters=%s, multipleDelimiters=%s," - + " rRawDelimiters=%s, spliter=%s]"; + final String fmt + = "ConfigurableTokenSplitter [simpleDelimiters=%s, multipleDelimiters=%s," + + " rRawDelimiters=%s, spliter=%s]"; - return String.format(fmt, simpleDelimiters, multipleDelimiters, rRawDelimiters, spliter); + return String.format(fmt, simpleDelimiters, multipleDelimiters, rRawDelimiters, + spliter); } /** * Builder class for the configurable token splitter. - * + * * @author bjculkin * */ @@ -138,9 +139,9 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Create a new splitter builder. - * + * * @param keepDelims - * Whether or not to keep the delimited splitter. + * Whether or not to keep the delimited splitter. */ public Builder(boolean keepDelims) { cts = new ConfigurableTokenSplitter(keepDelims); @@ -148,7 +149,7 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Add a set of simple delimiters. - * + * * @param strings * The simple delimiters to use. * @return The builder, for chaining. @@ -161,7 +162,7 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Add a set of multiple delimiters. - * + * * @param strings * The multiple delimiters to use. * @return The builder, for chaining. @@ -174,7 +175,7 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Add a set of raw delimiters. - * + * * @param strings * The raw delimiters to use. * @return The builder, for chaining. @@ -187,14 +188,14 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { /** * Build the splitter. - * + * * @return The built splitter. */ public ConfigurableTokenSplitter build() { ConfigurableTokenSplitter ret = new ConfigurableTokenSplitter(cts.keepDelim, cts.simpleDelimiters, cts.multipleDelimiters, cts.rRawDelimiters); ret.compile(); - + return ret; } } 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 8bdb176..9a0cd65 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java @@ -23,7 +23,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; @@ -37,33 +37,32 @@ 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); } } /** - * Exclude all of the strings matching any of the predicates from - * splitting. + * Exclude all of the strings matching any of the predicates from splitting. * * @param exclusions - * The predicates to use for exclusions. + * The predicates to use for exclusions. */ @SafeVarargs public final void addPredicateExclusion(final Predicate... exclusions) { - for(final Predicate exclusion : exclusions) { + for (final Predicate exclusion : exclusions) { predExclusions.add(exclusion); } } @Override public IList 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); 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 3bcbea2..85d72e2 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/FilteredTokenSplitter.java @@ -7,7 +7,7 @@ import bjc.funcdata.IList; /** * A token splitter that removes tokens that match a predicate from the stream * of tokens. - * + * * @author bjculkin * */ @@ -18,12 +18,12 @@ 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 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 8f4fb6c..43793e3 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,7 +34,7 @@ public class SimpleTokenSplitter implements TokenSplitter { @Override public IList split(final String input) { - if(keepDelim) { + if (keepDelim) { return RegexStringEditor.mapOccurances(input, spliter, ID.id(), ID.id()); } @@ -43,6 +43,7 @@ public class SimpleTokenSplitter implements TokenSplitter { @Override public String toString() { - return String.format("SimpleTokenSplitter [spliter=%s, keepDelim=%s]", spliter, keepDelim); + return String.format("SimpleTokenSplitter [spliter=%s, keepDelim=%s]", spliter, + keepDelim); } } 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 f2d9c73..59e73e8 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/TokenSplitters.java b/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitters.java index c8827b6..15d6b8b 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitters.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitters.java @@ -4,16 +4,16 @@ import java.util.function.UnaryOperator; /** * Factory methods for producing token splitters. - * + * * @author student * */ public class TokenSplitters { /** * Create a new chained token splitter. - * + * * @param splitters - * The series of splitters to chain together. + * The series of splitters to chain together. * @return A chained-together series of splitters. */ public static TokenSplitter chainSplitter(final TokenSplitter... splitters) { @@ -26,16 +26,17 @@ public class TokenSplitters { /** * Create a new transforming token splitter. - * + * * @param splitter - * The splitter to gain tokens from - * + * The splitter to gain tokens from + * * @param transform - * The transform to apply to the strings. - * + * The transform to apply to the strings. + * * @return A splitter that applies the chosen transform to the tokens. */ - public static TokenSplitter transformSplitter(final TokenSplitter splitter, UnaryOperator transform) { + public static TokenSplitter transformSplitter(final TokenSplitter splitter, + UnaryOperator transform) { return new TransformTokenSplitter(splitter, transform); } } 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 3cbe103..b9fbedc 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/TransformTokenSplitter.java @@ -7,7 +7,7 @@ import bjc.funcdata.IList; /** * A token splitter that performs a transform on the tokens from another * splitter. - * + * * @author bjculkin * */ @@ -18,12 +18,12 @@ 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 transform) { this.source = source; -- cgit v1.2.3