summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-12-05 21:22:31 +0000
committerMichael Williamson <mike@zwobble.org>2026-12-05 21:22:31 +0000
commitf28a32ae999d35ec5065bbab0ed41364524c0435 (patch)
tree7d555938f8557f0f9a2723d67dae3bc71924eb7b /src
parentf7bbf52c8cad3c28fbc75b8628bde3cba8cd0d24 (diff)
Parse params in query definition
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNode.java14
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNode.java38
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNode.java18
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNode.java34
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java27
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java10
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java46
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java11
12 files changed, 225 insertions, 34 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNode.java
index d4a6034..e14360e 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNode.java
@@ -6,7 +6,7 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode imports
public record UntypedFunctionExpressionNode(
- java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode> params,
+ java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode> params,
org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode body,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode {
@@ -15,7 +15,7 @@ public record UntypedFunctionExpressionNode(
}
public record Builder(
- java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode> params,
+ java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode> params,
org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode body,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder {
@@ -23,18 +23,18 @@ public record UntypedFunctionExpressionNode(
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode(params, body, source);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder withParams(java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode> params) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder withParams(java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode> params) {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder(params, body, source);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode param) {
- var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>(this.params);
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode param) {
+ var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>(this.params);
params.add(param);
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder(params, body, source);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder param) {
- var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>(this.params);
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder param) {
+ var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>(this.params);
params.add(param.build());
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder(params, body, source);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNode.java
new file mode 100644
index 0000000..63ff9ad
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNode.java
@@ -0,0 +1,38 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode imports
+
+public record UntypedFunctionExpressionParamNode(
+ String name,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+) {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder("", org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ }
+
+ public record Builder(
+ String name,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+ ) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode build() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode(name, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder withName(String name) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder(name, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder(name, source);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNode.java
index 068097f..db6fb69 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNode.java
@@ -7,26 +7,36 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
public record UntypedParamNode(
String name,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type,
org.zwobble.hobgoblin.compiler.sources.Source source
) {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder("", org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
String name,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type,
org.zwobble.hobgoblin.compiler.sources.Source source
) {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode build() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode(name, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode(name, type, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder withName(String name) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder(name, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder(name, type, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder withType(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode type) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder(name, type, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder withType(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode.Builder type) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder(name, type.build(), source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder(name, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder(name, type, source);
}
// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder body
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNode.java
index b48a95c..4e0b3ca 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNode.java
@@ -7,50 +7,68 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
public record UntypedQueryDefinitionNode(
String name,
+ java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode> params,
java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode> statements,
org.zwobble.hobgoblin.compiler.ast.DocComment docComment,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceStatementNode {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.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.untyped.UntypedQueryDefinitionNode.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.untyped.UntypedParamNode> params,
java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode> statements,
org.zwobble.hobgoblin.compiler.ast.DocComment docComment,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceStatementNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode build() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode(name, params, statements, docComment, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withName(String name) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withParams(java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode> params) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode param) {
+ var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>(this.params);
+ params.add(param);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder addParam(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode.Builder param) {
+ var params = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>(this.params);
+ params.add(param.build());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withStatements(java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode> statements) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder addStatement(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode statement) {
var statements = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode>(this.statements);
statements.add(statement);
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder addStatement(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode.Builder statement) {
var statements = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode>(this.statements);
statements.add(statement.build());
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withDocComment(org.zwobble.hobgoblin.compiler.ast.DocComment docComment) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, params, statements, docComment, source);
}
// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder body
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
index b4bb07d..96a3c50 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
@@ -255,6 +255,13 @@ public class Parser {
var name = parseIdentifier(tokens);
tokens.skip(TokenType.SYMBOL_PAREN_OPEN);
+
+ var params = parseMany(
+ () -> tokens.isNext(TokenType.SYMBOL_PAREN_CLOSE),
+ () -> parseParam(tokens),
+ () -> tokens.trySkip(TokenType.SYMBOL_COMMA)
+ );
+
tokens.skip(TokenType.SYMBOL_PAREN_CLOSE);
tokens.skip(TokenType.SYMBOL_BRACE_OPEN);
@@ -272,6 +279,7 @@ public class Parser {
return new UntypedQueryDefinitionNode(
name,
+ params,
statements,
docComment,
source
@@ -461,10 +469,14 @@ public class Parser {
var name = parseIdentifier(tokens);
+ tokens.skip(TokenType.SYMBOL_COLON);
+
+ var type = parseTypeLevelExpression(tokens);
+
var end = tokens.endPosition();
var source = createSource(start, end);
- return new UntypedParamNode(name, source);
+ return new UntypedParamNode(name, type, source);
}
// == Type-level expressions ==
@@ -578,7 +590,7 @@ public class Parser {
var params = parseMany(
() -> tokens.isNext(TokenType.SYMBOL_PAREN_CLOSE),
- () -> parseParam(tokens),
+ () -> parseFunctionExpressionParam(tokens),
() -> tokens.trySkip(TokenType.SYMBOL_COMMA)
);
@@ -597,6 +609,17 @@ public class Parser {
);
}
+ private static UntypedFunctionExpressionParamNode parseFunctionExpressionParam(TokenIterator tokens) {
+ var start = tokens.startPosition();
+
+ var name = parseIdentifier(tokens);
+
+ var end = tokens.endPosition();
+ var source = createSource(start, end);
+
+ return new UntypedFunctionExpressionParamNode(name, source);
+ }
+
private static UntypedNumberLiteralNode parseNumberLiteral(TokenIterator tokens) {
var start = tokens.startPosition();
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java
index 71356e8..1e45982 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNodeMatcher.java
@@ -30,7 +30,7 @@ public final class UntypedFunctionExpressionNodeMatcher implements org.zwobble.p
return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.class, this.submatchers);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>> params) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>> params) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode::params, (org.zwobble.precisely.Matcher) params));
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher(submatchers);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java
new file mode 100644
index 0000000..996c590
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionParamNodeMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher imports
+
+public final class UntypedFunctionExpressionParamNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher isUntypedFunctionExpressionParamNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>> submatchers;
+
+ private UntypedFunctionExpressionParamNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>> submatchers
+ ) {
+ this.submatchers = submatchers;
+ }
+
+ public org.zwobble.precisely.MatchResult match(java.lang.Object actual) {
+ return this.toMatcher().match(actual);
+ }
+
+ public org.zwobble.precisely.TextTree describe() {
+ return this.toMatcher().describe();
+ }
+
+ private org.zwobble.precisely.Matcher<java.lang.Object> toMatcher() {
+ return org.zwobble.precisely.Matchers.instanceOf(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher withName(org.zwobble.precisely.Matcher<? super String> name) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java
index c140fb2..f1dcf75 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedParamNodeMatcher.java
@@ -36,6 +36,12 @@ public final class UntypedParamNodeMatcher implements org.zwobble.precisely.Matc
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher withType(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> type) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("type", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode::type, (org.zwobble.precisely.Matcher) type));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher withSource(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.sources.Source> source) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode::source, (org.zwobble.precisely.Matcher) source));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java
index adcc2d9..7f1ded1 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java
@@ -36,6 +36,12 @@ public final class UntypedQueryDefinitionNodeMatcher implements org.zwobble.prec
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher withParams(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode>> params) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("params", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode::params, (org.zwobble.precisely.Matcher) params));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher withStatements(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode>> statements) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("statements", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode::statements, (org.zwobble.precisely.Matcher) statements));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java
index 99cf3c0..9813324 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserFunctionExpressionTests.java
@@ -3,7 +3,7 @@ package org.zwobble.hobgoblin.compiler.parser;
import org.junit.jupiter.api.Test;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNodeMatcher.isUntypedFunctionExpressionNode;
-import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher.isUntypedParamNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionParamNodeMatcher.isUntypedFunctionExpressionParamNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNodeMatcher.isUntypedReferenceNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -31,7 +31,7 @@ public class ParserFunctionExpressionTests {
assertThat(node, isUntypedFunctionExpressionNode()
.withParams(isSequence(
- isUntypedParamNode().withName(equalTo("a"))
+ isUntypedFunctionExpressionParamNode().withName(equalTo("a"))
))
.withBody(isUntypedReferenceNode().withName(equalTo("x")))
);
@@ -44,9 +44,9 @@ public class ParserFunctionExpressionTests {
assertThat(node, isUntypedFunctionExpressionNode()
.withParams(isSequence(
- isUntypedParamNode().withName(equalTo("a")),
- isUntypedParamNode().withName(equalTo("b")),
- isUntypedParamNode().withName(equalTo("c"))
+ isUntypedFunctionExpressionParamNode().withName(equalTo("a")),
+ isUntypedFunctionExpressionParamNode().withName(equalTo("b")),
+ isUntypedFunctionExpressionParamNode().withName(equalTo("c"))
))
.withBody(isUntypedReferenceNode().withName(equalTo("x")))
);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
index e5b5a45..255b810 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
@@ -2,9 +2,11 @@ package org.zwobble.hobgoblin.compiler.parser;
import org.junit.jupiter.api.Test;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNodeMatcher.isUntypedParamNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNodeMatcher.isUntypedQueryDefinitionNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNodeMatcher.isUntypedReferenceNode;
import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNodeMatcher.isUntypedReturnNode;
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNodeMatcher.isUntypedTypeLevelReferenceNode;
import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
import static org.zwobble.precisely.AssertThat.assertThat;
import static org.zwobble.precisely.Matchers.equalTo;
@@ -70,5 +72,49 @@ public class ParserQueryDefinitionTests {
))
);
}
+
+ @Test
+ public void canParseQueryDefinitionWithSingleParam() {
+ var source = """
+ query allAuthors(a: A) {
+ }""";
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(node, isUntypedQueryDefinitionNode()
+ .withName(equalTo("allAuthors"))
+ .withParams(isSequence(
+ isUntypedParamNode()
+ .withName(equalTo("a"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("A")))
+ ))
+ .withStatements(isSequence())
+ );
+ }
+
+ @Test
+ public void canParseQueryDefinitionWithMultipleParams() {
+ var source = """
+ query allAuthors(a: A, b: B, c: C) {
+ }""";
+
+ var node = parseString(source, Parser::parseNamespaceStatement);
+
+ assertThat(node, isUntypedQueryDefinitionNode()
+ .withName(equalTo("allAuthors"))
+ .withParams(isSequence(
+ isUntypedParamNode()
+ .withName(equalTo("a"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("A"))),
+ isUntypedParamNode()
+ .withName(equalTo("b"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("B"))),
+ isUntypedParamNode()
+ .withName(equalTo("c"))
+ .withType(isUntypedTypeLevelReferenceNode().withName(equalTo("C")))
+ ))
+ .withStatements(isSequence())
+ );
+ }
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
index af8005f..6ba102e 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerFunctionExpressionTests.java
@@ -1,10 +1,7 @@
package org.zwobble.hobgoblin.compiler.typechecker;
import org.junit.jupiter.api.Test;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedParamNode;
-import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.*;
import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
import org.zwobble.hobgoblin.compiler.sources.NullSource;
import org.zwobble.hobgoblin.compiler.types.FunctionType;
@@ -49,8 +46,8 @@ public class TypeCheckerFunctionExpressionTests {
@Test
public void paramTypesAreInferredFromHint() {
var untyped = UntypedFunctionExpressionNode.arbitrary()
- .addParam(UntypedParamNode.arbitrary().withName("a"))
- .addParam(UntypedParamNode.arbitrary().withName("b"))
+ .addParam(UntypedFunctionExpressionParamNode.arbitrary().withName("a"))
+ .addParam(UntypedFunctionExpressionParamNode.arbitrary().withName("b"))
.withBody(UntypedNumberLiteralNode.arbitrary().withValue(BigDecimal.ZERO))
.build();
var globalContext = TypeCheckerContextArb.globalContext();
@@ -79,7 +76,7 @@ public class TypeCheckerFunctionExpressionTests {
@Test
public void paramsAreAvailableInFunctionExpressionBody() {
var untyped = UntypedFunctionExpressionNode.arbitrary()
- .addParam(UntypedParamNode.arbitrary().withName("a"))
+ .addParam(UntypedFunctionExpressionParamNode.arbitrary().withName("a"))
.withBody(UntypedReferenceNode.arbitrary().withName("a"))
.build();
var globalContext = TypeCheckerContextArb.globalContext();