summaryrefslogtreecommitdiff
path: root/hobgoblin/src
diff options
context:
space:
mode:
Diffstat (limited to 'hobgoblin/src')
-rw-r--r--hobgoblin/src/ast/typed.hob71
-rw-r--r--hobgoblin/src/ast/untyped.hob26
-rw-r--r--hobgoblin/src/math.hob1
-rw-r--r--hobgoblin/src/output/lang/sql/ast.hob31
-rw-r--r--hobgoblin/src/types.hob3
5 files changed, 129 insertions, 3 deletions
diff --git a/hobgoblin/src/ast/typed.hob b/hobgoblin/src/ast/typed.hob
index b03dffe..6ec62ec 100644
--- a/hobgoblin/src/ast/typed.hob
+++ b/hobgoblin/src/ast/typed.hob
@@ -1,4 +1,5 @@
import {DocComment} from ast;
+import {BigDecimal} from math;
import {Source} from sources;
import {
EnumType,
@@ -8,6 +9,7 @@ import {
SimpleStructType,
StructType,
SumType,
+ Table,
Type,
TypeOrConstructor,
} from types;
@@ -58,6 +60,7 @@ struct TypedNativeTypeDefinitionNode {
struct TypedQueryDefinitionNode {
field name: String;
+ field relation: Relation;
field docComment: DocComment;
field source: Source;
}
@@ -101,3 +104,71 @@ struct TypedTableDefinitionNode {
field docComment: DocComment;
field source: Source;
}
+
+// == Params ==
+
+struct TypedParamNode {
+ field name: String;
+ field type: Type;
+ field source: Source;
+}
+
+// == Expressions ==
+
+sum TypedExpressionNode {
+ variant TypedBinaryOperationNode;
+ variant TypedFunctionExpressionNode;
+ variant TypedMemberAccessNode;
+ variant TypedNumberLiteralNode;
+ variant TypedReferenceNode;
+
+ field type: Type;
+}
+
+struct TypedBinaryOperationNode {
+ field operator: TypedBinaryOperator;
+ field left: TypedExpressionNode;
+ field right: TypedExpressionNode;
+ field type: Type;
+ field source: Source;
+}
+
+enum TypedBinaryOperator {
+ variant equals;
+}
+
+struct TypedFunctionExpressionNode {
+ field params: List[TypedParamNode];
+ field body: TypedExpressionNode;
+ field type: Type;
+ field source: Source;
+}
+
+struct TypedMemberAccessNode {
+ field receiver: TypedExpressionNode;
+ field memberName: String;
+ field type: Type;
+ field source: Source;
+}
+
+struct TypedNumberLiteralNode {
+ field value: BigDecimal;
+ field type: Type;
+ field source: Source;
+}
+
+struct TypedReferenceNode {
+ field name: String;
+ field type: Type;
+ 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..570c9e5 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,10 +155,25 @@ struct UntypedReturnNode {
// == Expressions ==
sum UntypedExpressionNode {
+ variant UntypedBinaryOperationNode;
variant UntypedCallNode;
variant UntypedFunctionExpressionNode;
variant UntypedMemberAccessNode;
+ variant UntypedNumberLiteralNode;
variant UntypedReferenceNode;
+
+ field source: Source;
+}
+
+struct UntypedBinaryOperationNode {
+ field operator: UntypedBinaryOperator;
+ field left: UntypedExpressionNode;
+ field right: UntypedExpressionNode;
+ field source: Source;
+}
+
+enum UntypedBinaryOperator {
+ variant equals;
}
struct UntypedCallNode {
@@ -175,7 +190,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 {
+}