summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/18-database/output/sqlite3/scripts/data/allAuthors.sql7
-rw-r--r--examples/18-database/output/sqlite3/test.py27
-rw-r--r--examples/18-database/src/data.hob12
-rw-r--r--hobgoblin/hobgoblin.json56
-rw-r--r--hobgoblin/src/ast/typed.hob12
-rw-r--r--hobgoblin/src/ast/untyped.hob24
-rw-r--r--hobgoblin/src/math.hob1
-rw-r--r--hobgoblin/src/output/lang/sql/ast.hob31
-rw-r--r--hobgoblin/src/types.hob3
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/Relation.java18
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTable.java32
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNode.java20
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNode.java58
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperator.java13
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedCallNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedExpressionNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedFunctionExpressionNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNode.java18
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNode.java38
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNode.java26
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNode.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNode.java12
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/math/HobgoblinNativeMath.java11
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGenerator.java53
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sqlscripts/SqlScriptsGenerator.java63
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriter.java63
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlExpression.java18
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteral.java32
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTerm.java36
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRef.java36
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumn.java46
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatement.java72
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlStatement.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/OperatorPrecedence.java1
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java72
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/TokenType.java3
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/parser/Tokenizer.java35
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java138
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceContext.java4
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NoSuchMemberError.java24
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/ConstantNumber.java12
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/HobgoblinNativeTypes.java8
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/RelationMethod.java10
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/Table.java8
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/TableInfo.java1
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/TypeLevelValue.java2
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/TypeSet.java7
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java8
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTableMatcher.java41
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNodeMatcher.java59
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNodeMatcher.java4
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNodeMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedQueryDefinitionNodeMatcher.java6
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGeneratorTests.java69
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java94
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteralMatcher.java41
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTermMatcher.java41
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRefMatcher.java41
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumnMatcher.java47
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java53
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserBinaryOperationTests.java26
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserMemberAccessTests.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNumberTests.java24
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java10
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/parser/TokenizerTests.java55
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerDatabaseSchemaDefinitionTests.java3
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerEvalExpressionTests.java137
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerMetaTypeTests.java2
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java37
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTableDefinitionTests.java9
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTypeLevelReferenceTests.java2
75 files changed, 1848 insertions, 145 deletions
diff --git a/examples/18-database/output/sqlite3/scripts/data/allAuthors.sql b/examples/18-database/output/sqlite3/scripts/data/allAuthors.sql
new file mode 100644
index 0000000..07aed9a
--- /dev/null
+++ b/examples/18-database/output/sqlite3/scripts/data/allAuthors.sql
@@ -0,0 +1,7 @@
+-- Generated by hobgoblin.
+
+SELECT
+ id AS id,
+ name AS name
+FROM authors
+ORDER BY id;
diff --git a/examples/18-database/output/sqlite3/test.py b/examples/18-database/output/sqlite3/test.py
index 885212b..b3c76c3 100644
--- a/examples/18-database/output/sqlite3/test.py
+++ b/examples/18-database/output/sqlite3/test.py
@@ -5,9 +5,7 @@ import unittest
class DataTestCase(unittest.TestCase):
def test_create(self):
- sql_script_path = os.path.join(os.path.dirname(__file__), "scripts/data/Data.sql")
- with open(sql_script_path, "rt", encoding="utf-8") as sql_script_file:
- sql_script = sql_script_file.read()
+ sql_script = self._read_script("Data")
connection = sqlite3.connect(":memory:", autocommit=False)
cursor = connection.cursor()
@@ -22,3 +20,26 @@ class DataTestCase(unittest.TestCase):
rows = cursor.fetchall()
self.assertEqual(rows, [(2, "Bob"), (3, "Carol")])
+
+ def test_query_all_authors(self):
+ create_script = self._read_script("Data")
+
+ connection = sqlite3.connect(":memory:", autocommit=False)
+ cursor = connection.cursor()
+ cursor.executescript(create_script)
+ connection.commit()
+
+ cursor.execute("INSERT INTO authors VALUES (1, 'Alice')")
+ cursor.execute("INSERT INTO authors VALUES (2, 'Bob')")
+ cursor.execute("INSERT INTO authors VALUES (3, 'Carol')")
+
+ select_query = self._read_script("allAuthors")
+ cursor.execute(select_query)
+ rows = cursor.fetchall()
+
+ self.assertEqual(rows, [(1, "Alice"), (2, "Bob"), (3, "Carol")])
+
+ def _read_script(self, name):
+ sql_script_path = os.path.join(os.path.dirname(__file__), "scripts/data", name + ".sql")
+ with open(sql_script_path, "rt", encoding="utf-8") as sql_script_file:
+ return sql_script_file.read()
diff --git a/examples/18-database/src/data.hob b/examples/18-database/src/data.hob
index c6a16a7..927f4f1 100644
--- a/examples/18-database/src/data.hob
+++ b/examples/18-database/src/data.hob
@@ -10,11 +10,15 @@ databaseSchema Data {
}
}
-//query allAuthors() on Data {
-// return Data.authors;
+query allAuthors() {
+ return Data.authors;
+}
+
+//query authorsByFixedId() {
+// return Data.authors.where($(author) => author.id == 42);
//}
-//query authorsByName(name: String) on Data {
+//query authorsByName(name: String) {
// return Data.authors
-// .where($(author) => author.name = name);
+// .where($(author) => author.name == name);
//}
diff --git a/hobgoblin/hobgoblin.json5 b/hobgoblin/hobgoblin.json5
index 3de67b4..1b5c3ee 100644
--- a/hobgoblin/hobgoblin.json5
+++ b/hobgoblin/hobgoblin.json5
@@ -3,6 +3,12 @@
langs: {
java: {
packageName: "org.zwobble.hobgoblin.compiler",
+ nativeTypes: [
+ {
+ hobgoblin: "math.BigDecimal",
+ java: "java.math.BigDecimal",
+ },
+ ],
},
},
generators: [
diff --git a/hobgoblin/src/ast/typed.hob b/hobgoblin/src/ast/typed.hob
index b03dffe..6343024 100644
--- a/hobgoblin/src/ast/typed.hob
+++ b/hobgoblin/src/ast/typed.hob
@@ -8,6 +8,7 @@ import {
SimpleStructType,
StructType,
SumType,
+ Table,
Type,
TypeOrConstructor,
} from types;
@@ -58,6 +59,7 @@ struct TypedNativeTypeDefinitionNode {
struct TypedQueryDefinitionNode {
field name: String;
+ field relation: Relation;
field docComment: DocComment;
field source: Source;
}
@@ -101,3 +103,13 @@ struct TypedTableDefinitionNode {
field docComment: DocComment;
field source: Source;
}
+
+// == Queries ==
+
+sum Relation {
+ variant RelationTable;
+}
+
+struct RelationTable {
+ field table: Table;
+}
diff --git a/hobgoblin/src/ast/untyped.hob b/hobgoblin/src/ast/untyped.hob
index 33e3fe0..fb0116b 100644
--- a/hobgoblin/src/ast/untyped.hob
+++ b/hobgoblin/src/ast/untyped.hob
@@ -1,4 +1,5 @@
import {DocComment} from ast;
+import {BigDecimal} from math;
import {Source} from sources;
import {NamespaceName} from types;
@@ -60,7 +61,6 @@ struct UntypedNativeTypeDefinitionNode {
struct UntypedQueryDefinitionNode {
field name: String;
- field databaseSchema: UntypedTypeLevelExpressionNode;
field statements: List[UntypedStatementNode];
field docComment: DocComment;
field source: Source;
@@ -102,7 +102,7 @@ sum UntypedDatabaseSchemaStatementNode {
struct UntypedTableDefinitionNode {
field name: String;
field rowType: UntypedTypeLevelExpressionNode;
- field primaryKey: String;
+ field primaryKey: UntypedTypeLevelReferenceNode;
field docComment: DocComment;
field source: Source;
}
@@ -155,12 +155,25 @@ struct UntypedReturnNode {
// == Expressions ==
sum UntypedExpressionNode {
+ variant UntypedBinaryOperationNode;
variant UntypedCallNode;
variant UntypedFunctionExpressionNode;
variant UntypedMemberAccessNode;
+ variant UntypedNumberLiteralNode;
variant UntypedReferenceNode;
}
+struct UntypedBinaryOperationNode {
+ field operator: UntypedBinaryOperator;
+ field left: UntypedExpressionNode;
+ field right: UntypedExpressionNode;
+ field source: Source;
+}
+
+enum UntypedBinaryOperator {
+ variant equals;
+}
+
struct UntypedCallNode {
field receiver: UntypedExpressionNode;
field args: List[UntypedExpressionNode];
@@ -175,7 +188,12 @@ struct UntypedFunctionExpressionNode {
struct UntypedMemberAccessNode {
field receiver: UntypedExpressionNode;
- field fieldName: String;
+ field memberName: String;
+ field source: Source;
+}
+
+struct UntypedNumberLiteralNode {
+ field value: BigDecimal;
field source: Source;
}
diff --git a/hobgoblin/src/math.hob b/hobgoblin/src/math.hob
new file mode 100644
index 0000000..9560ae3
--- /dev/null
+++ b/hobgoblin/src/math.hob
@@ -0,0 +1 @@
+native BigDecimal {}
diff --git a/hobgoblin/src/output/lang/sql/ast.hob b/hobgoblin/src/output/lang/sql/ast.hob
index d70e7bc..16e7b64 100644
--- a/hobgoblin/src/output/lang/sql/ast.hob
+++ b/hobgoblin/src/output/lang/sql/ast.hob
@@ -8,6 +8,7 @@ struct SqlScript {
sum SqlStatement {
variant SqlCreateTableStatement;
+ variant SqlSelectStatement;
}
struct SqlCreateTableStatement {
@@ -21,6 +22,21 @@ struct SqlColumnDefinition {
field typeName: SqlIdentifier;
}
+struct SqlSelectStatement {
+ field columns: List[SqlResultColumn];
+ field from: SqlIdentifier;
+ field orderBy: List[SqlOrderingTerm];
+}
+
+struct SqlResultColumn {
+ field expression: SqlExpression;
+ field alias: SqlIdentifier;
+}
+
+struct SqlOrderingTerm {
+ field expression: SqlExpression;
+}
+
// == Table constraints ==
sum SqlTableConstraint {
@@ -31,6 +47,21 @@ struct SqlPrimaryKeyConstraint {
field columns: List[SqlIdentifier];
}
+// == Expressions ==
+
+sum SqlExpression {
+ variant SqlIntLiteral;
+ variant SqlRef;
+}
+
+struct SqlIntLiteral {
+ field value: Int64;
+}
+
+struct SqlRef {
+ field name: SqlIdentifier;
+}
+
// == Identifiers ==
struct SqlIdentifier {
diff --git a/hobgoblin/src/types.hob b/hobgoblin/src/types.hob
index 2473b6c..fe39906 100644
--- a/hobgoblin/src/types.hob
+++ b/hobgoblin/src/types.hob
@@ -24,3 +24,6 @@ native TypeOrConstructor[T] {
native Field {
}
+
+native Table {
+}
diff --git a/pom.xml b/pom.xml
index b5260da..4544db5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
<groupId>org.zwobble.hobgoblin</groupId>
<artifactId>hobgoblin</artifactId>
- <version>0.0.9</version>
+ <version>0.0.10</version>
<packaging>jlink</packaging>
<name>hobgoblin</name>
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/Relation.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/Relation.java
new file mode 100644
index 0000000..7f08714
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/Relation.java
@@ -0,0 +1,18 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.typed;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.Relation imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.Relation imports
+
+public sealed interface Relation permits org.zwobble.hobgoblin.compiler.ast.typed.RelationTable {
+ public interface Builder {
+ public org.zwobble.hobgoblin.compiler.ast.typed.Relation build();
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.Relation.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.Relation.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.Relation body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.Relation body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTable.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTable.java
new file mode 100644
index 0000000..d62753e
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTable.java
@@ -0,0 +1,32 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.typed;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.RelationTable imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.RelationTable imports
+
+public record RelationTable(
+ org.zwobble.hobgoblin.compiler.types.Table table
+) implements org.zwobble.hobgoblin.compiler.ast.typed.Relation {
+ public static org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.Builder(org.zwobble.hobgoblin.compiler.types.HobgoblinNativeTypes.arbitraryTable());
+ }
+
+ public record Builder(
+ org.zwobble.hobgoblin.compiler.types.Table table
+ ) implements org.zwobble.hobgoblin.compiler.ast.typed.Relation.Builder {
+ public org.zwobble.hobgoblin.compiler.ast.typed.RelationTable build() {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.RelationTable(table);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.Builder withTable(org.zwobble.hobgoblin.compiler.types.Table table) {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.Builder(table);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.RelationTable body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.RelationTable body
+}
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 abfe470..dc61d28 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,32 +7,42 @@ package org.zwobble.hobgoblin.compiler.ast.typed;
public record TypedQueryDefinitionNode(
String name,
+ org.zwobble.hobgoblin.compiler.ast.typed.Relation relation,
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("", org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder("", org.zwobble.hobgoblin.compiler.ast.typed.RelationTable.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
String name,
+ org.zwobble.hobgoblin.compiler.ast.typed.Relation relation,
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, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode(name, relation, 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, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, relation, docComment, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withRelation(org.zwobble.hobgoblin.compiler.ast.typed.Relation relation) {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, relation, docComment, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder withRelation(org.zwobble.hobgoblin.compiler.ast.typed.Relation.Builder relation) {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, relation.build(), 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, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, relation, 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, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder(name, relation, docComment, source);
}
// Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode.Builder body
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNode.java
new file mode 100644
index 0000000..b6fb024
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNode.java
@@ -0,0 +1,58 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode imports
+
+public record UntypedBinaryOperationNode(
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator operator,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode left,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode right,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator.EQUALS, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ }
+
+ public record Builder(
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator operator,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode left,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode right,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+ ) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode build() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode(operator, left, right, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder withOperator(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator operator) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(operator, left, right, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder withLeft(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode left) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(operator, left, right, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder withLeft(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder left) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(operator, left.build(), right, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder withRight(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode right) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(operator, left, right, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder withRight(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder right) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(operator, left, right.build(), source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder(operator, left, right, source);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperator.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperator.java
new file mode 100644
index 0000000..b479e9b
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperator.java
@@ -0,0 +1,13 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator imports
+
+public enum UntypedBinaryOperator {
+ EQUALS
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedCallNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedCallNode.java
index 2c19adb..8da37c1 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedCallNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedCallNode.java
@@ -11,7 +11,7 @@ public record UntypedCallNode(
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedCallNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedCallNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode.arbitrary().build(), java.util.List.of(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedCallNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.arbitrary().build(), java.util.List.of(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedExpressionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedExpressionNode.java
index a5c54a0..2fd499e 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedExpressionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedExpressionNode.java
@@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode imports
// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode imports
-public sealed interface UntypedExpressionNode permits org.zwobble.hobgoblin.compiler.ast.untyped.UntypedCallNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode {
+public sealed interface UntypedExpressionNode permits org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedCallNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode, org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode {
public interface Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode build();
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 4e410f3..d4a6034 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
@@ -11,7 +11,7 @@ public record UntypedFunctionExpressionNode(
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder(java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedFunctionExpressionNode.Builder(java.util.List.of(), org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNode.java
index 6a6e406..4fef83e 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNode.java
@@ -7,36 +7,36 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
public record UntypedMemberAccessNode(
org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode receiver,
- String fieldName,
+ String memberName,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode.arbitrary().build(), "", org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.arbitrary().build(), "", org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode receiver,
- String fieldName,
+ String memberName,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder {
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode build() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode(receiver, fieldName, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode(receiver, memberName, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder withReceiver(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode receiver) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver, fieldName, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver, memberName, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder withReceiver(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder receiver) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver.build(), fieldName, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver.build(), memberName, source);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder withFieldName(String fieldName) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver, fieldName, source);
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder withMemberName(String memberName) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver, memberName, source);
}
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver, fieldName, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder(receiver, memberName, source);
}
// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode.Builder body
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNode.java
new file mode 100644
index 0000000..1e041ea
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNode.java
@@ -0,0 +1,38 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode imports
+
+public record UntypedNumberLiteralNode(
+ java.math.BigDecimal value,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder(org.zwobble.hobgoblin.compiler.math.HobgoblinNativeMath.arbitraryBigDecimal(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ }
+
+ public record Builder(
+ java.math.BigDecimal value,
+ org.zwobble.hobgoblin.compiler.sources.Source source
+ ) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode.Builder {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode build() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode(value, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder withValue(java.math.BigDecimal value) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder(value, source);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder withSource(org.zwobble.hobgoblin.compiler.sources.Source source) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder(value, source);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode 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 ee1ddbc..b48a95c 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,60 +7,50 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
public record UntypedQueryDefinitionNode(
String name,
- org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode databaseSchema,
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("", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), 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(), org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
String name,
- org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode databaseSchema,
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, databaseSchema, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode(name, 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, databaseSchema, statements, docComment, source);
- }
-
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withDatabaseSchema(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode databaseSchema) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, databaseSchema, statements, docComment, source);
- }
-
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder withDatabaseSchema(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode.Builder databaseSchema) {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, databaseSchema.build(), statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, 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, databaseSchema, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, 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, databaseSchema, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, 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, databaseSchema, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, 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, databaseSchema, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, 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, databaseSchema, statements, docComment, source);
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode.Builder(name, 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/ast/untyped/UntypedReturnNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNode.java
index f115b24..03c3446 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedReturnNode.java
@@ -10,7 +10,7 @@ public record UntypedReturnNode(
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStatementNode {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode.Builder(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNode.java
index ebff463..072d12a 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNode.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNode.java
@@ -8,18 +8,18 @@ package org.zwobble.hobgoblin.compiler.ast.untyped;
public record UntypedTableDefinitionNode(
String name,
org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode rowType,
- String primaryKey,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode primaryKey,
org.zwobble.hobgoblin.compiler.ast.DocComment docComment,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaStatementNode {
public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder arbitrary() {
- return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), "", org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder("", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.arbitrary().build(), org.zwobble.hobgoblin.compiler.ast.HobgoblinNativeAst.arbitraryDocComment(), org.zwobble.hobgoblin.compiler.sources.HobgoblinNativeSources.arbitrarySource());
}
public record Builder(
String name,
org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode rowType,
- String primaryKey,
+ org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode primaryKey,
org.zwobble.hobgoblin.compiler.ast.DocComment docComment,
org.zwobble.hobgoblin.compiler.sources.Source source
) implements org.zwobble.hobgoblin.compiler.ast.untyped.UntypedDatabaseSchemaStatementNode.Builder {
@@ -39,10 +39,14 @@ public record UntypedTableDefinitionNode(
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder(name, rowType.build(), primaryKey, docComment, source);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder withPrimaryKey(String primaryKey) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder withPrimaryKey(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode primaryKey) {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder(name, rowType, primaryKey, docComment, source);
}
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder withPrimaryKey(org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode.Builder primaryKey) {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder(name, rowType, primaryKey.build(), docComment, source);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder withDocComment(org.zwobble.hobgoblin.compiler.ast.DocComment docComment) {
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode.Builder(name, rowType, primaryKey, docComment, source);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/math/HobgoblinNativeMath.java b/src/main/java/org/zwobble/hobgoblin/compiler/math/HobgoblinNativeMath.java
new file mode 100644
index 0000000..1592b50
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/math/HobgoblinNativeMath.java
@@ -0,0 +1,11 @@
+package org.zwobble.hobgoblin.compiler.math;
+
+import java.math.BigDecimal;
+
+public class HobgoblinNativeMath {
+ private HobgoblinNativeMath() {}
+
+ public static BigDecimal arbitraryBigDecimal() {
+ return BigDecimal.ZERO;
+ }
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGenerator.java
index be847d5..4a23fa1 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGenerator.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGenerator.java
@@ -1,7 +1,11 @@
package org.zwobble.hobgoblin.compiler.output.generators.sql;
+import org.zwobble.hobgoblin.compiler.ast.typed.Relation;
+import org.zwobble.hobgoblin.compiler.ast.typed.RelationTable;
+import org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode;
import org.zwobble.hobgoblin.compiler.ast.typed.TypedTableDefinitionNode;
import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
+import org.zwobble.hobgoblin.compiler.errors.InternalError;
import org.zwobble.hobgoblin.compiler.output.lang.sql.ast.*;
import org.zwobble.hobgoblin.compiler.typechecker.TypesInfo;
import org.zwobble.hobgoblin.compiler.types.SimpleStructType;
@@ -50,6 +54,55 @@ public class SqlGenerator {
}
}
+ public SqlStatement generateQueryDefinition(
+ TypedQueryDefinitionNode queryDefinition,
+ TypesInfo typesInfo
+ ) {
+ return generateRelation(queryDefinition.relation(), typesInfo);
+ }
+
+ SqlSelectStatement generateRelation(Relation relation, TypesInfo typesInfo) {
+ switch (relation) {
+ case RelationTable relationTable -> {
+ var table = relationTable.table();
+ var schemaInfo = typesInfo.databaseSchemaInfo(table.databaseSchema());
+ var tableInfo = schemaInfo.tables().get(table.name());
+
+ var fields = typesInfo.fieldsOf(tableInfo.rowType())
+ .orElse(List.of());
+
+ // The type-checker should have verified that the row type has
+ // fields, so don't try to handle gracefully here.
+ if (fields.isEmpty()) {
+ throw new InternalError("row type has no fields");
+ }
+
+ var columns = fields.stream()
+ .map(field -> {
+ var columnName = generateColumnName(field.name());
+ return new SqlResultColumn(
+ new SqlRef(columnName),
+ columnName
+ );
+ })
+ .toList();
+
+ // Order by the primary key to ensure stable ordering.
+ var orderBy = List.of(
+ new SqlOrderingTerm(new SqlRef(
+ generateColumnName(tableInfo.primaryKey().name())
+ ))
+ );
+
+ return new SqlSelectStatement(
+ columns,
+ generateTableName(table.name()),
+ orderBy
+ );
+ }
+ }
+ }
+
private SqlIdentifier generateColumnName(String fieldName) {
return new SqlIdentifier(Casing.lowerCamelCaseToSnakeCase(fieldName));
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sqlscripts/SqlScriptsGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sqlscripts/SqlScriptsGenerator.java
index 5089271..f34a629 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sqlscripts/SqlScriptsGenerator.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/sqlscripts/SqlScriptsGenerator.java
@@ -1,9 +1,6 @@
package org.zwobble.hobgoblin.compiler.output.generators.sqlscripts;
-import org.zwobble.hobgoblin.compiler.ast.typed.TypedDatabaseSchemaDefinitionNode;
-import org.zwobble.hobgoblin.compiler.ast.typed.TypedDatabaseSchemaStatementNode;
-import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode;
-import org.zwobble.hobgoblin.compiler.ast.typed.TypedTableDefinitionNode;
+import org.zwobble.hobgoblin.compiler.ast.typed.*;
import org.zwobble.hobgoblin.compiler.config.OutputConfig;
import org.zwobble.hobgoblin.compiler.output.generators.Generator;
import org.zwobble.hobgoblin.compiler.output.generators.GeneratorDefinition;
@@ -70,13 +67,46 @@ public class SqlScriptsGenerator implements Generator {
) throws IOException {
for (var namespace : namespaces) {
for (var namespaceStatement : namespace.body()) {
- if (namespaceStatement instanceof TypedDatabaseSchemaDefinitionNode databaseSchemaDefinition) {
- generateDatabaseSchemaDefinition(
- databaseSchemaDefinition,
- namespace.namespaceName(),
- typesInfo
- );
- }
+ generateNamespaceStatement(
+ namespaceStatement,
+ namespace.namespaceName(),
+ typesInfo
+ );
+ }
+ }
+ }
+
+ private void generateNamespaceStatement(
+ TypedNamespaceStatementNode namespaceStatement,
+ NamespaceName namespaceName,
+ TypesInfo typesInfo
+ ) throws IOException {
+ switch (namespaceStatement) {
+ case TypedDatabaseSchemaDefinitionNode databaseSchemaDefinition ->
+ generateDatabaseSchemaDefinition(
+ databaseSchemaDefinition,
+ namespaceName,
+ typesInfo
+ );
+
+ case TypedEnumDefinitionNode _ -> {
+ }
+
+ case TypedNativeTypeDefinitionNode _ -> {
+ }
+
+ case TypedQueryDefinitionNode queryDefinition -> {
+ generateQueryDefinition(
+ queryDefinition,
+ namespaceName,
+ typesInfo
+ );
+ }
+
+ case TypedStructDefinitionNode _ -> {
+ }
+
+ case TypedSumDefinitionNode _ -> {
}
}
}
@@ -110,6 +140,17 @@ public class SqlScriptsGenerator implements Generator {
};
}
+ private void generateQueryDefinition(
+ TypedQueryDefinitionNode queryDefinition,
+ NamespaceName namespaceName,
+ TypesInfo typesInfo
+ ) throws IOException {
+ var sqlQuery = this.sqlGenerator.generateQueryDefinition(queryDefinition, typesInfo);
+ var sqlScript = new SqlScript(List.of(sqlQuery));
+
+ write(namespaceName, queryDefinition.name(), sqlScript);
+ }
+
private void write(
NamespaceName namespaceName,
String schemaName,
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 ef1562e..7f0c17a 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
@@ -68,6 +68,10 @@ public class SqlWriter {
case SqlCreateTableStatement createTableStatement -> {
writeCreateTableStatement(createTableStatement);
}
+
+ case SqlSelectStatement selectStatement -> {
+ writeSelectStatement(selectStatement);
+ }
}
}
@@ -104,6 +108,43 @@ public class SqlWriter {
this.writeIdentifier(column.typeName());
}
+ private void writeSelectStatement(SqlSelectStatement selectStatement) throws IOException {
+ this.writer.write("SELECT");
+ this.writer.newLine();
+ this.writer.indent();
+
+ writeWithSeparator(
+ selectStatement.columns(),
+ column -> {
+ this.writeExpression(column.expression());
+ this.writer.write(" AS ");
+ this.writeIdentifier(column.alias());
+ },
+ () -> {
+ this.writer.write(",");
+ this.writer.newLine();
+ }
+ );
+
+ this.writer.newLine();
+ this.writer.dedent();
+ this.writer.write("FROM ");
+ this.writeIdentifier(selectStatement.from());
+
+ if (!selectStatement.orderBy().isEmpty()) {
+ this.writer.newLine();
+ this.writer.write("ORDER BY ");
+
+ writeWithSeparator(
+ selectStatement.orderBy(),
+ orderingTerm -> this.writeExpression(orderingTerm.expression()),
+ () -> this.writer.write(", ")
+ );
+ }
+
+ this.writer.write(";");
+ }
+
// == Table constraints ==
void writeTableConstraint(SqlTableConstraint tableConstraint) throws IOException {
@@ -124,6 +165,28 @@ public class SqlWriter {
this.writer.write(")");
}
+ // == Expressions ==
+
+ void writeExpression(SqlExpression expression) throws IOException {
+ switch (expression) {
+ case SqlIntLiteral intLiteral -> {
+ this.writeIntLiteral(intLiteral);
+ }
+
+ case SqlRef ref -> {
+ this.writeRef(ref);
+ }
+ }
+ }
+
+ private void writeIntLiteral(SqlIntLiteral intLiteral) throws IOException {
+ this.writer.write(Long.toString(intLiteral.value()));
+ }
+
+ private void writeRef(SqlRef ref) throws IOException {
+ this.writeIdentifier(ref.name());
+ }
+
// == Identifiers ==
private void writeIdentifier(SqlIdentifier name) throws IOException {
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlExpression.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlExpression.java
new file mode 100644
index 0000000..8479160
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlExpression.java
@@ -0,0 +1,18 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression imports
+
+public sealed interface SqlExpression permits org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral, org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef {
+ public interface Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression build();
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteral.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteral.java
new file mode 100644
index 0000000..8a6c3a4
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteral.java
@@ -0,0 +1,32 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral imports
+
+public record SqlIntLiteral(
+ long value
+) implements org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.Builder(0);
+ }
+
+ public record Builder(
+ long value
+ ) implements org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral(value);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.Builder withValue(long value) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.Builder(value);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTerm.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTerm.java
new file mode 100644
index 0000000..80ca2e6
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTerm.java
@@ -0,0 +1,36 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm imports
+
+public record SqlOrderingTerm(
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression expression
+) {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.arbitrary().build());
+ }
+
+ public record Builder(
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression expression
+ ) {
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm(expression);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder withExpression(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression expression) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder(expression);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder withExpression(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression.Builder expression) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder(expression.build());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRef.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRef.java
new file mode 100644
index 0000000..156e6ab
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRef.java
@@ -0,0 +1,36 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef imports
+
+public record SqlRef(
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier name
+) implements org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier.arbitrary().build());
+ }
+
+ public record Builder(
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier name
+ ) implements org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef(name);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder withName(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder(name);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder withName(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier.Builder name) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder(name.build());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumn.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumn.java
new file mode 100644
index 0000000..26516b0
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumn.java
@@ -0,0 +1,46 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn imports
+
+public record SqlResultColumn(
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression expression,
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier alias
+) {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral.arbitrary().build(), org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier.arbitrary().build());
+ }
+
+ public record Builder(
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression expression,
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier alias
+ ) {
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn(expression, alias);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder withExpression(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression expression) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder(expression, alias);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder withExpression(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression.Builder expression) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder(expression.build(), alias);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder withAlias(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier alias) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder(expression, alias);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder withAlias(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier.Builder alias) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder(expression, alias.build());
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatement.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatement.java
new file mode 100644
index 0000000..8bd29a2
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatement.java
@@ -0,0 +1,72 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement imports
+
+public record SqlSelectStatement(
+ java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn> columns,
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier from,
+ java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm> orderBy
+) implements org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder arbitrary() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(java.util.List.of(), org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier.arbitrary().build(), java.util.List.of());
+ }
+
+ public record Builder(
+ java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn> columns,
+ org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier from,
+ java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm> orderBy
+ ) implements org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement.Builder {
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement build() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder withColumns(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn> columns) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder addColumn(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn column) {
+ var columns = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>(this.columns);
+ columns.add(column);
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder addColumn(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn.Builder column) {
+ var columns = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>(this.columns);
+ columns.add(column.build());
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder withFrom(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier from) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder withFrom(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier.Builder from) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from.build(), orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder withOrderBy(java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm> orderBy) {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder addOrderByElement(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm orderByElement) {
+ var orderBy = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm>(this.orderBy);
+ orderBy.add(orderByElement);
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder addOrderByElement(org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm.Builder orderByElement) {
+ var orderBy = new java.util.ArrayList<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm>(this.orderBy);
+ orderBy.add(orderByElement.build());
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder(columns, from, orderBy);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement.Builder body
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement body
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlStatement.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlStatement.java
index 0f90dc1..a6d4ab2 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlStatement.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlStatement.java
@@ -5,7 +5,7 @@ package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement imports
// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement imports
-public sealed interface SqlStatement permits org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement {
+public sealed interface SqlStatement permits org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlCreateTableStatement, org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement {
public interface Builder {
public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlStatement build();
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/parser/OperatorPrecedence.java b/src/main/java/org/zwobble/hobgoblin/compiler/parser/OperatorPrecedence.java
index b63ca86..13c38db 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/OperatorPrecedence.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/OperatorPrecedence.java
@@ -2,4 +2,5 @@ package org.zwobble.hobgoblin.compiler.parser;
enum OperatorPrecedence {
CALL,
+ COMPARE,
}
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 cdeeedd..b4bb07d 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Parser.java
@@ -9,6 +9,7 @@ import org.zwobble.hobgoblin.compiler.types.QualifiedTypeName;
import org.zwobble.sourcetext.SourcePosition;
import org.zwobble.sourcetext.SourceText;
+import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -74,7 +75,7 @@ public class Parser {
);
tokens.skip(TokenType.SYMBOL_BRACE_CLOSE);
- tokens.skip(TokenType.KEYWORD_FROM);
+ tokens.skip(TokenType.IDENTIFIER, "from");
var isSibling = tokens.trySkip(TokenType.SYMBOL_DOT);
@@ -256,9 +257,6 @@ public class Parser {
tokens.skip(TokenType.SYMBOL_PAREN_OPEN);
tokens.skip(TokenType.SYMBOL_PAREN_CLOSE);
- tokens.skip(TokenType.IDENTIFIER, "on");
- var databaseSchema = parseTypeLevelExpression(tokens);
-
tokens.skip(TokenType.SYMBOL_BRACE_OPEN);
var statements = parseMany(
@@ -274,7 +272,6 @@ public class Parser {
return new UntypedQueryDefinitionNode(
name,
- databaseSchema,
statements,
docComment,
source
@@ -413,7 +410,7 @@ public class Parser {
tokens.skip(TokenType.SYMBOL_SEMICOLON);
tokens.skip(TokenType.IDENTIFIER, "primaryKey");
- var primaryKey = parseIdentifier(tokens);
+ var primaryKey = parseTypeLevelReference(tokens);
tokens.skip(TokenType.SYMBOL_SEMICOLON);
tokens.skip(TokenType.SYMBOL_BRACE_CLOSE);
@@ -497,6 +494,10 @@ public class Parser {
}
private static UntypedTypeLevelReferenceNode parsePrimaryTypeLevelExpression(TokenIterator tokens) {
+ return parseTypeLevelReference(tokens);
+ }
+
+ private static UntypedTypeLevelReferenceNode parseTypeLevelReference(TokenIterator tokens) {
var start = tokens.startPosition();
var name = parseIdentifier(tokens);
@@ -560,6 +561,8 @@ public class Parser {
) {
if (tokens.isNext(TokenType.SYMBOL_DOLLAR)) {
return parseFunctionExpression(tokens);
+ } else if (tokens.isNext(TokenType.NUMBER)) {
+ return parseNumberLiteral(tokens);
} else if (tokens.isNext(TokenType.IDENTIFIER)) {
return parseReference(tokens);
} else {
@@ -594,6 +597,18 @@ public class Parser {
);
}
+ private static UntypedNumberLiteralNode parseNumberLiteral(TokenIterator tokens) {
+ var start = tokens.startPosition();
+
+ var valueToken = tokens.next(TokenType.NUMBER);
+ var value = new BigDecimal(valueToken.charSequence().toString());
+
+ var end = tokens.endPosition();
+ var source = createSource(start, end);
+
+ return new UntypedNumberLiteralNode(value, source);
+ }
+
private static UntypedReferenceNode parseReference(TokenIterator tokens) {
var start = tokens.startPosition();
@@ -605,6 +620,44 @@ public class Parser {
return new UntypedReferenceNode(name, source);
}
+ private static class BinaryOperationParser implements OperationParser<OperatorPrecedence, UntypedExpressionNode> {
+ private final UntypedBinaryOperator operator;
+ private final OperatorPrecedence precedence;
+ private final TokenType operatorTokenType;
+
+ public BinaryOperationParser(
+ UntypedBinaryOperator operator,
+ OperatorPrecedence precedence,
+ TokenType operatorTokenType
+ ) {
+ this.operator = operator;
+ this.precedence = precedence;
+ this.operatorTokenType = operatorTokenType;
+ }
+
+ @Override
+ public OperatorPrecedence precedence() {
+ return precedence;
+ }
+
+ @Override
+ public List<TokenType> operatorTokenTypes() {
+ return List.of(operatorTokenType);
+ }
+
+ @Override
+ public UntypedExpressionNode parse(SourcePosition start, UntypedExpressionNode left, TokenIterator tokens) {
+ tokens.skip(operatorTokenType);
+
+ var right = parseExpression(tokens, Optional.of(precedence));
+
+ var end = tokens.endPosition();
+ var source = createSource(start, end);
+
+ return new UntypedBinaryOperationNode(operator, left, right, source);
+ }
+ }
+
private static final OperationParser<OperatorPrecedence, UntypedExpressionNode> CALL_PARSER = new OperationParser<>() {
@Override
public OperatorPrecedence precedence() {
@@ -666,8 +719,15 @@ public class Parser {
}
};
+ private static final BinaryOperationParser EQUALS_OPERATION_PARSER = new BinaryOperationParser(
+ UntypedBinaryOperator.EQUALS,
+ OperatorPrecedence.COMPARE,
+ TokenType.SYMBOL_EQUALS_EQUALS
+ );
+
private static final Map<TokenType, OperationParser<OperatorPrecedence, UntypedExpressionNode>> OPERATION_PARSERS = Stream.of(
CALL_PARSER,
+ EQUALS_OPERATION_PARSER,
MEMBER_ACCESS_PARSER
)
.flatMap(parser ->
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/parser/TokenType.java b/src/main/java/org/zwobble/hobgoblin/compiler/parser/TokenType.java
index 1181fca..5896d6f 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/TokenType.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/TokenType.java
@@ -4,11 +4,11 @@ enum TokenType {
DOC_COMMENT,
END,
IDENTIFIER,
+ NUMBER,
WHITESPACE,
KEYWORD_ENUM,
KEYWORD_FIELD,
- KEYWORD_FROM,
KEYWORD_IMPORT,
KEYWORD_NATIVE,
KEYWORD_STRUCT,
@@ -22,6 +22,7 @@ enum TokenType {
SYMBOL_DOLLAR,
SYMBOL_DOT,
SYMBOL_DOT_DOT,
+ SYMBOL_EQUALS_EQUALS,
SYMBOL_FAT_ARROW,
SYMBOL_FORWARD_SLASH,
SYMBOL_PAREN_OPEN,
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Tokenizer.java b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Tokenizer.java
index 56c2123..b36ca12 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/parser/Tokenizer.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/parser/Tokenizer.java
@@ -55,6 +55,11 @@ class Tokenizer {
return identifierOrKeyword;
}
+ var number = tokenizeNumber(iterator);
+ if (number.isPresent()) {
+ return number;
+ }
+
var docComment = tokenizeDocComment(iterator);
if (docComment.isPresent()) {
return docComment;
@@ -126,8 +131,6 @@ class Tokenizer {
tokenType = TokenType.KEYWORD_ENUM;
} else if (CharSequence.compare(sourceRange.charSequence(), "field") == 0) {
tokenType = TokenType.KEYWORD_FIELD;
- } else if (CharSequence.compare(sourceRange.charSequence(), "from") == 0) {
- tokenType = TokenType.KEYWORD_FROM;
} else if (CharSequence.compare(sourceRange.charSequence(), "import") == 0) {
tokenType = TokenType.KEYWORD_IMPORT;
} else if (CharSequence.compare(sourceRange.charSequence(), "native") == 0) {
@@ -146,6 +149,30 @@ class Tokenizer {
return Optional.of(token);
}
+ private static Optional<Token> tokenizeNumber(CharacterIterator iterator) {
+ var firstChar = iterator.peek();
+ if (!(firstChar >= '1' && firstChar <= '9')) {
+ return Optional.empty();
+ }
+
+ var start = iterator.position();
+
+ while (true) {
+ var nextChar = iterator.peek();
+ if (!(nextChar >= '0' && nextChar <= '9')) {
+ if (Character.isAlphabetic(nextChar)) {
+ throw new ParseError("number must contain only digits", iterator.characterSourceRange());
+ }
+
+ var end = iterator.position();
+ var token = new Token(TokenType.NUMBER, start.to(end));
+ return Optional.of(token);
+ }
+
+ iterator.skip();
+ }
+ }
+
private static Optional<Token> tokenizeSymbol(CharacterIterator iterator) {
TokenType tokenType;
var start = iterator.position();
@@ -158,6 +185,10 @@ class Tokenizer {
tokenType = TokenType.SYMBOL_FAT_ARROW;
iterator.skip();
iterator.skip();
+ } else if ("==".contentEquals(iterator.peekSequence(2))) {
+ tokenType = TokenType.SYMBOL_EQUALS_EQUALS;
+ iterator.skip();
+ iterator.skip();
} else {
switch (iterator.peek()) {
case '{':
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 10dfc20..c3f664c 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
@@ -22,6 +22,8 @@ public class TypeChecker {
private TypeChecker() {
}
+ // == Namespaces ==
+
public static List<TypedNamespaceNode> typeCheckNamespaces(
List<UntypedNamespaceNode> untypedNamespaces,
TypeCheckerGlobalContext context
@@ -90,6 +92,8 @@ public class TypeChecker {
return typedNamespaceNodes;
}
+ // == Namespace statements ==
+
static Optional<Type> declareNamespaceStatement(
UntypedNamespaceStatementNode untyped,
TypeCheckerNamespaceContext context
@@ -159,16 +163,19 @@ public class TypeChecker {
UntypedDatabaseSchemaDefinitionNode untyped,
TypeCheckerNamespaceContext context
) {
+ var databaseSchema = new DatabaseSchema(context.namespaceName(), untyped.name());
var databaseSchemaInfo = new DatabaseSchemaInfo(new LinkedHashMap<>());
var typedBody = untyped.body().stream()
- .map(statement -> typeCheckDatabaseSchemaStatement(statement, databaseSchemaInfo, context))
+ .map(statement -> typeCheckDatabaseSchemaStatement(
+ statement,
+ databaseSchema,
+ databaseSchemaInfo,
+ context
+ ))
.toList();
- context.defineDatabaseSchema(
- new DatabaseSchema(context.namespaceName(), untyped.name()),
- databaseSchemaInfo
- );
+ context.defineDatabaseSchema(databaseSchema, databaseSchemaInfo);
return new TypedDatabaseSchemaDefinitionNode(
untyped.name(),
@@ -282,8 +289,12 @@ public class TypeChecker {
UntypedQueryDefinitionNode untyped,
TypeCheckerNamespaceContext context
) {
+ var value = evalStatements(untyped.statements(), context);
+ var table = (Table) value;
+
return new TypedQueryDefinitionNode(
untyped.name(),
+ new RelationTable(table),
untyped.docComment(),
untyped.source()
);
@@ -497,19 +508,28 @@ public class TypeChecker {
}
}
+ // == Database schema statements ==
+
static TypedDatabaseSchemaStatementNode typeCheckDatabaseSchemaStatement(
UntypedDatabaseSchemaStatementNode statement,
+ DatabaseSchema databaseSchema,
DatabaseSchemaInfo databaseSchemaInfo,
TypeCheckerNamespaceContext context
) {
return switch (statement) {
case UntypedTableDefinitionNode untypedTableDefinition ->
- typeCheckTableDefinition(untypedTableDefinition, databaseSchemaInfo, context);
+ typeCheckTableDefinition(
+ untypedTableDefinition,
+ databaseSchema,
+ databaseSchemaInfo,
+ context
+ );
};
}
private static TypedTableDefinitionNode typeCheckTableDefinition(
UntypedTableDefinitionNode untyped,
+ DatabaseSchema databaseSchema,
DatabaseSchemaInfo databaseSchemaInfo,
TypeCheckerNamespaceContext context
) {
@@ -523,16 +543,23 @@ public class TypeChecker {
);
}
+ // In principle, we should check that fields is non-empty. In practice,
+ // we implicitly check this by requiring a primary key.
var fields = context.fieldsOf(rowType).orElse(List.of());
+
var primaryKeyField = fields.stream()
- .filter(field -> field.name().equals(untyped.primaryKey()))
+ .filter(field -> field.name().equals(untyped.primaryKey().name()))
.findFirst();
if (primaryKeyField.isEmpty()) {
- // TODO: more precise source.
- throw new NoSuchFieldError(rowType, untyped.primaryKey(), untyped.source());
+ throw new NoSuchFieldError(
+ rowType,
+ untyped.primaryKey().name(),
+ untyped.primaryKey().source()
+ );
}
- var tableInfo = new TableInfo(rowType, primaryKeyField.get());
+ var table = new Table(databaseSchema, untyped.name());
+ var tableInfo = new TableInfo(table, rowType, primaryKeyField.get());
databaseSchemaInfo.tables().put(untyped.name(), tableInfo);
@@ -545,6 +572,8 @@ public class TypeChecker {
);
}
+ // == Type-level expressions ==
+
static TypedTypeLevelExpressionNode<? extends TypeLevelValue> typeCheckTypeLevelExpression(
UntypedTypeLevelExpressionNode untyped,
TypeCheckerNamespaceContext context
@@ -630,7 +659,7 @@ public class TypeChecker {
// TODO: handle not a type-level value
if (!(type instanceof TypeLevelValueType(TypeLevelValue value))) {
- throw new UnexpectedTypeError(new TypeSet.MetaType(), type, source);
+ throw new UnexpectedTypeError(new TypeSet.TypeLevelValue(), type, source);
}
return value;
@@ -650,4 +679,91 @@ public class TypeChecker {
);
}
}
+
+ // == Statements ==
+
+ private static TypeLevelValue evalStatements(
+ List<UntypedStatementNode> statements,
+ TypeCheckerNamespaceContext context
+ ) {
+ for (var statement : statements) {
+ switch (statement) {
+ case UntypedReturnNode untypedReturn -> {
+ // TODO: test multiple returns.
+ return evalExpression(untypedReturn.expression(), context);
+ }
+ }
+ }
+
+ throw new UnsupportedOperationException("TODO");
+ }
+
+ // == Expressions ==
+
+ static TypeLevelValue evalExpression(
+ UntypedExpressionNode expression,
+ TypeCheckerNamespaceContext context
+ ) {
+ switch (expression) {
+ case UntypedBinaryOperationNode _ -> {
+ throw new UnsupportedOperationException("TODO");
+ }
+ case UntypedCallNode _ -> {
+ throw new UnsupportedOperationException("TODO");
+ }
+ case UntypedFunctionExpressionNode _ -> {
+ throw new UnsupportedOperationException("TODO");
+ }
+ case UntypedMemberAccessNode memberAccess -> {
+ return evalMemberAccess(memberAccess, context);
+ }
+ case UntypedNumberLiteralNode numberLiteral -> {
+ return evalNumberLiteral(numberLiteral);
+ }
+ case UntypedReferenceNode reference -> {
+ return lookupTypeLevelValue(reference.name(), reference.source(), context);
+ }
+ }
+ }
+
+ private static TypeLevelValue evalMemberAccess(
+ UntypedMemberAccessNode memberAccess,
+ TypeCheckerNamespaceContext context
+ ) {
+ var receiver = evalExpression(memberAccess.receiver(), context);
+ switch (receiver) {
+ case DatabaseSchema databaseSchema -> {
+ var schemaInfo = context.databaseSchemaInfo(databaseSchema);
+ var tableInfo = schemaInfo.tables().get(memberAccess.memberName());
+ if (tableInfo != null) {
+ return tableInfo.table();
+ }
+ }
+
+ case Table table -> {
+ switch (memberAccess.memberName()) {
+ case "where":
+ return new RelationMethod(new RelationTable(table), "where");
+
+ default:
+ break;
+ }
+ }
+
+ case ConstantNumber _, Type _, TypeConstructor<?> _, RelationMethod _ -> {
+ }
+ }
+
+ throw new NoSuchMemberError(
+ new TypeLevelValueType(receiver),
+ memberAccess.memberName(),
+ memberAccess.source()
+ );
+ }
+
+ private static TypeLevelValue evalNumberLiteral(
+ UntypedNumberLiteralNode numberLiteral
+ ) {
+ return new ConstantNumber(numberLiteral.value());
+ }
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceContext.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceContext.java
index b18769d..4a82c05 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceContext.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerNamespaceContext.java
@@ -64,6 +64,10 @@ public class TypeCheckerNamespaceContext {
this.typesInfo.defineDatabaseSchema(databaseSchema, databaseSchemaInfo);
}
+ public DatabaseSchemaInfo databaseSchemaInfo(DatabaseSchema databaseSchema) {
+ return this.typesInfo.databaseSchemaInfo(databaseSchema);
+ }
+
public void defineEnumType(EnumType enumType, List<EnumVariant> enumVariants) {
this.typesInfo.defineEnumType(enumType, enumVariants);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NoSuchMemberError.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NoSuchMemberError.java
new file mode 100644
index 0000000..b2b1d55
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NoSuchMemberError.java
@@ -0,0 +1,24 @@
+package org.zwobble.hobgoblin.compiler.typechecker.errors;
+
+import org.zwobble.hobgoblin.compiler.errors.SourceError;
+import org.zwobble.hobgoblin.compiler.sources.Source;
+import org.zwobble.hobgoblin.compiler.types.Type;
+
+public class NoSuchMemberError extends SourceError {
+ private final Type type;
+ private final String memberName;
+
+ public NoSuchMemberError(Type type, String memberName, Source source) {
+ super(type.describe() + " does not have a member named " + memberName, source);
+ this.type = type;
+ this.memberName = memberName;
+ }
+
+ public Type type() {
+ return type;
+ }
+
+ public String memberName() {
+ return memberName;
+ }
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/ConstantNumber.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/ConstantNumber.java
new file mode 100644
index 0000000..bd16d81
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/ConstantNumber.java
@@ -0,0 +1,12 @@
+package org.zwobble.hobgoblin.compiler.types;
+
+import java.math.BigDecimal;
+
+public record ConstantNumber(
+ BigDecimal value
+) implements TypeLevelValue {
+ @Override
+ public String describe() {
+ return value.toString();
+ }
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/HobgoblinNativeTypes.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/HobgoblinNativeTypes.java
index 96efbd2..186557e 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/types/HobgoblinNativeTypes.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/HobgoblinNativeTypes.java
@@ -40,4 +40,12 @@ public class HobgoblinNativeTypes {
public static Field arbitraryField() {
return new Field("", arbitraryType(), NullSource.INSTANCE);
}
+
+ public static DatabaseSchema arbitraryDatabaseSchema() {
+ return new DatabaseSchema(arbitraryNamespaceName(), "");
+ }
+
+ public static Table arbitraryTable() {
+ return new Table(arbitraryDatabaseSchema(), "");
+ }
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/RelationMethod.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/RelationMethod.java
new file mode 100644
index 0000000..87ba7fa
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/RelationMethod.java
@@ -0,0 +1,10 @@
+package org.zwobble.hobgoblin.compiler.types;
+
+import org.zwobble.hobgoblin.compiler.ast.typed.Relation;
+
+public record RelationMethod(Relation relation, String name) implements TypeLevelValue {
+ @Override
+ public String describe() {
+ return name;
+ }
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/Table.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/Table.java
new file mode 100644
index 0000000..a33e226
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/Table.java
@@ -0,0 +1,8 @@
+package org.zwobble.hobgoblin.compiler.types;
+
+public record Table(DatabaseSchema databaseSchema, String name) implements TypeLevelValue {
+ @Override
+ public String describe() {
+ return databaseSchema.describe() + "." + name;
+ }
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/TableInfo.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/TableInfo.java
index 6632e51..b991b54 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/types/TableInfo.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/TableInfo.java
@@ -1,6 +1,7 @@
package org.zwobble.hobgoblin.compiler.types;
public record TableInfo(
+ Table table,
SimpleStructType rowType,
Field primaryKey
) {
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeLevelValue.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeLevelValue.java
index 8208521..e0f7042 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeLevelValue.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeLevelValue.java
@@ -1,5 +1,5 @@
package org.zwobble.hobgoblin.compiler.types;
-public sealed interface TypeLevelValue permits DatabaseSchema, Type, TypeConstructor {
+public sealed interface TypeLevelValue permits ConstantNumber, DatabaseSchema, RelationMethod, Table, Type, TypeConstructor {
String describe();
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeSet.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeSet.java
index c3896d9..3a64b85 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeSet.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/TypeSet.java
@@ -23,4 +23,11 @@ public sealed interface TypeSet {
return "type constructor";
}
}
+
+ record TypeLevelValue() implements TypeSet {
+ @Override
+ public String describe() {
+ return "type-level value";
+ }
+ }
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java
index a914081..756f3bf 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java
@@ -30,4 +30,12 @@ public class Types {
public static Type databaseSchema(DatabaseSchema databaseSchema) {
return new TypeLevelValueType(databaseSchema);
}
+
+ public static Type relationMethod(RelationMethod method) {
+ return new TypeLevelValueType(method);
+ }
+
+ public static Type table(Table table) {
+ return new TypeLevelValueType(table);
+ }
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTableMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTableMatcher.java
new file mode 100644
index 0000000..3aff4dc
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/RelationTableMatcher.java
@@ -0,0 +1,41 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.typed;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher imports
+
+public final class RelationTableMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher isRelationTable() {
+ return new org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.RelationTable>> submatchers;
+
+ private RelationTableMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.RelationTable>> 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.typed.RelationTable.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher withTable(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.types.Table> table) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.RelationTable>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("table", org.zwobble.hobgoblin.compiler.ast.typed.RelationTable::table, (org.zwobble.precisely.Matcher) table));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java
index bf3272d..d9a6bc5 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedQueryDefinitionNodeMatcher.java
@@ -36,6 +36,12 @@ public final class TypedQueryDefinitionNodeMatcher implements org.zwobble.precis
return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher(submatchers);
}
+ public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher withRelation(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.Relation> relation) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("relation", org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode::relation, (org.zwobble.precisely.Matcher) relation));
+ return new org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher(submatchers);
+ }
+
public org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher withDocComment(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.DocComment> docComment) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("docComment", org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNode::docComment, (org.zwobble.precisely.Matcher) docComment));
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNodeMatcher.java
new file mode 100644
index 0000000..63cf1d8
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedBinaryOperationNodeMatcher.java
@@ -0,0 +1,59 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher imports
+
+public final class UntypedBinaryOperationNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher isUntypedBinaryOperationNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode>> submatchers;
+
+ private UntypedBinaryOperationNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode>> 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.UntypedBinaryOperationNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher withOperator(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator> operator) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("operator", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode::operator, (org.zwobble.precisely.Matcher) operator));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher withLeft(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode> left) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("left", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode::left, (org.zwobble.precisely.Matcher) left));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher withRight(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedExpressionNode> right) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("right", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode::right, (org.zwobble.precisely.Matcher) right));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher 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.UntypedBinaryOperationNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNodeMatcher.java
index ffe9804..c11f7ef 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedMemberAccessNodeMatcher.java
@@ -36,9 +36,9 @@ public final class UntypedMemberAccessNodeMatcher implements org.zwobble.precise
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNodeMatcher(submatchers);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNodeMatcher withFieldName(org.zwobble.precisely.Matcher<? super String> fieldName) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNodeMatcher withMemberName(org.zwobble.precisely.Matcher<? super String> memberName) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode>>(this.submatchers);
- submatchers.add(org.zwobble.precisely.Matchers.has("fieldName", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode::fieldName, (org.zwobble.precisely.Matcher) fieldName));
+ submatchers.add(org.zwobble.precisely.Matchers.has("memberName", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode::memberName, (org.zwobble.precisely.Matcher) memberName));
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNodeMatcher(submatchers);
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNodeMatcher.java
new file mode 100644
index 0000000..b6b0f86
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedNumberLiteralNodeMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.ast.untyped;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher imports
+
+public final class UntypedNumberLiteralNodeMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher isUntypedNumberLiteralNode() {
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode>> submatchers;
+
+ private UntypedNumberLiteralNodeMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode>> 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.UntypedNumberLiteralNode.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher withValue(org.zwobble.precisely.Matcher<? super java.math.BigDecimal> value) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode::value, (org.zwobble.precisely.Matcher) value));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher 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.UntypedNumberLiteralNode>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("source", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode::source, (org.zwobble.precisely.Matcher) source));
+ return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher body
+}
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 2e0ab23..adcc2d9 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,12 +36,6 @@ 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 withDatabaseSchema(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelExpressionNode> databaseSchema) {
- 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("databaseSchema", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode::databaseSchema, (org.zwobble.precisely.Matcher) databaseSchema));
- 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/ast/untyped/UntypedTableDefinitionNodeMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java
index 6f8bdfc..d2b55d2 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ast/untyped/UntypedTableDefinitionNodeMatcher.java
@@ -42,7 +42,7 @@ public final class UntypedTableDefinitionNodeMatcher implements org.zwobble.prec
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers);
}
- public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher withPrimaryKey(org.zwobble.precisely.Matcher<? super String> primaryKey) {
+ public org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher withPrimaryKey(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTypeLevelReferenceNode> primaryKey) {
var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode>>(this.submatchers);
submatchers.add(org.zwobble.precisely.Matchers.has("primaryKey", org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNode::primaryKey, (org.zwobble.precisely.Matcher) primaryKey));
return new org.zwobble.hobgoblin.compiler.ast.untyped.UntypedTableDefinitionNodeMatcher(submatchers);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGeneratorTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGeneratorTests.java
new file mode 100644
index 0000000..0438baf
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/generators/sql/SqlGeneratorTests.java
@@ -0,0 +1,69 @@
+package org.zwobble.hobgoblin.compiler.output.generators.sql;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.hobgoblin.compiler.ast.typed.RelationTable;
+import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
+import org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier;
+import org.zwobble.hobgoblin.compiler.sources.NullSource;
+import org.zwobble.hobgoblin.compiler.typechecker.TypesInfoInMemory;
+import org.zwobble.hobgoblin.compiler.types.*;
+import org.zwobble.hobgoblin.compiler.util.SequencedMaps;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher.isSqlOrderingTerm;
+import static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher.isSqlRef;
+import static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher.isSqlResultColumn;
+import static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher.isSqlSelectStatement;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+import static org.zwobble.precisely.Matchers.isSequence;
+
+public class SqlGeneratorTests {
+ @Test
+ public void relationTableIsTranslatedToSelectFromTable() {
+ var namespaceName = NamespaceName.of("App");
+ var databaseSchema = new DatabaseSchema(namespaceName, "blog");
+ var table = new Table(databaseSchema, "authors");
+ var authorType = new SimpleStructType(namespaceName, "Author");
+ var authorIdField = new Field("id", NativeTypes.INT_32, NullSource.INSTANCE);
+ var authorNameField = new Field("name", NativeTypes.STRING, NullSource.INSTANCE);
+
+ var typesInfo = TypesInfoInMemory.empty();
+ var databaseSchemaInfo = new DatabaseSchemaInfo(SequencedMaps.ofEntries(
+ Map.entry("authors", new TableInfo(table, authorType, authorIdField))
+ ));
+ typesInfo.defineDatabaseSchema(databaseSchema, databaseSchemaInfo);
+ typesInfo.defineStructType(authorType, Optional.of(List.of(authorIdField, authorNameField)));
+
+ var sqlGenerator = new SqlGenerator();
+
+ var relation = RelationTable.arbitrary()
+ .withTable(table)
+ .build();
+
+ var statement = sqlGenerator.generateRelation(relation, typesInfo);
+
+ assertThat(statement, isSqlSelectStatement()
+ .withColumns(isSequence(
+ isSqlResultColumn()
+ .withExpression(isSqlRef().withName(equalTo(id("id"))))
+ .withAlias(equalTo(id("id"))),
+ isSqlResultColumn()
+ .withExpression(isSqlRef().withName(equalTo(id("name"))))
+ .withAlias(equalTo(id("name")))
+ ))
+ .withFrom(equalTo(id("authors")))
+ .withOrderBy(isSequence(
+ isSqlOrderingTerm()
+ .withExpression(isSqlRef().withName(equalTo(id("id"))))
+ ))
+ );
+ }
+
+ private SqlIdentifier id(String value) {
+ return new SqlIdentifier(value);
+ }
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java
index 42b075f..20d6dac 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/SqlWriterTests.java
@@ -105,6 +105,75 @@ public class SqlWriterTests {
));
}
+ // === Select statements ===
+
+ @Test
+ public void minimalSelectStatement() throws IOException {
+ var sql = SqlSelectStatement.arbitrary()
+ .addColumn(SqlResultColumn.arbitrary()
+ .withExpression(ref("a"))
+ .withAlias(id("x"))
+ )
+ .addColumn(SqlResultColumn.arbitrary()
+ .withExpression(ref("b"))
+ .withAlias(id("y"))
+ )
+ .withFrom(id("blah"))
+ .build();
+
+ var string = write(writer -> writer.writeStatement(sql));
+
+ assertThat(string, equalTo("""
+ SELECT
+ a AS x,
+ b AS y
+ FROM blah;"""
+ ));
+ }
+
+ @Test
+ public void selectStatementWithSingleOrderByExpression() throws IOException {
+ var sql = SqlSelectStatement.arbitrary()
+ .addColumn(SqlResultColumn.arbitrary()
+ .withExpression(ref("a"))
+ .withAlias(id("x"))
+ )
+ .withFrom(id("blah"))
+ .addOrderByElement(SqlOrderingTerm.arbitrary().withExpression(ref("b")))
+ .build();
+
+ var string = write(writer -> writer.writeStatement(sql));
+
+ assertThat(string, equalTo("""
+ SELECT
+ a AS x
+ FROM blah
+ ORDER BY b;"""
+ ));
+ }
+
+ @Test
+ public void selectStatementWithMultipleOrderByExpressions() throws IOException {
+ var sql = SqlSelectStatement.arbitrary()
+ .addColumn(SqlResultColumn.arbitrary()
+ .withExpression(ref("a"))
+ .withAlias(id("x"))
+ )
+ .withFrom(id("blah"))
+ .addOrderByElement(SqlOrderingTerm.arbitrary().withExpression(ref("b")))
+ .addOrderByElement(SqlOrderingTerm.arbitrary().withExpression(ref("c")))
+ .build();
+
+ var string = write(writer -> writer.writeStatement(sql));
+
+ assertThat(string, equalTo("""
+ SELECT
+ a AS x
+ FROM blah
+ ORDER BY b, c;"""
+ ));
+ }
+
// == Table constraints ==
@Test
@@ -130,6 +199,28 @@ public class SqlWriterTests {
assertThat(string, equalTo("PRIMARY KEY (a, b)"));
}
+ // === Expressions ===
+
+ @Test
+ public void intLiteral() throws IOException {
+ var sql = SqlIntLiteral.arbitrary()
+ .withValue(42)
+ .build();
+
+ var string = write(writer -> writer.writeExpression(sql));
+
+ assertThat(string, equalTo("42"));
+ }
+
+ @Test
+ public void ref() throws IOException {
+ var sql = ref("a");
+
+ var string = write(writer -> writer.writeExpression(sql));
+
+ assertThat(string, equalTo("a"));
+ }
+
// == Test utilities ==
private String write(SqlWriter.Write write) throws IOException {
@@ -147,6 +238,9 @@ public class SqlWriterTests {
private SqlIdentifier id(String value) {
return new SqlIdentifier(value);
+ }
+ private SqlRef ref(String name) {
+ return new SqlRef(id(name));
}
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteralMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteralMatcher.java
new file mode 100644
index 0000000..36fe6be
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlIntLiteralMatcher.java
@@ -0,0 +1,41 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher imports
+
+public final class SqlIntLiteralMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher isSqlIntLiteral() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral>> submatchers;
+
+ private SqlIntLiteralMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral>> 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.output.lang.sql.ast.SqlIntLiteral.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher withValue(org.zwobble.precisely.Matcher<? super java.lang.Long> value) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("value", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteral::value, (org.zwobble.precisely.Matcher) value));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIntLiteralMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTermMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTermMatcher.java
new file mode 100644
index 0000000..b947f47
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlOrderingTermMatcher.java
@@ -0,0 +1,41 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher imports
+
+public final class SqlOrderingTermMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher isSqlOrderingTerm() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm>> submatchers;
+
+ private SqlOrderingTermMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm>> 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.output.lang.sql.ast.SqlOrderingTerm.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher withExpression(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression> expression) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("expression", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm::expression, (org.zwobble.precisely.Matcher) expression));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTermMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRefMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRefMatcher.java
new file mode 100644
index 0000000..c56f266
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlRefMatcher.java
@@ -0,0 +1,41 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher imports
+
+public final class SqlRefMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher isSqlRef() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef>> submatchers;
+
+ private SqlRefMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef>> 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.output.lang.sql.ast.SqlRef.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher withName(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier> name) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("name", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRef::name, (org.zwobble.precisely.Matcher) name));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlRefMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumnMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumnMatcher.java
new file mode 100644
index 0000000..772b6c5
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlResultColumnMatcher.java
@@ -0,0 +1,47 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher imports
+
+public final class SqlResultColumnMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher isSqlResultColumn() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>> submatchers;
+
+ private SqlResultColumnMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>> 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.output.lang.sql.ast.SqlResultColumn.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher withExpression(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlExpression> expression) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("expression", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn::expression, (org.zwobble.precisely.Matcher) expression));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher withAlias(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier> alias) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("alias", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn::alias, (org.zwobble.precisely.Matcher) alias));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumnMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java
new file mode 100644
index 0000000..db254ca
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/sql/ast/SqlSelectStatementMatcher.java
@@ -0,0 +1,53 @@
+// Generated by hobgoblin.
+
+package org.zwobble.hobgoblin.compiler.output.lang.sql.ast;
+
+// Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher imports
+// Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher imports
+
+public final class SqlSelectStatementMatcher implements org.zwobble.precisely.Matcher<java.lang.Object> {
+ public static org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher isSqlSelectStatement() {
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher(java.util.List.of());
+ }
+
+ private final java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement>> submatchers;
+
+ private SqlSelectStatementMatcher(
+ java.util.List<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement>> 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.output.lang.sql.ast.SqlSelectStatement.class, this.submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher withColumns(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlResultColumn>> columns) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("columns", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement::columns, (org.zwobble.precisely.Matcher) columns));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher withFrom(org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlIdentifier> from) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("from", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement::from, (org.zwobble.precisely.Matcher) from));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher(submatchers);
+ }
+
+ public org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher withOrderBy(org.zwobble.precisely.Matcher<? super java.util.List<org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlOrderingTerm>> orderBy) {
+ var submatchers = new java.util.ArrayList<org.zwobble.precisely.Matcher<? super org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement>>(this.submatchers);
+ submatchers.add(org.zwobble.precisely.Matchers.has("orderBy", org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatement::orderBy, (org.zwobble.precisely.Matcher) orderBy));
+ return new org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher(submatchers);
+ }
+
+ // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher body
+ // Custom area end: org.zwobble.hobgoblin.compiler.output.lang.sql.ast.SqlSelectStatementMatcher body
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserBinaryOperationTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserBinaryOperationTests.java
new file mode 100644
index 0000000..ea2f673
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserBinaryOperationTests.java
@@ -0,0 +1,26 @@
+package org.zwobble.hobgoblin.compiler.parser;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperator;
+
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedBinaryOperationNodeMatcher.isUntypedBinaryOperationNode;
+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;
+import static org.zwobble.precisely.Matchers.equalTo;
+
+public class ParserBinaryOperationTests {
+ @Test
+ public void canParseEquality() {
+ var source = "a == b";
+
+ var node = parseString(source, Parser::parseTopLevelExpression);
+
+ assertThat(node, isUntypedBinaryOperationNode()
+ .withOperator(equalTo(UntypedBinaryOperator.EQUALS))
+ .withLeft(isUntypedReferenceNode().withName(equalTo("a")))
+ .withRight(isUntypedReferenceNode().withName(equalTo("b")))
+ );
+ }
+}
+
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserMemberAccessTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserMemberAccessTests.java
index d28cc2b..f096b93 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserMemberAccessTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserMemberAccessTests.java
@@ -19,7 +19,7 @@ public class ParserMemberAccessTests {
.withReceiver(isUntypedReferenceNode()
.withName(equalTo("author"))
)
- .withFieldName(equalTo("name"))
+ .withMemberName(equalTo("name"))
);
}
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNumberTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNumberTests.java
new file mode 100644
index 0000000..92f11ee
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserNumberTests.java
@@ -0,0 +1,24 @@
+package org.zwobble.hobgoblin.compiler.parser;
+
+import org.junit.jupiter.api.Test;
+
+import java.math.BigDecimal;
+
+import static org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNodeMatcher.isUntypedNumberLiteralNode;
+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 ParserNumberTests {
+ @Test
+ public void canParseNumber() {
+ var source = "42";
+
+ var node = parseString(source, Parser::parseTopLevelExpression);
+
+ assertThat(node, isUntypedNumberLiteralNode()
+ .withValue(equalTo(BigDecimal.valueOf(42)))
+ );
+ }
+}
+
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 e7676c9..e5b5a45 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserQueryDefinitionTests.java
@@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test;
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;
@@ -15,14 +14,13 @@ public class ParserQueryDefinitionTests {
@Test
public void canParseQueryDefinitionWithNoStatements() {
var source = """
- query allAuthors() on BlogAppDatabase {
+ query allAuthors() {
}""";
var node = parseString(source, Parser::parseNamespaceStatement);
assertThat(node, isUntypedQueryDefinitionNode()
.withName(equalTo("allAuthors"))
- .withDatabaseSchema(isUntypedTypeLevelReferenceNode().withName(equalTo("BlogAppDatabase")))
.withStatements(isSequence())
);
}
@@ -30,7 +28,7 @@ public class ParserQueryDefinitionTests {
@Test
public void canParseQueryDefinitionWithSingleStatement() {
var source = """
- query allAuthors() on BlogAppDatabase {
+ query allAuthors() {
return x;
}""";
@@ -38,7 +36,6 @@ public class ParserQueryDefinitionTests {
assertThat(node, isUntypedQueryDefinitionNode()
.withName(equalTo("allAuthors"))
- .withDatabaseSchema(isUntypedTypeLevelReferenceNode().withName(equalTo("BlogAppDatabase")))
.withStatements(isSequence(
isUntypedReturnNode()
.withExpression(isUntypedReferenceNode()
@@ -52,7 +49,7 @@ public class ParserQueryDefinitionTests {
@Test
public void canParseQueryDefinitionWithMultipleStatements() {
var source = """
- query allAuthors() on BlogAppDatabase {
+ query allAuthors() {
return x;
return y;
}""";
@@ -61,7 +58,6 @@ public class ParserQueryDefinitionTests {
assertThat(node, isUntypedQueryDefinitionNode()
.withName(equalTo("allAuthors"))
- .withDatabaseSchema(isUntypedTypeLevelReferenceNode().withName(equalTo("BlogAppDatabase")))
.withStatements(isSequence(
isUntypedReturnNode()
.withExpression(isUntypedReferenceNode()
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java
index 3c3b259..cb1e1cb 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/ParserTableDefinitionTests.java
@@ -25,7 +25,7 @@ public class ParserTableDefinitionTests {
assertThat(node, isUntypedTableDefinitionNode()
.withName(equalTo("posts"))
.withRowType(isUntypedTypeLevelReferenceNode().withName(equalTo("Post")))
- .withPrimaryKey(equalTo("id"))
+ .withPrimaryKey(isUntypedTypeLevelReferenceNode().withName(equalTo("id")))
);
}
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/parser/TokenizerTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/parser/TokenizerTests.java
index d5b7347..b434ac0 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/parser/TokenizerTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/parser/TokenizerTests.java
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test;
import org.zwobble.sourcetext.SourceRange;
import org.zwobble.sourcetext.SourceText;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.zwobble.precisely.AssertThat.assertThat;
import static org.zwobble.precisely.Matchers.equalTo;
import static org.zwobble.precisely.Matchers.isSequence;
@@ -41,17 +42,6 @@ public class TokenizerTests {
}
@Test
- public void keywordFromIsTokenized() {
- var sourceText = SourceText.fromString("<string>", "from");
-
- var tokens = Tokenizer.tokenize(sourceText);
-
- assertThat(tokens.tokens(), isSequence(
- equalTo(new Token(TokenType.KEYWORD_FROM, sourceRange(sourceText, 0, 4)))
- ));
- }
-
- @Test
public void keywordImportIsTokenized() {
var sourceText = SourceText.fromString("<string>", "import");
@@ -129,6 +119,38 @@ public class TokenizerTests {
}
@Test
+ public void digitsAreTokenizedAsNumber() {
+ var sourceText = SourceText.fromString("<string>", "42");
+
+ var tokens = Tokenizer.tokenize(sourceText);
+
+ assertThat(tokens.tokens(), isSequence(
+ equalTo(new Token(TokenType.NUMBER, sourceRange(sourceText, 0, 2)))
+ ));
+ }
+
+ @Test
+ public void digitsFollowedByNonDigitIdentifierCharacterProducesError() {
+ var sourceText = SourceText.fromString("<string>", "42a");
+
+ var error = assertThrows(ParseError.class, () -> Tokenizer.tokenize(sourceText));
+
+ assertThat(error.getMessage(), equalTo("number must contain only digits"));
+ }
+
+ @Test
+ public void digitsMayBeFollowedByNonDigitNonIdentifierCharacter() {
+ var sourceText = SourceText.fromString("<string>", "42==");
+
+ var tokens = Tokenizer.tokenize(sourceText);
+
+ assertThat(tokens.tokens(), isSequence(
+ equalTo(new Token(TokenType.NUMBER, sourceRange(sourceText, 0, 2))),
+ equalTo(new Token(TokenType.SYMBOL_EQUALS_EQUALS, sourceRange(sourceText, 2, 4)))
+ ));
+ }
+
+ @Test
public void symbolBraceOpenIsTokenized() {
var sourceText = SourceText.fromString("<string>", "{");
@@ -206,6 +228,17 @@ public class TokenizerTests {
}
@Test
+ public void symbolEqualsEqualsIsTokenized() {
+ var sourceText = SourceText.fromString("<string>", "==");
+
+ var tokens = Tokenizer.tokenize(sourceText);
+
+ assertThat(tokens.tokens(), isSequence(
+ equalTo(new Token(TokenType.SYMBOL_EQUALS_EQUALS, sourceRange(sourceText, 0, 2)))
+ ));
+ }
+
+ @Test
public void symbolFatArrowIsTokenized() {
var sourceText = SourceText.fromString("<string>", "=>");
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerDatabaseSchemaDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerDatabaseSchemaDefinitionTests.java
index daecb54..63ed810 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerDatabaseSchemaDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerDatabaseSchemaDefinitionTests.java
@@ -27,9 +27,8 @@ public class TypeCheckerDatabaseSchemaDefinitionTests {
.withName("authors")
.withRowType(UntypedTypeLevelReferenceNode.arbitrary()
.withName("Author")
- .build()
)
- .withPrimaryKey("id")
+ .withPrimaryKey(UntypedTypeLevelReferenceNode.arbitrary().withName("id"))
.build()
)
.build();
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerEvalExpressionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerEvalExpressionTests.java
new file mode 100644
index 0000000..48dde6e
--- /dev/null
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerEvalExpressionTests.java
@@ -0,0 +1,137 @@
+package org.zwobble.hobgoblin.compiler.typechecker;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.hobgoblin.compiler.ast.typed.RelationTable;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedMemberAccessNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode;
+import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
+import org.zwobble.hobgoblin.compiler.sources.NullSource;
+import org.zwobble.hobgoblin.compiler.typechecker.errors.UndeclaredVariableError;
+import org.zwobble.hobgoblin.compiler.typechecker.errors.UnexpectedTypeError;
+import org.zwobble.hobgoblin.compiler.types.*;
+import org.zwobble.hobgoblin.compiler.util.SequencedMaps;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
+
+public class TypeCheckerEvalExpressionTests {
+ // == Member access ==
+
+ @Test
+ public void memberAccessCanReadFieldOnStruct() {
+ var untyped = UntypedMemberAccessNode.arbitrary()
+ .withReceiver(UntypedReferenceNode.arbitrary().withName("blogApp"))
+ .withMemberName("authors")
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+ var databaseSchema = new DatabaseSchema(namespaceName, "blogApp");
+ namespaceContext.declare("blogApp", Types.databaseSchema(databaseSchema), NullSource.INSTANCE);
+ var table = new Table(databaseSchema, "authors");
+ var rowType = new SimpleStructType(namespaceName, "Author");
+ var idField = new Field("id", NativeTypes.INT_32, NullSource.INSTANCE);
+ var databaseSchemaInfo = new DatabaseSchemaInfo(SequencedMaps.ofEntries(
+ Map.entry("authors", new TableInfo(table, rowType, idField))
+ ));
+ namespaceContext.defineDatabaseSchema(databaseSchema, databaseSchemaInfo);
+
+ var typed = TypeChecker.evalExpression(untyped, namespaceContext);
+
+ assertThat(typed, equalTo(table));
+ }
+
+ @Test
+ public void memberAccessOnTableCanReadRelationMethod() {
+ var untyped = UntypedMemberAccessNode.arbitrary()
+ .withReceiver(UntypedReferenceNode.arbitrary().withName("authors"))
+ .withMemberName("where")
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+ var databaseSchema = new DatabaseSchema(namespaceName, "blogApp");
+ var table = new Table(databaseSchema, "authors");
+ namespaceContext.declare("authors", Types.table(table), NullSource.INSTANCE);
+
+ var typed = TypeChecker.evalExpression(untyped, namespaceContext);
+
+ assertThat(typed, equalTo(new RelationMethod(new RelationTable(table), "where")));
+ }
+
+ // == Number literal ==
+
+ @Test
+ public void canEvaluateNumber() {
+ // TODO: infer more precise type for number
+ var untyped = UntypedNumberLiteralNode.arbitrary()
+ .withValue(BigDecimal.valueOf(42))
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+
+ var typed = TypeChecker.evalExpression(untyped, namespaceContext);
+
+ assertThat(typed, equalTo(new ConstantNumber(BigDecimal.valueOf(42))));
+ }
+
+ // == References ==
+
+ @Test
+ public void whenVariableIsTypeLevelValueThenCanEvaluateReference() {
+ var untyped = UntypedReferenceNode.arbitrary()
+ .withName("authors")
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+ var databaseSchema = new DatabaseSchema(namespaceName, "blogApp");
+ var table = new Table(databaseSchema, "authors");
+ namespaceContext.declare("authors", Types.table(table), NullSource.INSTANCE);
+
+ var typed = TypeChecker.evalExpression(untyped, namespaceContext);
+
+ assertThat(typed, equalTo(table));
+ }
+
+ @Test
+ public void whenVariableIsNotTypeLevelValueThenCannotEvaluateReference() {
+ var untyped = UntypedReferenceNode.arbitrary()
+ .withName("count")
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+ namespaceContext.declare("count", NativeTypes.INT_32, NullSource.INSTANCE);
+
+ var error = assertThrows(
+ UnexpectedTypeError.class,
+ () -> TypeChecker.evalExpression(untyped, namespaceContext)
+ );
+
+ assertThat(error.expected(), equalTo(new TypeSet.TypeLevelValue()));
+ }
+
+ @Test
+ public void whenVariableIsNotDeclaredThenCannotEvaluateReference() {
+ var untyped = UntypedReferenceNode.arbitrary()
+ .withName("count")
+ .build();
+ var globalContext = TypeCheckerContextArb.globalContext();
+ var namespaceName = NamespaceName.of("App");
+ var namespaceContext = globalContext.enterNamespace(namespaceName);
+
+ var error = assertThrows(
+ UndeclaredVariableError.class,
+ () -> TypeChecker.evalExpression(untyped, namespaceContext)
+ );
+
+ assertThat(error.variableName(), equalTo("count"));
+ }
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerMetaTypeTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerMetaTypeTests.java
index 074d1df..713cd13 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerMetaTypeTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerMetaTypeTests.java
@@ -27,7 +27,7 @@ public class TypeCheckerMetaTypeTests {
() -> TypeChecker.typeCheckMetaType(untyped, context)
);
- assertThat(error.expected(), equalTo(new TypeSet.MetaType()));
+ assertThat(error.expected(), equalTo(new TypeSet.TypeLevelValue()));
assertThat(error.actual(), equalTo(nativeType));
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java
index 84b3e25..43ffb04 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerQueryDefinitionTests.java
@@ -1,53 +1,42 @@
package org.zwobble.hobgoblin.compiler.typechecker;
import org.junit.jupiter.api.Test;
-import org.zwobble.hobgoblin.compiler.ast.untyped.*;
-import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedQueryDefinitionNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode;
+import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReturnNode;
import org.zwobble.hobgoblin.compiler.sources.NullSource;
-import org.zwobble.hobgoblin.compiler.types.*;
-import org.zwobble.hobgoblin.compiler.util.SequencedMaps;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import org.zwobble.hobgoblin.compiler.types.DatabaseSchema;
+import org.zwobble.hobgoblin.compiler.types.NamespaceName;
+import org.zwobble.hobgoblin.compiler.types.Table;
+import org.zwobble.hobgoblin.compiler.types.Types;
+import static org.zwobble.hobgoblin.compiler.ast.typed.RelationTableMatcher.isRelationTable;
import static org.zwobble.hobgoblin.compiler.ast.typed.TypedQueryDefinitionNodeMatcher.isTypedQueryDefinitionNode;
import static org.zwobble.hobgoblin.compiler.typechecker.TypeCheckerTesting.typeCheckNamespaceStatement;
import static org.zwobble.precisely.AssertThat.assertThat;
-import static org.zwobble.precisely.Matchers.*;
+import static org.zwobble.precisely.Matchers.equalTo;
public class TypeCheckerQueryDefinitionTests {
@Test
public void queryForAllTableRows() {
var untyped = UntypedQueryDefinitionNode.arbitrary()
.withName("allAuthors")
- .withDatabaseSchema(UntypedTypeLevelReferenceNode.arbitrary().withName("blogApp"))
.addStatement(UntypedReturnNode.arbitrary().withExpression(
- UntypedMemberAccessNode.arbitrary()
- .withReceiver(UntypedReferenceNode.arbitrary().withName("blogApp"))
- .withFieldName("authors")
+ UntypedReferenceNode.arbitrary().withName("authors")
))
.build();
var globalContext = TypeCheckerContextArb.globalContext();
var namespaceName = NamespaceName.of("App");
var namespaceContext = globalContext.enterNamespace(namespaceName);
- var authorType = new SimpleStructType(namespaceName, "Author");
- namespaceContext.declare("Author", Types.metaType(authorType), NullSource.INSTANCE);
- var authorIdField = new Field("id", NativeTypes.INT_32, NullSource.INSTANCE);
- namespaceContext.defineStructType(authorType, Optional.of(List.of(
- authorIdField
- )));
var databaseSchema = new DatabaseSchema(namespaceName, "blogApp");
- namespaceContext.defineDatabaseSchema(databaseSchema, new DatabaseSchemaInfo(
- SequencedMaps.ofEntries(
- Map.entry("authors", new TableInfo(authorType, authorIdField))
- )
- ));
+ var table = new Table(databaseSchema, "authors");
+ namespaceContext.declare("authors", Types.table(table), NullSource.INSTANCE);
var typed = typeCheckNamespaceStatement(untyped, namespaceContext);
assertThat(typed, isTypedQueryDefinitionNode()
.withName(equalTo("allAuthors"))
+ .withRelation(isRelationTable().withTable(equalTo(table)))
);
}
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTableDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTableDefinitionTests.java
index 989fa39..9dbee97 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTableDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTableDefinitionTests.java
@@ -26,9 +26,8 @@ public class TypeCheckerTableDefinitionTests {
.withName("authors")
.withRowType(UntypedTypeLevelReferenceNode.arbitrary()
.withName("Author")
- .build()
)
- .withPrimaryKey("id")
+ .withPrimaryKey(UntypedTypeLevelReferenceNode.arbitrary().withName("id"))
.build();
var globalContext = TypeCheckerContextArb.globalContext();
var namespaceContext = globalContext.enterNamespace(NamespaceName.of("App"));
@@ -40,6 +39,7 @@ public class TypeCheckerTableDefinitionTests {
var typed = typeCheckDatabaseSchemaStatement(
untyped,
+ new DatabaseSchema(NamespaceName.of("App"), "blogApp"),
new DatabaseSchemaInfo(new LinkedHashMap<>()),
namespaceContext
);
@@ -69,6 +69,7 @@ public class TypeCheckerTableDefinitionTests {
TableRowTypeMustBeStructError.class,
() -> typeCheckDatabaseSchemaStatement(
untyped,
+ new DatabaseSchema(NamespaceName.of("App"), "blogApp"),
new DatabaseSchemaInfo(new LinkedHashMap<>()),
namespaceContext
)
@@ -83,9 +84,8 @@ public class TypeCheckerTableDefinitionTests {
.withName("authors")
.withRowType(UntypedTypeLevelReferenceNode.arbitrary()
.withName("Author")
- .build()
)
- .withPrimaryKey("id")
+ .withPrimaryKey(UntypedTypeLevelReferenceNode.arbitrary().withName("id"))
.build();
var globalContext = TypeCheckerContextArb.globalContext();
var namespaceContext = globalContext.enterNamespace(NamespaceName.of("App"));
@@ -99,6 +99,7 @@ public class TypeCheckerTableDefinitionTests {
NoSuchFieldError.class,
() -> typeCheckDatabaseSchemaStatement(
untyped,
+ new DatabaseSchema(NamespaceName.of("App"), "blogApp"),
new DatabaseSchemaInfo(new LinkedHashMap<>()),
namespaceContext
)
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTypeLevelReferenceTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTypeLevelReferenceTests.java
index 084be46..98f4f22 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTypeLevelReferenceTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerTypeLevelReferenceTests.java
@@ -40,7 +40,7 @@ public class TypeCheckerTypeLevelReferenceTests {
() -> TypeChecker.typeCheckTypeLevelExpression(untyped, context)
);
- assertThat(error.expected(), equalTo(new TypeSet.MetaType()));
+ assertThat(error.expected(), equalTo(new TypeSet.TypeLevelValue()));
assertThat(error.actual(), equalTo(nativeType));
}