summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/delims
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/bjc/utils/parserutils/delims')
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java61
-rw-r--r--base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java14
2 files changed, 35 insertions, 40 deletions
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 0fe998d..e89ba08 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/DelimiterGroup.java
@@ -47,8 +47,8 @@ public class DelimiterGroup<T> {
/*
* The token that opened the group, and any opening parameters.
*/
- private final T opener;
- private final T[] params;
+ private final T opener;
+ private final T[] params;
/**
* Create a new instance of a delimiter group.
@@ -148,8 +148,8 @@ public class DelimiterGroup<T> {
final ITree<T> 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()) {
currentGroup.forEach(res::addChild);
@@ -261,14 +261,12 @@ public class DelimiterGroup<T> {
* open one.
*/
public IPair<T, T[]> doesOpen(final T marker) {
- if (openDelimiters.containsKey(marker))
- return new Pair<>(openDelimiters.get(marker), null);
+ if(openDelimiters.containsKey(marker)) return new Pair<>(openDelimiters.get(marker), null);
for(final Function<T, IPair<T, T[]>> pred : predOpeners) {
final IPair<T, T[]> par = pred.apply(marker);
- if (par.getLeft() != null)
- return par;
+ if(par.getLeft() != null) return par;
}
return new Pair<>(null, null);
@@ -329,20 +327,19 @@ public class DelimiterGroup<T> {
* 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<>();
@@ -359,10 +356,10 @@ public class DelimiterGroup<T> {
public final void addClosing(final T... closers) {
final List<T> closerList = Arrays.asList(closers);
- for (final T closer : closerList) {
- if (closer == null) {
+ for(final T closer : closerList) {
+ if(closer == null) {
throw new NullPointerException("Closing delimiter must not be null");
- } else if (closer.equals("")) {
+ } else if(closer.equals("")) {
/*
* We can do this because equals works on
* arbitrary objects, not just those of the same
@@ -384,10 +381,10 @@ public class DelimiterGroup<T> {
*/
@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
@@ -408,10 +405,10 @@ public class DelimiterGroup<T> {
*/
@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
@@ -434,8 +431,7 @@ public class DelimiterGroup<T> {
* 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);
}
@@ -450,10 +446,9 @@ public class DelimiterGroup<T> {
* 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);
}
@@ -468,9 +463,9 @@ public class DelimiterGroup<T> {
* 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");
}
@@ -487,13 +482,13 @@ public class DelimiterGroup<T> {
* 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));
}
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 6aa3cc9..ff4b348 100644
--- a/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
+++ b/base/src/main/java/bjc/utils/parserutils/delims/SequenceDelimiter.java
@@ -87,9 +87,9 @@ public class SequenceDelimiter<T> {
*/
public ITree<T> delimitSequence(final SequenceCharacteristics<T> 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");
}
@@ -110,10 +110,10 @@ public class SequenceDelimiter<T> {
/* Map of who forbid what for debugging purposes. */
final IMap<T, T> 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. */
@@ -233,8 +233,8 @@ public class SequenceDelimiter<T> {
if(groupStack.size() > 1) {
final DelimiterGroup<T>.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");
@@ -270,7 +270,7 @@ public class SequenceDelimiter<T> {
* The delimiter group.
*/
public void addGroup(final DelimiterGroup<T> group) {
- if (group == null) {
+ if(group == null) {
throw new NullPointerException("Group must not be null");
}