diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-12-05 21:42:53 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-12-05 21:42:53 +0000 |
| commit | d536d0535af4a3b88ec356a6d1b561d6942334f2 (patch) | |
| tree | 331a3084f4fb492a3778de2a7a8141935b9ccb06 /src/main | |
| parent | 5a646ae3ae92b9756e005b38e40f9fd8476cdc7c (diff) | |
Add params to typed query definition nodes
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNode.java | 34 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java | 3 |
2 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNode.java index b154528..05ef9c9 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNode.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNode.java @@ -7,50 +7,68 @@ package org.zwobble.hobgoblin.compiler.ast.typed; public record TypedQueryDefinitionNode( String name, + java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode> params, java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode> statements, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source ) implements org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceStatementNode { public static org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder arbitrary() { - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder("", java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource()); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder("", java.util.List.of(), java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource()); } public record Builder( String name, + java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode> params, java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode> statements, org.zwobble.hobgoblin.compiler.ast.DocComment docComment, org.zwobble.hobgoblin.compiler.sources.Source source ) implements org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceStatementNode.Builder { public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode build() { - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode(name, params, statements, docComment, source); } public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withName(String name) { - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); + } + + public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withParams(java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode> params) { + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); + } + + public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode param) { + var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>(this.params); + params.add(param); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); + } + + public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode.Builder param) { + var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.typed.TypedParamNode>(this.params); + params.add(param.build()); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); } public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withStatements(java.util.List<org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode> statements) { - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); } public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder addStatement(org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode statement) { var statements = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode>(this.statements); statements.add(statement); - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); } public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder addStatement(org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode.Builder statement) { var statements = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.typed.TypedStatementNode>(this.statements); statements.add(statement.build()); - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); } public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withDocComment(org.zwobble.hobgoblin.compiler.ast.DocComment docComment) { - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); } public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) { - return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, statements, docComment, source); + return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, params, statements, docComment, source); } // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder body diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java index abeb74d..debcc63 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java @@ -303,9 +303,11 @@ public class TypeChecker { // TODO: check return type from query // TODO: check there is a return + var typedParams = new ArrayList<TypedParamNode>(); var bodyContextDeclaring = context.enter(); for (var untypedParam : untyped.params()) { var typedParam = typeCheckMetaType(untypedParam.type(), context); + typedParams.add(new TypedParamNode(untypedParam.name(), typedParam.value(), untyped.source())); bodyContextDeclaring.define(untypedParam.name(), typedParam.value(), untypedParam.source()); } var bodyContext = bodyContextDeclaring.endDeclarations(); @@ -316,6 +318,7 @@ public class TypeChecker { return new TypedQueryDefinitionNode( untyped.name(), + typedParams, typedStatements, untyped.docComment(), untyped.source() |
