Skip to content

Commit

Permalink
Update to Go 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
dave committed Aug 8, 2023
1 parent e319413 commit 54879c4
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -154,7 +154,7 @@ explanatory:
| Construct | Name |
| ---------------- | ---- |
| Keywords | Break, Chan, Const, Continue, Default, Defer, Else, Fallthrough, Func, Go, Goto, Range, Select, Type, Var |
| Functions | Append, Cap, Close, Complex, Copy, Delete, Imag, Len, Make, New, Panic, Print, Println, Real, Recover |
| Functions | Append, Cap, Clear, Close, Complex, Copy, Delete, Imag, Len, Make, Max, Min, New, Panic, Print, Println, Real, Recover |
| Types | Bool, Byte, Complex64, Complex128, Error, Float32, Float64, Int, Int8, Int16, Int32, Int64, Rune, String, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr |
| Constants | True, False, Iota, Nil |
| Helpers | Err |
Expand Down
2 changes: 1 addition & 1 deletion README.md.tpl
Expand Up @@ -85,7 +85,7 @@ explanatory:
| Construct | Name |
| ---------------- | ---- |
| Keywords | Break, Chan, Const, Continue, Default, Defer, Else, Fallthrough, Func, Go, Goto, Range, Select, Type, Var |
| Functions | Append, Cap, Close, Complex, Copy, Delete, Imag, Len, Make, New, Panic, Print, Println, Real, Recover |
| Functions | Append, Cap, Clear, Close, Complex, Copy, Delete, Imag, Len, Make, Max, Min, New, Panic, Print, Println, Real, Recover |
| Types | Bool, Byte, Complex64, Complex128, Error, Float32, Float64, Int, Int8, Int16, Int32, Int64, Rune, String, Uint, Uint8, Uint16, Uint32, Uint64, Uintptr |
| Constants | True, False, Iota, Nil |
| Helpers | Err |
Expand Down
27 changes: 27 additions & 0 deletions genjen/data.go
Expand Up @@ -195,6 +195,33 @@ var groups = []struct {
separator: ",",
parameters: []string{"c"},
},
{
name: "Clear",
comment: "renders the clear built-in function.",
variadic: false,
opening: "clear(",
closing: ")",
separator: ",",
parameters: []string{"c"},
},
{
name: "Min",
comment: "renders the min built-in function.",
variadic: true,
opening: "min(",
closing: ")",
separator: ",",
parameters: []string{"args"},
},
{
name: "Max",
comment: "renders the max built-in function.",
variadic: true,
opening: "max(",
closing: ")",
separator: ",",
parameters: []string{"args"},
},
{
name: "Complex",
comment: "renders the complex built-in function.",
Expand Down
35 changes: 35 additions & 0 deletions jen/examples_test.go
Expand Up @@ -973,6 +973,41 @@ func ExampleClose() {
// }
}

func ExampleClear() {
c := Block(
Id("a").Op(":=").Map(String()).String().Values(),
Clear(Id("a")),
)
fmt.Printf("%#v", c)
// Output:
// {
// a := map[string]string{}
// clear(a)
// }
}

func ExampleMin() {
c := Block(
Id("n").Op(":=").Min(Lit(1), Lit(2)),
)
fmt.Printf("%#v", c)
// Output:
// {
// n := min(1, 2)
// }
}

func ExampleMax() {
c := Block(
Id("x").Op(":=").Max(Lit(1), Lit(2)),
)
fmt.Printf("%#v", c)
// Output:
// {
// x := max(1, 2)
// }
}

func ExampleComment() {
f := NewFile("a")
f.Comment("Foo returns the string \"foo\"")
Expand Down
130 changes: 130 additions & 0 deletions jen/generated.go
Expand Up @@ -912,6 +912,136 @@ func (s *Statement) Close(c Code) *Statement {
return s
}

// Clear renders the clear built-in function.
func Clear(c Code) *Statement {
return newStatement().Clear(c)
}

// Clear renders the clear built-in function.
func (g *Group) Clear(c Code) *Statement {
s := Clear(c)
g.items = append(g.items, s)
return s
}

// Clear renders the clear built-in function.
func (s *Statement) Clear(c Code) *Statement {
g := &Group{
close: ")",
items: []Code{c},
multi: false,
name: "clear",
open: "clear(",
separator: ",",
}
*s = append(*s, g)
return s
}

// Min renders the min built-in function.
func Min(args ...Code) *Statement {
return newStatement().Min(args...)
}

// Min renders the min built-in function.
func (g *Group) Min(args ...Code) *Statement {
s := Min(args...)
g.items = append(g.items, s)
return s
}

// Min renders the min built-in function.
func (s *Statement) Min(args ...Code) *Statement {
g := &Group{
close: ")",
items: args,
multi: false,
name: "min",
open: "min(",
separator: ",",
}
*s = append(*s, g)
return s
}

// MinFunc renders the min built-in function.
func MinFunc(f func(*Group)) *Statement {
return newStatement().MinFunc(f)
}

// MinFunc renders the min built-in function.
func (g *Group) MinFunc(f func(*Group)) *Statement {
s := MinFunc(f)
g.items = append(g.items, s)
return s
}

// MinFunc renders the min built-in function.
func (s *Statement) MinFunc(f func(*Group)) *Statement {
g := &Group{
close: ")",
multi: false,
name: "min",
open: "min(",
separator: ",",
}
f(g)
*s = append(*s, g)
return s
}

// Max renders the max built-in function.
func Max(args ...Code) *Statement {
return newStatement().Max(args...)
}

// Max renders the max built-in function.
func (g *Group) Max(args ...Code) *Statement {
s := Max(args...)
g.items = append(g.items, s)
return s
}

// Max renders the max built-in function.
func (s *Statement) Max(args ...Code) *Statement {
g := &Group{
close: ")",
items: args,
multi: false,
name: "max",
open: "max(",
separator: ",",
}
*s = append(*s, g)
return s
}

// MaxFunc renders the max built-in function.
func MaxFunc(f func(*Group)) *Statement {
return newStatement().MaxFunc(f)
}

// MaxFunc renders the max built-in function.
func (g *Group) MaxFunc(f func(*Group)) *Statement {
s := MaxFunc(f)
g.items = append(g.items, s)
return s
}

// MaxFunc renders the max built-in function.
func (s *Statement) MaxFunc(f func(*Group)) *Statement {
g := &Group{
close: ")",
multi: false,
name: "max",
open: "max(",
separator: ",",
}
f(g)
*s = append(*s, g)
return s
}

// Complex renders the complex built-in function.
func Complex(r Code, i Code) *Statement {
return newStatement().Complex(r, i)
Expand Down
14 changes: 14 additions & 0 deletions jen/hints.go
Expand Up @@ -8,6 +8,7 @@ var standardLibraryHints = map[string]string{
"archive/zip": "zip",
"bufio": "bufio",
"bytes": "bytes",
"cmp": "cmp",
"compress/bzip2": "bzip2",
"compress/flate": "flate",
"compress/gzip": "gzip",
Expand Down Expand Up @@ -112,6 +113,7 @@ var standardLibraryHints = map[string]string{
"image/png": "png",
"index/suffixarray": "suffixarray",
"internal/abi": "abi",
"internal/bisect": "bisect",
"internal/buildcfg": "buildcfg",
"internal/bytealg": "bytealg",
"internal/cfg": "cfg",
Expand All @@ -137,6 +139,7 @@ var standardLibraryHints = map[string]string{
"internal/fuzz": "fuzz",
"internal/goarch": "goarch",
"internal/godebug": "godebug",
"internal/godebugs": "godebugs",
"internal/goexperiment": "goexperiment",
"internal/goos": "goos",
"internal/goroot": "goroot",
Expand Down Expand Up @@ -168,11 +171,19 @@ var standardLibraryHints = map[string]string{
"internal/types/errors": "errors",
"internal/unsafeheader": "unsafeheader",
"internal/xcoff": "xcoff",
"internal/zstd": "zstd",
"io": "io",
"io/fs": "fs",
"io/ioutil": "ioutil",
"log": "log",
"log/internal": "internal",
"log/slog": "slog",
"log/slog/internal": "internal",
"log/slog/internal/benchmarks": "benchmarks",
"log/slog/internal/buffer": "buffer",
"log/slog/internal/slogtest": "slogtest",
"log/syslog": "syslog",
"maps": "maps",
"math": "math",
"math/big": "big",
"math/bits": "bits",
Expand Down Expand Up @@ -221,10 +232,12 @@ var standardLibraryHints = map[string]string{
"runtime/internal/atomic": "atomic",
"runtime/internal/math": "math",
"runtime/internal/sys": "sys",
"runtime/internal/wasitest": "wasi",
"runtime/metrics": "metrics",
"runtime/pprof": "pprof",
"runtime/race": "race",
"runtime/trace": "trace",
"slices": "slices",
"sort": "sort",
"strconv": "strconv",
"strings": "strings",
Expand All @@ -236,6 +249,7 @@ var standardLibraryHints = map[string]string{
"testing/internal/testdeps": "testdeps",
"testing/iotest": "iotest",
"testing/quick": "quick",
"testing/slogtest": "slogtest",
"text/scanner": "scanner",
"text/tabwriter": "tabwriter",
"text/template": "template",
Expand Down
2 changes: 1 addition & 1 deletion jen/reserved.go
Expand Up @@ -4,7 +4,7 @@ var reserved = []string{
/* keywords */
"break", "default", "func", "interface", "select", "case", "defer", "go", "map", "struct", "chan", "else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", "continue", "for", "import", "return", "var",
/* predeclared */
"bool", "byte", "complex64", "complex128", "error", "float32", "float64", "int", "int8", "int16", "int32", "int64", "rune", "string", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "true", "false", "iota", "nil", "append", "cap", "close", "complex", "copy", "delete", "imag", "len", "make", "new", "panic", "print", "println", "real", "recover",
"bool", "byte", "complex64", "complex128", "error", "float32", "float64", "int", "int8", "int16", "int32", "int64", "rune", "string", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "true", "false", "iota", "nil", "append", "cap", "close", "clear", "min", "max", "complex", "copy", "delete", "imag", "len", "make", "new", "panic", "print", "println", "real", "recover",
/* common variables */
"err",
}
Expand Down

0 comments on commit 54879c4

Please sign in to comment.