summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/parserutils/TreeConstructor.java
diff options
context:
space:
mode:
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.java5
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();
});