diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-31 22:47:37 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-31 22:47:37 +0100 |
| commit | 46005281330e2a001aba50a5c1358d9ae22334ec (patch) | |
| tree | b959f1bd186bda464f7bc15cdc73b679932a21c3 /src/main | |
| parent | 075435ee62dfe934de840d60ee71dcfef7aea654 (diff) | |
Add calls to TypeScript AST
Diffstat (limited to 'src/main')
3 files changed, 70 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java index 9e52843..93216bf 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/TypescriptWriter.java @@ -241,6 +241,10 @@ public class TypescriptWriter implements AutoCloseable { this.writeBinaryOperation(binaryOperation); } + case TypescriptCall call -> { + this.writeCall(call); + } + case TypescriptConstructedType constructedType -> { this.writeConstructedType(constructedType); } @@ -277,6 +281,17 @@ public class TypescriptWriter implements AutoCloseable { }); } + private void writeCall(TypescriptCall call) throws IOException { + this.writeExpression(call.receiver()); + this.writer.write("("); + writeWithSeparator( + call.args(), + this::writeExpression, + () -> this.writer.write(", ") + ); + this.writer.write(")"); + } + private void writeConstructedType(TypescriptConstructedType constructedType) throws IOException { this.writeExpression(constructedType.receiver()); this.writer.write("<"); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCall.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCall.java new file mode 100644 index 0000000..1c47666 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptCall.java @@ -0,0 +1,54 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall imports + +public record TypescriptCall( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression receiver, + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression> args +) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.arbitrary().build(), java.util.List.of()); + } + + public record Builder( + org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression receiver, + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression> args + ) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder withReceiver(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression receiver) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder withReceiver(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder receiver) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder(receiver.build(), args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder withArgs(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression> args) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder addArg(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression arg) { + var args = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression>(this.args); + args.add(arg); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder(receiver, args); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder addArg(org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder arg) { + var args = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression>(this.args); + args.add(arg.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder(receiver, args); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java index 79057fe..7d443a3 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java @@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression imports // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression imports -public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef { +public sealed interface TypescriptExpression permits org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptBinaryOperation, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptConstructedType, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptFieldAccess, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNewCall, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral, org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptRef { public interface Builder { public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression build(); |
