Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union members & version bumps #15

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.21'

- uses: acifani/setup-tinygo@v1
with:
tinygo-version: 0.27.0
tinygo-version: 0.30.0

- name: Install wasm-opt
run: |
Expand Down
4 changes: 2 additions & 2 deletions apex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ config:
module: github.com/apexlang/apex-go
generates:
model/model.go:
module: 'https://deno.land/x/apex_codegen@v0.1.9/go/mod.ts'
module: 'https://deno.land/x/apex_codegen@v0.1.10/go/mod.ts'
visitorClass: InterfacesVisitor
config:
writeTypeInfo: false
runAfter:
- command: tinyjson -all model/model.go
model/msgpack.go:
module: 'https://deno.land/x/apex_codegen@v0.1.9/go/mod.ts'
module: 'https://deno.land/x/apex_codegen@v0.1.10/go/mod.ts'
visitorClass: MsgPackVisitor
model/wapc.go:
module: 'https://deno.land/x/wapc_codegen@v0.0.6/tinygo/mod.ts'
Expand Down
32 changes: 28 additions & 4 deletions ast/definitions.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -317,16 +317,16 @@ type UnionDefinition struct {
Name *Name `json:"name"`
Description *StringValue `json:"description,omitempty"` // Optional
AnnotatedNode
Types []Type `json:"types"`
Members []*UnionMemberDefinition `json:"types"`
}

func NewUnionDefinition(loc *Location, name *Name, description *StringValue, annotations []*Annotation, types []Type) *UnionDefinition {
func NewUnionDefinition(loc *Location, name *Name, description *StringValue, annotations []*Annotation, members []*UnionMemberDefinition) *UnionDefinition {
return &UnionDefinition{
BaseNode: BaseNode{kinds.UnionDefinition, loc},
Name: name,
Description: description,
AnnotatedNode: AnnotatedNode{annotations},
Types: types,
Members: members,
}
}

Expand All @@ -335,6 +335,30 @@ func (d *UnionDefinition) Accept(context Context, visitor Visitor) {
VisitAnnotations(context, visitor, d.Annotations)
}

// UnionMemberDefinition implements Node, Definition
var _ Definition = (*UnionMemberDefinition)(nil)

type UnionMemberDefinition struct {
BaseNode
Description *StringValue `json:"description,omitempty"` // Optional
Type Type `json:"type"`
AnnotatedNode
}

func NewUnionMemberDefinition(loc *Location, description *StringValue, t Type, annotations []*Annotation) *UnionMemberDefinition {
return &UnionMemberDefinition{
BaseNode: BaseNode{kinds.EnumValueDefinition, loc},
Description: description,
Type: t,
AnnotatedNode: AnnotatedNode{annotations},
}
}

func (d *UnionMemberDefinition) Accept(context Context, visitor Visitor) {
visitor.VisitUnionMember(context)
VisitAnnotations(context, visitor, d.Annotations)
}

// EnumDefinition implements Node, Definition
var _ Definition = (*EnumDefinition)(nil)

Expand Down
2 changes: 1 addition & 1 deletion ast/document.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion ast/location.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion ast/nodes.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion ast/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion ast/values.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
23 changes: 19 additions & 4 deletions ast/visitor.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -164,6 +164,9 @@ type Visitor interface {

VisitUnionsBefore(context Context)
VisitUnion(context Context)
VisitUnionMembersBefore(context Context)
VisitUnionMember(context Context)
VisitUnionMembersAfter(context Context)
VisitUnionsAfter(context Context)

VisitAnnotationsBefore(context Context)
Expand Down Expand Up @@ -243,9 +246,12 @@ func (b *BaseVisitor) VisitEnumValuesAfter(context Context) {}
func (b *BaseVisitor) VisitEnumAfter(context Context) {}
func (b *BaseVisitor) VisitEnumsAfter(context Context) {}

func (b *BaseVisitor) VisitUnionsBefore(context Context) {}
func (b *BaseVisitor) VisitUnion(context Context) {}
func (b *BaseVisitor) VisitUnionsAfter(context Context) {}
func (b *BaseVisitor) VisitUnionsBefore(context Context) {}
func (b *BaseVisitor) VisitUnion(context Context) {}
func (b *BaseVisitor) VisitUnionMembersBefore(context Context) {}
func (b *BaseVisitor) VisitUnionMember(context Context) {}
func (b *BaseVisitor) VisitUnionMembersAfter(context Context) {}
func (b *BaseVisitor) VisitUnionsAfter(context Context) {}

func (b *BaseVisitor) VisitAnnotationsBefore(context Context) {}
func (b *BaseVisitor) VisitAnnotationBefore(context Context) {}
Expand Down Expand Up @@ -451,6 +457,15 @@ func (m *MultiVisitor) VisitUnionsBefore(context Context) {
func (m *MultiVisitor) VisitUnion(context Context) {
m.visit(func(v Visitor) { v.VisitUnionsBefore(context) })
}
func (m *MultiVisitor) VisitUnionMembersBefore(context Context) {
m.visit(func(v Visitor) { v.VisitUnionMembersBefore(context) })
}
func (m *MultiVisitor) VisitUnionMember(context Context) {
m.visit(func(v Visitor) { v.VisitUnionMember(context) })
}
func (m *MultiVisitor) VisitUnionMembersAfter(context Context) {
m.visit(func(v Visitor) { v.VisitUnionMembersAfter(context) })
}
func (m *MultiVisitor) VisitUnionsAfter(context Context) {
m.visit(func(v Visitor) { v.VisitUnionsAfter(context) })
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/apex-api/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion cmd/apex-cli/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions cmd/host/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/apexlang/apex-go/cmd/host

go 1.19
go 1.21

require (
github.com/mitchellh/go-homedir v1.1.0
github.com/tetratelabs/wazero v1.0.1
github.com/tetratelabs/wazero v1.6.0
)
4 changes: 2 additions & 2 deletions cmd/host/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/tetratelabs/wazero v1.0.1 h1:xyWBoGyMjYekG3mEQ/W7xm9E05S89kJ/at696d/9yuc=
github.com/tetratelabs/wazero v1.0.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g=
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
2 changes: 1 addition & 1 deletion errors/error.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion errors/syntax.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/apexlang/apex-go

go 1.18
go 1.21

require (
github.com/CosmWasm/tinyjson v0.9.0
github.com/iancoleman/strcase v0.2.0
github.com/iancoleman/strcase v0.3.0
github.com/tetratelabs/tinymem v0.1.0
github.com/wapc/tinygo-msgpack v0.1.6
github.com/wapc/wapc-guest-tinygo v0.3.3
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107 h1:GljFiJysL3S8SBhXWU47Emj34D3pVZgJ+Amj+jhM4fQ=
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107/go.mod h1:5+7QnSKrkIWnpIdhUT2t2EYzXnII3/3MlM0oDsBSbc8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/tetratelabs/tinymem v0.1.0 h1:Qza1JAg9lquPPJ/CIei5qQYx7t18KLie83O2WR6CM58=
github.com/tetratelabs/tinymem v0.1.0/go.mod h1:WFFTZFhLod6lTL+UetFAopVbGaB+KFsVcIY+RUv7NeY=
github.com/wapc/tinygo-msgpack v0.1.6 h1:geW3N0MAVehJBZp1ITnK2J1R2woI/S1APJB+tFShO6Y=
github.com/wapc/tinygo-msgpack v0.1.6/go.mod h1:2P4rQimy/6oQAkytwC2LdtVjLJ2D1dYkQHejfCtZXZQ=
github.com/wapc/wapc-guest-tinygo v0.3.3 h1:jLebiwjVSHLGnS+BRabQ6+XOV7oihVWAc05Hf1SbeR0=
github.com/wapc/wapc-guest-tinygo v0.3.3/go.mod h1:mzM3CnsdSYktfPkaBdZ8v88ZlfUDEy5Jh5XBOV3fYcw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.19
go 1.21

use (
.
Expand Down
2 changes: 1 addition & 1 deletion kinds/kinds.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lexer/lexer.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion location/location.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 7 additions & 1 deletion model.axdl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ type Field {
type Union {
name: string @after("=")
description: string? @docs
types: [TypeRef] @delimiters(["|"])
members: [UnionMember] @delimiters(["|"])
annotations: [Annotation]? @prefix("@")
}

type UnionMember {
description: string? @docs
type: TypeRef
annotations: [Annotation]? @prefix("@")
}

Expand Down
14 changes: 9 additions & 5 deletions model/convert.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Apex Authors.
Copyright 2024 The Apex Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -225,20 +225,24 @@ func (c *Converter) convertUnions(items []*ast.UnionDefinition) []Union {
s[i] = Union{
Description: stringValuePtr(item.Description),
Name: item.Name.Value,
Types: c.convertTypeRefs(item.Types),
Members: c.convertUnionMembers(item.Members),
Annotations: c.convertAnnotations(item.Annotations),
}
}
return s
}

func (c *Converter) convertTypeRefs(items []ast.Type) []TypeRef {
func (c *Converter) convertUnionMembers(items []*ast.UnionMemberDefinition) []UnionMember {
if len(items) == 0 {
return nil
}
s := make([]TypeRef, len(items))
s := make([]UnionMember, len(items))
for i, item := range items {
s[i] = c.convertTypeRef(item)
s[i] = UnionMember{
Description: stringValuePtr(item.Description),
Type: c.convertTypeRef(item.Type),
Annotations: c.convertAnnotations(item.Annotations),
}
}
return s
}
Expand Down
20 changes: 16 additions & 4 deletions model/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading