From 1416b1bb15b1048b99b6a92b2923630b13de7e30 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 3 Jul 2023 11:37:28 +0100 Subject: Add builder for untyped call nodes --- .../compiler/ast/untyped/UntypedArgsNode.java | 18 ++++++++++++ .../compiler/ast/untyped/UntypedCallNode.java | 34 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'src/main/java') 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 named, Source source ) implements UntypedNode { + public static Builder builder() { + return new Builder( + P.vector(), + P.vector() + ); + } + + public record Builder( + PVector positional, + PVector 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 + ); + } + } } -- cgit v1.2.3