aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-03 11:37:28 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-03 11:37:28 +0100
commit1416b1bb15b1048b99b6a92b2923630b13de7e30 (patch)
tree66ba346d6a70304ba5f48bed1da0a24ea04ea923 /src/main/java
parent2e008d29e5d956f5463fa27c397f395a7e106d9e (diff)
Add builder for untyped call nodes
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/ast/untyped/UntypedArgsNode.java18
-rw-r--r--src/main/java/org/shedlang/compiler/ast/untyped/UntypedCallNode.java34
2 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedArgsNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedArgsNode.java
index 735f31ec..fb3df52e 100644
--- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedArgsNode.java
+++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedArgsNode.java
@@ -1,6 +1,9 @@
package org.shedlang.compiler.ast.untyped;
+import org.pcollections.PVector;
import org.shedlang.compiler.sources.Source;
+import org.shedlang.compiler.sources.Sources;
+import org.shedlang.compiler.util.P;
import java.util.List;
@@ -9,4 +12,19 @@ public record UntypedArgsNode(
List<UntypedNamedArgNode> named,
Source source
) implements UntypedNode {
+ public static Builder builder() {
+ return new Builder(
+ P.vector(),
+ P.vector()
+ );
+ }
+
+ public record Builder(
+ PVector<UntypedExpressionNode> positional,
+ PVector<UntypedNamedArgNode> named
+ ) {
+ public UntypedArgsNode build() {
+ return new UntypedArgsNode(positional, named, Sources.NULL);
+ }
+ }
}
diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedCallNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedCallNode.java
index 1f62d842..f9fe01a4 100644
--- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedCallNode.java
+++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedCallNode.java
@@ -1,6 +1,7 @@
package org.shedlang.compiler.ast.untyped;
import org.shedlang.compiler.sources.Source;
+import org.shedlang.compiler.sources.Sources;
public record UntypedCallNode(
UntypedExpressionNode receiver,
@@ -8,4 +9,37 @@ public record UntypedCallNode(
boolean hasEffects,
Source source
) implements UntypedExpressionNode {
+ public static Builder builder() {
+ return new Builder(
+ new UntypedReferenceNode("f", Sources.NULL),
+ UntypedArgsNode.builder(),
+ false
+ );
+ }
+
+ public record Builder(
+ UntypedExpressionNode receiver,
+ UntypedArgsNode.Builder args,
+ boolean hasEffects
+ ) {
+ public UntypedCallNode build() {
+ return new UntypedCallNode(receiver, args.build(), hasEffects, Sources.NULL);
+ }
+
+ public Builder withReceiver(UntypedReferenceNode receiver) {
+ return new Builder(
+ receiver,
+ this.args,
+ this.hasEffects
+ );
+ }
+
+ public Builder withHasEffects(boolean hasEffects) {
+ return new Builder(
+ this.receiver,
+ this.args,
+ hasEffects
+ );
+ }
+ }
}