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/SequenceDelimiter.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/SequenceDelimiter.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/parserutils/SequenceDelimiter.java | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/SequenceDelimiter.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/SequenceDelimiter.java index 9a3bac6..771933a 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/SequenceDelimiter.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/SequenceDelimiter.java @@ -1,5 +1,6 @@ package bjc.utils.parserutils; +import bjc.utils.data.IPair; import bjc.utils.data.ITree; import bjc.utils.data.Tree; import bjc.utils.esodata.PushdownMap; @@ -104,7 +105,7 @@ public class SequenceDelimiter<T> { /* * Open initial group. */ - groupStack.push(initialGroup.open(chars.root)); + groupStack.push(initialGroup.open(chars.root, null)); /* * Groups that aren't allowed to be opened at the moment. @@ -119,7 +120,9 @@ public class SequenceDelimiter<T> { for(int i = 0; i < seq.length; i++) { T tok = seq[i]; - T possibleOpen = groupStack.top().doesOpen(tok); + IPair<T, T[]> possibleOpenPar = groupStack.top().doesOpen(tok); + T possibleOpen = possibleOpenPar.getLeft(); + /* * If we have an opening delimiter, handle it. */ @@ -161,7 +164,7 @@ public class SequenceDelimiter<T> { /* * Add an open group. */ - DelimiterGroup<T>.OpenGroup open = group.open(tok); + DelimiterGroup<T>.OpenGroup open = group.open(tok, possibleOpenPar.getRight()); groupStack.push(open); /* |
