summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java
diff options
context:
space:
mode:
authorbjculkin <bjculkin@mix.wvu.edu>2017-03-31 08:53:33 -0400
committerbjculkin <bjculkin@mix.wvu.edu>2017-03-31 08:53:33 -0400
commitb4e4e7f1d6749de92b0f2c5ca09eb4170704100f (patch)
tree110443ec91e8ff4f8e85028e27409e9bd2bb9bd4 /BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java
parent21db48520acfd6e6ac175aa5df12e50c6be2c767 (diff)
Move Pratt Parser to new project
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java93
1 files changed, 0 insertions, 93 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java
deleted file mode 100644
index db7d1e0..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/TokenStream.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package bjc.utils.parserutils.pratt;
-
-import bjc.utils.funcutils.StringUtils;
-import bjc.utils.parserutils.ParserException;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A stream of tokens.
- *
- * @author EVE
- *
- * @param <K>
- * The key type of the token.
- *
- * @param <V>
- * The value type of the token.
- */
-public abstract class TokenStream<K, V> implements Iterator<Token<K, V>> {
- /**
- * The exception thrown when an expectation fails.
- *
- * @author EVE
- *
- */
- public static class ExpectationException extends ParserException {
- /**
- * Create a new exception with the specified message.
- *
- * @param msg
- * The message of the exception.
- */
- public ExpectationException(String msg) {
- super(msg);
- }
- }
-
- /**
- * Get the current token.
- *
- * @return The current token.
- */
- public abstract Token<K, V> current();
-
- @Override
- public abstract Token<K, V> next();
-
- @Override
- public abstract boolean hasNext();
-
- /**
- * Utility method for checking that the next token is one of a specific
- * set of types, and then consuming it.
- *
- * @param expectedKeys
- * The expected values
- *
- * @throws ExpectationException
- * If the token is not one of the expected types.
- */
- public void expect(Set<K> expectedKeys) throws ExpectationException {
- K curKey = current().getKey();
-
- if (!expectedKeys.contains(curKey)) {
- String expectedList = StringUtils.toEnglishList(expectedKeys.toArray(), false);
-
- throw new ExpectationException("One of '" + expectedList + "' was expected, not " + curKey);
- } else {
- next();
- }
- }
-
- /**
- * Utility method for checking that the next token is one of a specific
- * set of types, and then consuming it.
- *
- * @param expectedKeys
- * The expected values
- *
- * @throws ExpectationException
- * If the token is not one of the expected types.
- */
- @SafeVarargs
- public final void expect(K... expectedKeys) throws ExpectationException {
- expect(new HashSet<>(Arrays.asList(expectedKeys)));
- }
-
- public boolean headIs(K val) {
- return current().getKey().equals(val);
- }
-}