summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-10-22 21:26:09 +0100
committerMichael Williamson <mike@zwobble.org>2026-10-22 21:26:09 +0100
commit76dba2d183609094788afafe0cebd2045b212882 (patch)
tree3dfbd91de37cb213207b016aeb9c848f82f04962 /src
parent7244772054d4ee47e33b4791c689f61fa0dc83dd (diff)
Parse query expression reference
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionNode.java18
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNode.java38
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java15
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNodeMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryExpressionReferenceTests.java22
5 files changed, 140 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionNode.java
new file mode 100644
index 0000000..268e47a
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionNode.java
@@ -0,0 +1,18 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode imports
+
+public sealed interface UntypedQueryExpressionNode permits org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode {
+ public interface Builder {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode build();
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNode.java
new file mode 100644
index 0000000..e45a6bf
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNode.java
@@ -0,0 +1,38 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode imports
+
+public record UntypedQueryExpressionReferenceNode(
+ String name,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder("", org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ }
+
+ public record Builder(
+ String name,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+ ) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionNode.Builder {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode build() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode(name, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder withName(String name) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder(name, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder(name, source);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode 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 3563d0a..4003368 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
@@ -455,6 +455,21 @@ public class Parser {
);
}
+ // == Query expressions ==
+
+ static UntypedQueryExpressionNode parseQueryExpression(TokenIterator tokens) {
+ var start = tokens.startPosition();
+
+ var name = parseIdentifier(tokens);
+
+ var end = tokens.endPosition();
+ var source = createSource(start, end);
+
+ return new UntypedQueryExpressionReferenceNode(name, source);
+ }
+
+ // == Qualified type names ==
+
public static QualifiedTypeName parseQualifiedTypeName(SourceText sourceText) {
var tokens = Tokenizer.tokenize(sourceText);
var tokenIterator = tokens.iterator();
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNodeMatcher.java
new file mode 100644
index 0000000..3e4dd49
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryExpressionReferenceNodeMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher imports
+
+public final class UntypedQueryExpressionReferenceNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher isUntypedQueryExpressionReferenceNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode>> submatchers;
+
+ private UntypedQueryExpressionReferenceNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode>> 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.UntypedQueryExpressionReferenceNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher 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.UntypedQueryExpressionReferenceNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher 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.UntypedQueryExpressionReferenceNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryExpressionReferenceTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryExpressionReferenceTests.java
new file mode 100644
index 0000000..bc911dc
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryExpressionReferenceTests.java
@@ -0,0 +1,22 @@
+package org.zwobble.hobgoblin.compiler.parser;
+
+import org.junit.jupiter.api.Test;
+
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryExpressionReferenceNodeMatcher.isUntypedQueryExpressionReferenceNode;
+import static org.zwobble.hobgoblin.compiler.parser.ParserTesting.parseString;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+
+public class ParserQueryExpressionReferenceTests {
+ @Test
+ public void canParseReference() {
+ var source = "authors";
+
+ var node = parseString(source, Parser::parseQueryExpression);
+
+ assertThat(node, isUntypedQueryExpressionReferenceNode()
+ .withName(equalTo("authors"))
+ );
+ }
+}
+