summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java
index c4450f8..4b00b63 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/parserutils/AST.java
@@ -302,4 +302,55 @@ public class AST<T> {
action.accept(token);
}
}
+
+ /**
+ * Apply an action to the head node of this AST
+ *
+ * @param <E>
+ * The type of the returned value
+ * @param headAction
+ * The action to apply to the head node
+ * @return The result of applying the action
+ */
+ public <E> E applyToHead(Function<T, E> headAction) {
+ if (headAction == null) {
+ throw new NullPointerException("Action must not be null");
+ }
+
+ return headAction.apply(token);
+ }
+
+ /**
+ * Apply an action to the left side of this AST
+ *
+ * @param <E>
+ * The type of the returned value
+ * @param leftAction
+ * The action to apply to the left side
+ * @return The result of applying the action
+ */
+ public <E> E applyToLeft(Function<AST<T>, E> leftAction) {
+ if (leftAction == null) {
+ throw new NullPointerException("Action must not be null");
+ }
+
+ return leftAction.apply(left);
+ }
+
+ /**
+ * Apply an action to the right side of this AST
+ *
+ * @param <E>
+ * The type of the returned value
+ * @param rightAction
+ * The action to apply to the right side
+ * @return The result of applying the action
+ */
+ public <E> E applyToRight(Function<AST<T>, E> rightAction) {
+ if (rightAction == null) {
+ throw new NullPointerException("Action must not be null");
+ }
+
+ return rightAction.apply(right);
+ }
}