diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-29 22:46:39 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-29 22:46:39 +0100 |
| commit | fa0eb2727b12dc38d74228504c49f1a269c32b8c (patch) | |
| tree | 95cab36909903f3bf0d5f8a47bb42484073a0042 /src/main/java | |
| parent | d975ac0ba736e373c78661950b2884d12ac2a416 (diff) | |
Add number literals to TypeScript AST
Diffstat (limited to 'src/main/java')
3 files changed, 64 insertions, 0 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 80ce51b..74556bb 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 @@ -113,6 +113,20 @@ public class TypescriptWriter implements AutoCloseable { this.writer.write(";"); } + // == Expressions == + + void writeExpression(TypescriptExpression expression) throws IOException { + switch (expression) { + case TypescriptNumberLiteral numberLiteral -> { + this.writeNumberLiteral(numberLiteral); + } + } + } + + private void writeNumberLiteral(TypescriptNumberLiteral numberLiteral) throws IOException { + this.writer.write(Double.toString(numberLiteral.value())); + } + // == Identifiers == private void writeIdentifier(TypescriptIdentifier name) throws IOException { 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 new file mode 100644 index 0000000..4c04085 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptExpression.java @@ -0,0 +1,18 @@ +// Generated by hobgoblin. + +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.TypescriptNumberLiteral { + public interface Builder { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression build(); + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression body +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNumberLiteral.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNumberLiteral.java new file mode 100644 index 0000000..40c2f01 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/typescript/ast/TypescriptNumberLiteral.java @@ -0,0 +1,32 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.typescript.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral imports + +public record TypescriptNumberLiteral( + double value +) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression { + public static org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.Builder(0); + } + + public record Builder( + double value + ) implements org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptExpression.Builder { + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral build() { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral(value); + } + + public org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.Builder withValue(double value) { + return new org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.Builder(value); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.typescript.ast.TypescriptNumberLiteral body +} |
