From 2d8f0aba5565b292f17695afd276143a4f71c72b Mon Sep 17 00:00:00 2001 From: "Benjamin J. Culkin" Date: Tue, 13 Feb 2018 20:52:37 -0400 Subject: Update --- .../utils/ioutils/blocks/SimpleBlockReader.java | 5 +- .../utils/ioutils/blocks/ToggledBlockReader.java | 4 +- .../bjc/utils/parserutils/ParserException.java | 5 +- .../java/bjc/utils/parserutils/ShuntingYard.java | 7 +- .../java/bjc/utils/parserutils/StringDescaper.java | 49 +++++----- .../utils/parserutils/defines/IteratedDefine.java | 7 +- .../utils/parserutils/defines/SimpleDefine.java | 11 +-- .../parserutils/delims/DelimiterException.java | 5 +- .../utils/parserutils/delims/DelimiterGroup.java | 103 ++++++++++----------- .../bjc/utils/parserutils/delims/RegexCloser.java | 3 +- .../bjc/utils/parserutils/delims/RegexOpener.java | 3 +- .../parserutils/delims/SequenceDelimiter.java | 91 ++++++------------ .../splitter/ConfigurableTokenSplitter.java | 14 ++- .../splitter/ExcludingTokenSplitter.java | 3 +- 14 files changed, 129 insertions(+), 181 deletions(-) (limited to 'base/src/main/java') diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java index 6536d0c..4b7f76b 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/SimpleBlockReader.java @@ -9,7 +9,7 @@ import java.util.regex.Pattern; import bjc.utils.funcutils.StringUtils; /** - * Simple implementation of {@link BlockReader} + * Simple implementation of {@link BlockReader}. * * NOTE: The EOF marker is always treated as a delimiter. You are expected to * handle blocks that may be shorter than you expect. @@ -71,8 +71,9 @@ public class SimpleBlockReader implements BlockReader { /* * Read in a new block, and keep the line numbers sane. */ - final int blockStartLine = lineNo; final String blockContents = blockReader.next(); + + final int blockStartLine = lineNo; final int blockEndLine = lineNo + StringUtils.countMatches(blockContents, "\\R"); lineNo = blockEndLine; diff --git a/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java b/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java index 0b756c5..91952fc 100644 --- a/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java +++ b/base/src/main/java/bjc/utils/ioutils/blocks/ToggledBlockReader.java @@ -14,9 +14,7 @@ public class ToggledBlockReader implements BlockReader { private BlockReader leftSource; private BlockReader rightSource; - /* - * We choose the left source when this is true. - */ + /* We choose the left source when this is true. */ private BooleanToggle leftToggle; private int blockNo; diff --git a/base/src/main/java/bjc/utils/parserutils/ParserException.java b/base/src/main/java/bjc/utils/parserutils/ParserException.java index 72e8ac4..5e53a8b 100644 --- a/base/src/main/java/bjc/utils/parserutils/ParserException.java +++ b/base/src/main/java/bjc/utils/parserutils/ParserException.java @@ -7,9 +7,6 @@ package bjc.utils.parserutils; * */ public class ParserException extends Exception { - /** - * - */ private static final long serialVersionUID = 631298568113373233L; /** @@ -33,4 +30,4 @@ public class ParserException extends Exception { public ParserException(final String msg, final Exception cause) { super(msg, cause); } -} \ No newline at end of file +} diff --git a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java index a0b1249..352ad04 100644 --- a/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java +++ b/base/src/main/java/bjc/utils/parserutils/ShuntingYard.java @@ -181,7 +181,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 @@ -189,6 +190,7 @@ public class ShuntingYard { operators.put(operator, precedence); } + /* Check if one operator is higher precedence than another. */ private boolean isHigherPrec(final String left, final String right) { /* * Check if the right operator exists @@ -229,7 +231,8 @@ public class ShuntingYard { */ 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 diff --git a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java index 0beb7c8..c995396 100644 --- a/base/src/main/java/bjc/utils/parserutils/StringDescaper.java +++ b/base/src/main/java/bjc/utils/parserutils/StringDescaper.java @@ -13,10 +13,9 @@ import static java.util.Map.Entry; import static bjc.utils.PropertyDB.getRegex; /** - * Customizable string descaping. - * - * @author EVE + * Customizable string escapes. * + * @author Benjamin Culkin */ public class StringDescaper { private Logger LOGGER = Logger.getLogger(StringDescaper.class.getName()); @@ -34,33 +33,30 @@ public class StringDescaper { 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); - //private static Pattern doubleQuotePatt = Pattern.compile(rDoubleQuoteString); - - //private static Pattern quotePatt = getCompiledRegex("unescapedQuote"); - - private Map literalEscapes; - private Map> specialEscapes; - + private Map literalEscapes; + private Map> specialEscapes; + /** - * Create a new string descaper. + * Create a new customizable string escape remover. */ public StringDescaper() { + /* Setup the escape maps. */ literalEscapes = new HashMap<>(); specialEscapes = new HashMap<>(); - rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)"); - escapePatt = Pattern.compile(rEscapeString); + /* Set up the hard-coded escapes. */ + rEscapeString = String.format("\\\\(%1$s|%2$s|%3$s)", + rShortEscape, rOctalEscape, rUnicodeEscape); + escapePatt = Pattern.compile(rEscapeString); } /** - * Add a new literal string escape. - * + * Add a new literal escape. + * * @param escape - * The 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)) { @@ -146,12 +142,13 @@ public class StringDescaper { /* * 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); - while(possibleEscapeFinder.find()) { - if(!escapeFinder.find()) { + /* Go through each escape. */ + while (possibleEscapeFinder.find()) { + if (!escapeFinder.find()) { /* * Found a possible escape that isn't actually * an escape. @@ -198,13 +195,17 @@ 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")) { + /* Handle an octal escape. */ escapeRep = handleOctalEscape(escapeSeq.substring(1)); } 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()) { Pattern pat = ent.getKey(); 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 83ef8a8..6d1ed64 100644 --- a/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java +++ b/base/src/main/java/bjc/utils/parserutils/defines/IteratedDefine.java @@ -9,10 +9,9 @@ import java.util.regex.Pattern; import bjc.utils.data.CircularIterator; /** - * A define that has a set of replacements to use. - * - * @author EVE + * An iterated find/replace, using a circular assortment of replacements. * + * @author Ben Culkin */ public class IteratedDefine implements UnaryOperator { private Pattern patt; @@ -28,7 +27,7 @@ public class IteratedDefine implements UnaryOperator { * Whether or not to loop through the list of replacers, or just * repeat the last one. * @param replacers - * The set of replacers to use. + * The set of replacement strings to use. */ public IteratedDefine(Pattern pattern, boolean circular, String... replacers) { patt = pattern; 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 d42f7d8..c3496a8 100644 --- a/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java +++ b/base/src/main/java/bjc/utils/parserutils/defines/SimpleDefine.java @@ -5,10 +5,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; /** - * A simple match-and-replace operation on strings. - * - * @author EVE + * A simple implementation of a find/replace operator on a string. * + * @author Ben Culkin */ public class SimpleDefine implements UnaryOperator { private Pattern patt; @@ -16,11 +15,11 @@ public class SimpleDefine implements UnaryOperator { /** * Create a new simple define. - * + * * @param pattern - * The pattern to look for. + * The pattern to match against. * @param replace - * The thing to replace it with. + * 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 4172d32..427b4cf 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterException.java @@ -4,9 +4,6 @@ package bjc.utils.parserutils.delims; * The superclass for exceptions thrown during sequence delimitation. */ public class DelimiterException extends RuntimeException { - /** - * - */ private static final long serialVersionUID = 2079514406049040888L; /** @@ -18,4 +15,4 @@ public class DelimiterException extends RuntimeException { public DelimiterException(final String res) { super(res); } -} \ No newline at end of file +} 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 5d020a6..0fe998d 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java @@ -144,11 +144,12 @@ public class DelimiterGroup { markSubgroup(impliedSubgroups.get(closer), chars); } + /* The resulting tree. */ final ITree 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 there. */ if(contents.isEmpty()) { currentGroup.forEach(res::addChild); @@ -260,12 +261,14 @@ public class DelimiterGroup { * 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) { final IPair par = pred.apply(marker); - if(par.getLeft() != null) return par; + if (par.getLeft() != null) + return par; } return new Pair<>(null, null); @@ -286,29 +289,19 @@ public class DelimiterGroup { */ public final T groupName; - /* - * The delimiters that open groups at the top level of this group. - */ + /* The delimiters that open groups at the top level of this group. */ private final Map openDelimiters; - /* - * The delimiters that open groups inside of this group. - */ + /* The delimiters that open groups inside of this group. */ private final Map nestedOpenDelimiters; - /* - * The delimiters that close this group. - */ + /* The delimiters that close this group. */ private final Set closingDelimiters; - /* - * The groups that can't occur in the top level of this group. - */ + /* The groups that can't occur in the top level of this group. */ private final Set topLevelExclusions; - /* - * The groups that can't occur anywhere inside this group. - */ + /* The groups that can't occur anywhere inside this group. */ private final Set groupExclusions; /* @@ -317,24 +310,16 @@ public class DelimiterGroup { */ private final Map subgroups; - /* - * Subgroups implied by a particular closing delimiter - */ + /* Subgroups implied by a particular closing delimiter */ private final Map impliedSubgroups; - /* - * Allows more complex openings - */ + /* Allows more complex openings */ private final List>> predOpeners; - /* - * Allow more complex closings - */ + /* Allow more complex closings */ private final List> predClosers; - /* - * Whether or not this group starts a new nesting set. - */ + /* Whether or not this group starts a new nesting set. */ private boolean forgetful; /** @@ -344,19 +329,20 @@ public class DelimiterGroup { * 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; - openDelimiters = new HashMap<>(); + openDelimiters = new HashMap<>(); nestedOpenDelimiters = new HashMap<>(); closingDelimiters = new HashSet<>(); topLevelExclusions = new HashSet<>(); - groupExclusions = new HashSet<>(); + groupExclusions = new HashSet<>(); - subgroups = new HashMap<>(); + subgroups = new HashMap<>(); impliedSubgroups = new HashMap<>(); predOpeners = new LinkedList<>(); @@ -373,17 +359,17 @@ public class DelimiterGroup { 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. */ throw new IllegalArgumentException("Empty string is not a valid exclusion"); - else { + } else { closingDelimiters.add(closer); } } @@ -398,17 +384,17 @@ public class DelimiterGroup { */ @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. */ throw new IllegalArgumentException("Empty string is not a valid exclusion"); - else { + } else { topLevelExclusions.add(exclusion); } } @@ -422,17 +408,17 @@ public class DelimiterGroup { */ @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. */ throw new IllegalArgumentException("Empty string is not a valid exclusion"); - else { + } else { groupExclusions.add(exclusion); } } @@ -448,7 +434,8 @@ public class DelimiterGroup { * 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); } @@ -463,9 +450,10 @@ public class DelimiterGroup { * 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); } @@ -480,9 +468,11 @@ public class DelimiterGroup { * 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) throw new NullPointerException("Group to open must not be null"); + } else if (group == null) { + throw new NullPointerException("Group to open must not be null"); + } nestedOpenDelimiters.put(opener, group); } @@ -497,14 +487,15 @@ public class DelimiterGroup { * 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)) + } else if (!closingDelimiters.contains(closer)) { throw new IllegalArgumentException(String.format("No closing delimiter '%s' defined", closer)); - else if(!subgroups.containsKey(subgroup)) + } else if (!subgroups.containsKey(subgroup)) { throw new IllegalArgumentException(String.format("No subgroup '%s' defined", subgroup)); + } impliedSubgroups.put(closer, subgroup); } 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 ac257d1..a3c831e 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexCloser.java @@ -9,6 +9,7 @@ import java.util.function.BiPredicate; * */ public class RegexCloser implements BiPredicate { + /* Closing string. */ private final String rep; /** @@ -30,4 +31,4 @@ public class RegexCloser implements BiPredicate { return work.equals(closer); } -} \ No newline at end of file +} 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 15f11e3..a84b148 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/RegexOpener.java @@ -14,8 +14,9 @@ import bjc.utils.data.Pair; * */ public class RegexOpener implements Function> { + /* The name of the group. */ private final String name; - + /* The pattern that marks an opening group. */ private final Pattern patt; /** 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 0eddebe..6aa3cc9 100644 --- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java +++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java @@ -27,19 +27,13 @@ import bjc.utils.funcutils.StringUtils; * The type of items in the sequence. */ public class SequenceDelimiter { - /* - * Mapping from group names to actual groups. - */ + /* Mapping from group names to actual groups. */ private final Map> groups; - /* - * The initial group to start with. - */ + /* The initial group to start with. */ private DelimiterGroup initialGroup; - /** - * Create a new sequence delimiter. - */ + /** Create a new sequence delimiter. */ public SequenceDelimiter() { groups = new HashMap<>(); } @@ -93,46 +87,36 @@ public class SequenceDelimiter { */ 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) throw new NullPointerException("Sequence characteristics must not be null"); + } else if (chars == null) { + throw new NullPointerException("Sequence characteristics must not be null"); + } - /* - * The stack of opened and not yet closed groups. - */ + /* The stack of opened and not yet closed groups. */ final Stack.OpenGroup> groupStack = new SimpleStack<>(); - /* - * Open initial group. - */ + /* Open initial group. */ groupStack.push(initialGroup.open(chars.root, null)); - /* - * Groups that aren't allowed to be opened at the moment. - */ + /* Groups that aren't allowed to be opened at the moment. */ final Stack> forbiddenDelimiters = new SimpleStack<>(); forbiddenDelimiters.push(HashMultiset.create()); - /* - * Groups that are allowed to be opened at the moment. - */ + /* Groups that are allowed to be opened at the moment. */ final Stack> allowedDelimiters = new SimpleStack<>(); allowedDelimiters.push(HashMultimap.create()); - /* - * Map of who forbid what for debugging purposes. - */ + /* Map of who forbid what for debugging purposes. */ final IMap whoForbid = new PushdownMap<>(); - /* + /* * 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. - */ + /* Check if this token could open a group. */ final IPair possibleOpenPar = groupStack.top().doesOpen(tok); T possibleOpen = possibleOpenPar.getLeft(); @@ -178,9 +162,7 @@ public class SequenceDelimiter { throw new DelimiterException(String.format(fmt, group, forbiddenBy, ctxList)); } - /* - * Add an open group. - */ + /* Add an open group. */ final DelimiterGroup.OpenGroup open = group.open(tok, possibleOpenPar.getRight()); groupStack.push(open); @@ -192,17 +174,13 @@ public class SequenceDelimiter { forbiddenDelimiters.push(HashMultiset.create()); } - /* - * Add the nested opens from this group. - */ + /* Add the nested opens from this group. */ final Multimap currentAllowed = allowedDelimiters.top(); for(final Entry opener : open.getNestingOpeners().entrySet()) { currentAllowed.put(opener.getKey(), opener.getValue()); } - /* - * Add the nested exclusions from this group - */ + /* Add the nested exclusions from this group */ final Multiset currentForbidden = forbiddenDelimiters.top(); for(final T exclusion : open.getNestingExclusions()) { currentForbidden.add(exclusion); @@ -217,9 +195,7 @@ public class SequenceDelimiter { groupStack.top().addItem(closed.toTree(tok, chars)); - /* - * Remove nested exclusions from this group. - */ + /* Remove nested exclusions from this group. */ final Multiset currentForbidden = forbiddenDelimiters.top(); for(final T excludedGroup : closed.getNestingExclusions()) { currentForbidden.remove(excludedGroup); @@ -227,9 +203,7 @@ public class SequenceDelimiter { whoForbid.remove(excludedGroup); } - /* - * Remove the nested opens from this group. - */ + /* Remove the nested opens from this group. */ final Multimap currentAllowed = allowedDelimiters.top(); for(final Entry closer : closed.getNestingOpeners().entrySet()) { currentAllowed.remove(closer.getKey(), closer.getValue()); @@ -248,9 +222,7 @@ public class SequenceDelimiter { */ groupStack.top().markSubgroup(tok, chars); } else { - /* - * Add an item to the group. - */ + /* Add an item to the group. */ groupStack.top().addItem(new Tree<>(tok)); } } @@ -261,20 +233,11 @@ public class SequenceDelimiter { if(groupStack.size() > 1) { final DelimiterGroup.OpenGroup group = groupStack.top(); - final StringBuilder msgBuilder = new StringBuilder(); - - 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"); - msgBuilder.append("Unclosed group '"); - msgBuilder.append(group.getName()); - msgBuilder.append("'. Expected one of "); - msgBuilder.append(closingDelims); - msgBuilder.append(" to close it\nOpen groups: "); - msgBuilder.append(ctxList); - 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)); @@ -283,9 +246,7 @@ public class SequenceDelimiter { return groupStack.pop().toTree(chars.root, chars); } - /* - * Check if a group is forbidden to open in a context. - */ + /* Check if a group is forbidden to open in a context. */ private boolean isForbidden(final Stack.OpenGroup> groupStack, final Stack> forbiddenDelimiters, final T groupName) { boolean localForbid; @@ -309,7 +270,9 @@ public class SequenceDelimiter { * The delimiter group. */ public void addGroup(final DelimiterGroup 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); } 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 556a2b1..0a46edb 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/ConfigurableTokenSplitter.java @@ -16,9 +16,9 @@ import bjc.utils.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. @@ -29,12 +29,10 @@ public class ConfigurableTokenSplitter extends SimpleTokenSplitter { public ConfigurableTokenSplitter(final boolean keepDelims) { super(null, keepDelims); - /* - * Use linked hash-sets to keep items in insertion order. - */ - simpleDelimiters = new LinkedHashSet<>(); + /* Use linked hash-sets to keep items in insertion order. */ + simpleDelimiters = new LinkedHashSet<>(); multipleDelimiters = new LinkedHashSet<>(); - rRawDelimiters = new LinkedHashSet<>(); + rRawDelimiters = new LinkedHashSet<>(); } /** 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 7edba52..b38a5c3 100644 --- a/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java +++ b/base/src/main/java/bjc/utils/parserutils/splitter/ExcludingTokenSplitter.java @@ -14,8 +14,7 @@ import bjc.utils.funcdata.IList; * */ public class ExcludingTokenSplitter implements TokenSplitter { - private final Set literalExclusions; - + private final Set literalExclusions; private final IList> predExclusions; private final TokenSplitter spliter; -- cgit v1.2.3