diff options
Diffstat (limited to 'hobgoblin/src')
| -rw-r--r-- | hobgoblin/src/ast/typed.hob | 78 | ||||
| -rw-r--r-- | hobgoblin/src/ast/untyped.hob | 81 | ||||
| -rw-r--r-- | hobgoblin/src/math.hob | 1 | ||||
| -rw-r--r-- | hobgoblin/src/output/lang/sql/ast.hob | 31 | ||||
| -rw-r--r-- | hobgoblin/src/types.hob | 3 |
5 files changed, 193 insertions, 1 deletions
diff --git a/hobgoblin/src/ast/typed.hob b/hobgoblin/src/ast/typed.hob index a734d7c..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; @@ -26,6 +28,7 @@ sum TypedNamespaceStatementNode { variant TypedDatabaseSchemaDefinitionNode; variant TypedEnumDefinitionNode; variant TypedNativeTypeDefinitionNode; + variant TypedQueryDefinitionNode; variant TypedStructDefinitionNode; variant TypedSumDefinitionNode; } @@ -55,6 +58,13 @@ struct TypedNativeTypeDefinitionNode { field source: Source; } +struct TypedQueryDefinitionNode { + field name: String; + field relation: Relation; + field docComment: DocComment; + field source: Source; +} + struct TypedStructDefinitionNode { field typeOrConstructor: TypeOrConstructor[SimpleStructType]; field fields: Option[List[TypedStructFieldDefinitionNode]]; @@ -94,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 c72590a..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; @@ -24,6 +25,7 @@ sum UntypedNamespaceStatementNode { variant UntypedDatabaseSchemaDefinitionNode; variant UntypedEnumDefinitionNode; variant UntypedNativeTypeDefinitionNode; + variant UntypedQueryDefinitionNode; variant UntypedStructDefinitionNode; variant UntypedSumDefinitionNode; @@ -57,6 +59,13 @@ struct UntypedNativeTypeDefinitionNode { field source: Source; } +struct UntypedQueryDefinitionNode { + field name: String; + field statements: List[UntypedStatementNode]; + field docComment: DocComment; + field source: Source; +} + struct UntypedStructDefinitionNode { field name: String; field typeParams: Option[List[UntypedTypeParamNode]]; @@ -93,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; } @@ -105,6 +114,13 @@ struct UntypedTypeParamNode { field source: Source; } +// == Params == + +struct UntypedParamNode { + field name: String; + field source: Source; +} + // == Type-level expressions == sum UntypedTypeLevelExpressionNode { @@ -124,3 +140,66 @@ struct UntypedTypeLevelReferenceNode { field name: String; field source: Source; } + +// == Statements == + +sum UntypedStatementNode { + variant UntypedReturnNode; +} + +struct UntypedReturnNode { + field expression: UntypedExpressionNode; + field source: Source; +} + +// == 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 { + field receiver: UntypedExpressionNode; + field args: List[UntypedExpressionNode]; + field source: Source; +} + +struct UntypedFunctionExpressionNode { + field params: List[UntypedParamNode]; + field body: UntypedExpressionNode; + field source: Source; +} + +struct UntypedMemberAccessNode { + field receiver: UntypedExpressionNode; + field memberName: String; + field source: Source; +} + +struct UntypedNumberLiteralNode { + field value: BigDecimal; + field source: Source; +} + +struct UntypedReferenceNode { + field name: String; + 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 { +} |
