diff options
| author | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-20 16:06:10 -0400 |
|---|---|---|
| committer | bjculkin <bjculkin@mix.wvu.edu> | 2017-03-20 16:06:10 -0400 |
| commit | 9b375e71294dfa306c030cc5891274d57c2045f6 (patch) | |
| tree | 3248ea93b8e86c6737510208d4d8288530134d88 /BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java | |
| parent | 4b091676163fbaa4375d09806c0e500533ee1546 (diff) | |
Add more features to sequence delimiter.
Two main features were added.
One, various sequence closers can imply a subgroup. This is mainly useful
in contexts like arrays, where you want one subgroup per array element.
Two, predicated opening/closing delimiters. These allow having both an
infinite set of opening delimiters, as well as having a set of closers
that is both infinite and dependant on what the opener was.
Note, however, that predicated openers and closers will be slower than
using normal openers/closers, since every one has to be tried to check if
a token is a opener/closer.
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java index db2c288..d2569d9 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TokenSplitter.java @@ -105,7 +105,7 @@ public class TokenSplitter { public void addDelimiter(String... delims) { for(String delim : delims) { if(delim == null) throw new NullPointerException("Delim must not be null"); - + String quoteDelim = Pattern.quote(delim); String delimPat = String.format(WITH_DELIM, quoteDelim); @@ -136,7 +136,7 @@ public class TokenSplitter { public void addMultiDelimiter(String... delims) { for(String delim : delims) { if(delim == null) throw new NullPointerException("Delim must not be null"); - + String delimPat = String.format(WITH_MULTI_DELIM, "(?:" + delim + ")"); if(currPatt == null) { @@ -164,7 +164,7 @@ public class TokenSplitter { public void addNonMatcher(String... delims) { for(String delim : delims) { if(delim == null) throw new NullPointerException("Delim must not be null"); - + if(currPatt == null) { currPatt = new StringBuilder(); currExclusionPatt = new StringBuilder(); @@ -184,6 +184,9 @@ public class TokenSplitter { * Makes this splitter ready to use. */ public void compile() { + if(currPatt == null) currPatt = new StringBuilder(); + if(currExclusionPatt == null) currExclusionPatt = new StringBuilder(); + compPatt = Pattern.compile(currPatt.toString()); exclusionPatt = Pattern.compile(currExclusionPatt.toString()); } |
