diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-11-10 19:44:22 -0500 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-11-10 19:44:22 -0500 |
| commit | ba9cf27de7e9f31dfa97a7266979f300101d67f9 (patch) | |
| tree | dbf938e02d647e1be519808f8a14c6e954cab732 /BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java | |
| parent | 5cf7bcf156970fe72f79e40b8a6e320ea160ac83 (diff) | |
Doc updates
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java index 2ddde9d..0b61363 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java +++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java @@ -36,6 +36,7 @@ public class TreeConstructor { public static <TokenType> ITree<TokenType> constructTree( IList<TokenType> tokens, Predicate<TokenType> operatorPredicate) { + // Construct a tree with no special operators return constructTree(tokens, operatorPredicate, (op) -> false, null); } @@ -70,6 +71,7 @@ public class TreeConstructor { Predicate<TokenType> isSpecialOperator, Function<TokenType, Function<Deque<ITree<TokenType>>, ITree<TokenType>>> handleSpecialOperator) { + // Make sure our parameters are valid if (tokens == null) { throw new NullPointerException("Tokens must not be null"); } else if (operatorPredicate == null) { @@ -80,14 +82,17 @@ public class TreeConstructor { "Special operator determiner must not be null"); } + // Here is the state for the tree construction IHolder<IPair<Deque<ITree<TokenType>>, ITree<TokenType>>> initialState = new Identity<>( new Pair<>(new LinkedList<>(), null)); + // Transform each of the tokens tokens.forEach( new TokenTransformer<>(initialState, operatorPredicate, isSpecialOperator, handleSpecialOperator)); + // Grab the tree from the state return initialState.unwrap((pair) -> { return pair.getRight(); }); |
