diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-10-16 15:19:03 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-10-16 15:19:03 +0100 |
| commit | 6f392b7a68dc47811928463ee4502c9a222a0657 (patch) | |
| tree | fdebd67c4d21b02207f3133cbc905b95078d2c83 /src/main/java | |
| parent | 0c89574853f1ebe34bd37346ae21d5586440656d (diff) | |
Add SQL scripts to SQL AST
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java | 17 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java | 44 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java index b7d0caf..b6edc1b 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java @@ -37,6 +37,23 @@ public class SqlWriter { this.writer = writer; } + // == Scripts == + + public void writeScript(SqlScript script) throws IOException { + writer.writeHeader(); + + writeWithSeparator( + script.statements(), + this::writeStatement, + () -> { + writer.newLine(); + writer.newLine(); + } + ); + + writer.newLine(); + } + // == Statements == void writeStatement(SqlStatement statement) throws IOException { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java new file mode 100644 index 0000000..4b91c2e --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlScript.java @@ -0,0 +1,44 @@ +// Generated by hobgoblin. + +package org.zwobble.hobgoblin.compiler.output.lang.sql.ast; + +// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript imports +// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript imports + +public record SqlScript( + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement> statements +) { + public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder arbitrary() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(java.util.List.of()); + } + + public record Builder( + java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement> statements + ) { + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript build() { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript(statements); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder withStatements(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement> statements) { + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(statements); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder addStatement(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement statement) { + var statements = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement>(this.statements); + statements.add(statement); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(statements); + } + + public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder addStatement(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement.Builder statement) { + var statements = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement>(this.statements); + statements.add(statement.build()); + return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder(statements); + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript.Builder body + } + + // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript body + // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlScript body +} |
