Skip to content

Commit a55f514

Browse files
authored
Union members & version bumps (#15)
1 parent ac88d3b commit a55f514

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+747
-466
lines changed

.github/workflows/build.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020

2121
- uses: actions/setup-go@v3
2222
with:
23-
go-version: '1.20'
23+
go-version: '1.21'
2424

2525
- uses: acifani/setup-tinygo@v1
2626
with:
27-
tinygo-version: 0.27.0
27+
tinygo-version: 0.30.0
2828

2929
- name: Install wasm-opt
3030
run: |

apex.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ config:
44
module: github.com/apexlang/apex-go
55
generates:
66
model/model.go:
7-
module: 'https://deno.land/x/apex_codegen@v0.1.9/go/mod.ts'
7+
module: 'https://deno.land/x/apex_codegen@v0.1.10/go/mod.ts'
88
visitorClass: InterfacesVisitor
99
config:
1010
writeTypeInfo: false
1111
runAfter:
1212
- command: tinyjson -all model/model.go
1313
model/msgpack.go:
14-
module: 'https://deno.land/x/apex_codegen@v0.1.9/go/mod.ts'
14+
module: 'https://deno.land/x/apex_codegen@v0.1.10/go/mod.ts'
1515
visitorClass: MsgPackVisitor
1616
model/wapc.go:
1717
module: 'https://deno.land/x/wapc_codegen@v0.0.6/tinygo/mod.ts'

ast/definitions.go

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -317,16 +317,16 @@ type UnionDefinition struct {
317317
Name *Name `json:"name"`
318318
Description *StringValue `json:"description,omitempty"` // Optional
319319
AnnotatedNode
320-
Types []Type `json:"types"`
320+
Members []*UnionMemberDefinition `json:"types"`
321321
}
322322

323-
func NewUnionDefinition(loc *Location, name *Name, description *StringValue, annotations []*Annotation, types []Type) *UnionDefinition {
323+
func NewUnionDefinition(loc *Location, name *Name, description *StringValue, annotations []*Annotation, members []*UnionMemberDefinition) *UnionDefinition {
324324
return &UnionDefinition{
325325
BaseNode: BaseNode{kinds.UnionDefinition, loc},
326326
Name: name,
327327
Description: description,
328328
AnnotatedNode: AnnotatedNode{annotations},
329-
Types: types,
329+
Members: members,
330330
}
331331
}
332332

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

338+
// UnionMemberDefinition implements Node, Definition
339+
var _ Definition = (*UnionMemberDefinition)(nil)
340+
341+
type UnionMemberDefinition struct {
342+
BaseNode
343+
Description *StringValue `json:"description,omitempty"` // Optional
344+
Type Type `json:"type"`
345+
AnnotatedNode
346+
}
347+
348+
func NewUnionMemberDefinition(loc *Location, description *StringValue, t Type, annotations []*Annotation) *UnionMemberDefinition {
349+
return &UnionMemberDefinition{
350+
BaseNode: BaseNode{kinds.EnumValueDefinition, loc},
351+
Description: description,
352+
Type: t,
353+
AnnotatedNode: AnnotatedNode{annotations},
354+
}
355+
}
356+
357+
func (d *UnionMemberDefinition) Accept(context Context, visitor Visitor) {
358+
visitor.VisitUnionMember(context)
359+
VisitAnnotations(context, visitor, d.Annotations)
360+
}
361+
338362
// EnumDefinition implements Node, Definition
339363
var _ Definition = (*EnumDefinition)(nil)
340364

ast/document.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

ast/location.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

ast/nodes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

ast/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

ast/values.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

ast/visitor.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -164,6 +164,9 @@ type Visitor interface {
164164

165165
VisitUnionsBefore(context Context)
166166
VisitUnion(context Context)
167+
VisitUnionMembersBefore(context Context)
168+
VisitUnionMember(context Context)
169+
VisitUnionMembersAfter(context Context)
167170
VisitUnionsAfter(context Context)
168171

169172
VisitAnnotationsBefore(context Context)
@@ -243,9 +246,12 @@ func (b *BaseVisitor) VisitEnumValuesAfter(context Context) {}
243246
func (b *BaseVisitor) VisitEnumAfter(context Context) {}
244247
func (b *BaseVisitor) VisitEnumsAfter(context Context) {}
245248

246-
func (b *BaseVisitor) VisitUnionsBefore(context Context) {}
247-
func (b *BaseVisitor) VisitUnion(context Context) {}
248-
func (b *BaseVisitor) VisitUnionsAfter(context Context) {}
249+
func (b *BaseVisitor) VisitUnionsBefore(context Context) {}
250+
func (b *BaseVisitor) VisitUnion(context Context) {}
251+
func (b *BaseVisitor) VisitUnionMembersBefore(context Context) {}
252+
func (b *BaseVisitor) VisitUnionMember(context Context) {}
253+
func (b *BaseVisitor) VisitUnionMembersAfter(context Context) {}
254+
func (b *BaseVisitor) VisitUnionsAfter(context Context) {}
249255

250256
func (b *BaseVisitor) VisitAnnotationsBefore(context Context) {}
251257
func (b *BaseVisitor) VisitAnnotationBefore(context Context) {}
@@ -451,6 +457,15 @@ func (m *MultiVisitor) VisitUnionsBefore(context Context) {
451457
func (m *MultiVisitor) VisitUnion(context Context) {
452458
m.visit(func(v Visitor) { v.VisitUnionsBefore(context) })
453459
}
460+
func (m *MultiVisitor) VisitUnionMembersBefore(context Context) {
461+
m.visit(func(v Visitor) { v.VisitUnionMembersBefore(context) })
462+
}
463+
func (m *MultiVisitor) VisitUnionMember(context Context) {
464+
m.visit(func(v Visitor) { v.VisitUnionMember(context) })
465+
}
466+
func (m *MultiVisitor) VisitUnionMembersAfter(context Context) {
467+
m.visit(func(v Visitor) { v.VisitUnionMembersAfter(context) })
468+
}
454469
func (m *MultiVisitor) VisitUnionsAfter(context Context) {
455470
m.visit(func(v Visitor) { v.VisitUnionsAfter(context) })
456471
}

cmd/apex-api/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/apex-cli/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

cmd/host/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/apexlang/apex-go/cmd/host
22

3-
go 1.19
3+
go 1.21
44

55
require (
66
github.com/mitchellh/go-homedir v1.1.0
7-
github.com/tetratelabs/wazero v1.0.1
7+
github.com/tetratelabs/wazero v1.6.0
88
)

cmd/host/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
22
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
3-
github.com/tetratelabs/wazero v1.0.1 h1:xyWBoGyMjYekG3mEQ/W7xm9E05S89kJ/at696d/9yuc=
4-
github.com/tetratelabs/wazero v1.0.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
3+
github.com/tetratelabs/wazero v1.6.0 h1:z0H1iikCdP8t+q341xqepY4EWvHEw8Es7tlqiVzlP3g=
4+
github.com/tetratelabs/wazero v1.6.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=

errors/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

errors/syntax.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/apexlang/apex-go
22

3-
go 1.18
3+
go 1.21
44

55
require (
66
github.com/CosmWasm/tinyjson v0.9.0
7-
github.com/iancoleman/strcase v0.2.0
7+
github.com/iancoleman/strcase v0.3.0
88
github.com/tetratelabs/tinymem v0.1.0
99
github.com/wapc/tinygo-msgpack v0.1.6
1010
github.com/wapc/wapc-guest-tinygo v0.3.3

go.sum

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107 h1:GljFiJysL3S8SBhXWU47Emj34D3pVZgJ+Amj+jhM4fQ=
22
github.com/apexlang/tinyjson v0.9.1-0.20220929010544-92ef7a6da107/go.mod h1:5+7QnSKrkIWnpIdhUT2t2EYzXnII3/3MlM0oDsBSbc8=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4-
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
5-
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
6+
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
67
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
78
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
89
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
911
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
12+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
1013
github.com/tetratelabs/tinymem v0.1.0 h1:Qza1JAg9lquPPJ/CIei5qQYx7t18KLie83O2WR6CM58=
1114
github.com/tetratelabs/tinymem v0.1.0/go.mod h1:WFFTZFhLod6lTL+UetFAopVbGaB+KFsVcIY+RUv7NeY=
1215
github.com/wapc/tinygo-msgpack v0.1.6 h1:geW3N0MAVehJBZp1ITnK2J1R2woI/S1APJB+tFShO6Y=
1316
github.com/wapc/tinygo-msgpack v0.1.6/go.mod h1:2P4rQimy/6oQAkytwC2LdtVjLJ2D1dYkQHejfCtZXZQ=
1417
github.com/wapc/wapc-guest-tinygo v0.3.3 h1:jLebiwjVSHLGnS+BRabQ6+XOV7oihVWAc05Hf1SbeR0=
1518
github.com/wapc/wapc-guest-tinygo v0.3.3/go.mod h1:mzM3CnsdSYktfPkaBdZ8v88ZlfUDEy5Jh5XBOV3fYcw=
1619
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
20+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

go.work

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
go 1.19
1+
go 1.21
22

33
use (
44
.

kinds/kinds.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

lexer/lexer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

location/location.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

model.axdl

+7-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ type Field {
109109
type Union {
110110
name: string @after("=")
111111
description: string? @docs
112-
types: [TypeRef] @delimiters(["|"])
112+
members: [UnionMember] @delimiters(["|"])
113+
annotations: [Annotation]? @prefix("@")
114+
}
115+
116+
type UnionMember {
117+
description: string? @docs
118+
type: TypeRef
113119
annotations: [Annotation]? @prefix("@")
114120
}
115121

model/convert.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Apex Authors.
2+
Copyright 2024 The Apex Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -225,20 +225,24 @@ func (c *Converter) convertUnions(items []*ast.UnionDefinition) []Union {
225225
s[i] = Union{
226226
Description: stringValuePtr(item.Description),
227227
Name: item.Name.Value,
228-
Types: c.convertTypeRefs(item.Types),
228+
Members: c.convertUnionMembers(item.Members),
229229
Annotations: c.convertAnnotations(item.Annotations),
230230
}
231231
}
232232
return s
233233
}
234234

235-
func (c *Converter) convertTypeRefs(items []ast.Type) []TypeRef {
235+
func (c *Converter) convertUnionMembers(items []*ast.UnionMemberDefinition) []UnionMember {
236236
if len(items) == 0 {
237237
return nil
238238
}
239-
s := make([]TypeRef, len(items))
239+
s := make([]UnionMember, len(items))
240240
for i, item := range items {
241-
s[i] = c.convertTypeRef(item)
241+
s[i] = UnionMember{
242+
Description: stringValuePtr(item.Description),
243+
Type: c.convertTypeRef(item.Type),
244+
Annotations: c.convertAnnotations(item.Annotations),
245+
}
242246
}
243247
return s
244248
}

model/model.go

+16-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)