From 2292f9e40198d1d43db1e951089d4edd34079619 Mon Sep 17 00:00:00 2001 From: Walter Schulze Date: Tue, 28 Feb 2023 18:52:58 +0000 Subject: [PATCH] Less dependencies and update to go 1.19 (#136) * try less dependencies * ioutil is replaced with os * replace ioutil with os * replace ioutil with os --- Makefile | 7 +--- example/astx/lexer/lexer.go | 4 +-- example/bools/lexer/lexer.go | 4 +-- example/calc/lexer/lexer.go | 4 +-- example/errormsg/lexer/lexer.go | 4 +-- example/errorrecovery/lexer/lexer.go | 4 +-- example/mail/lexer/lexer.go | 4 +-- example/rr/lexer/lexer.go | 4 +-- example/sr/lexer/lexer.go | 4 +-- example/usercontext/lexer/lexer.go | 4 +-- go.mod | 8 ++--- go.sum | 48 ---------------------------- internal/config/config.go | 3 +- internal/frontend/token/token.go | 6 ++-- internal/io/io.go | 3 +- internal/lexer/gen/golang/lexer.go | 4 +-- internal/test/t1/lexer/lexer.go | 4 +-- internal/util/md/md.go | 6 ++-- main.go | 3 +- 19 files changed, 33 insertions(+), 95 deletions(-) diff --git a/Makefile b/Makefile index 76e08354..fa952bc6 100644 --- a/Makefile +++ b/Makefile @@ -20,11 +20,7 @@ ci-lint: ## see https://golangci-lint.run/, applies .golangci.yml lint: govet ci-lint -goimports: ## sort and separate imports - go get golang.org/x/tools/cmd/goimports - goimports -l -w . - -goclean: gofmt goimports ## apply go style rules to source +goclean: gofmt ## apply go style rules to source regenerate: ## regenerate all example and test files make install @@ -41,7 +37,6 @@ check: ## regenerate, lint and run a terse version of check @make --quiet -C internal/test regenerate @# promote formatting changes to errors @if [ -n "$(gofmt -l -s .)" ]; then { echo "gofmt errors:"; gofmt -d -l -s . ; exit 1; }; fi - @if [ -n "$(gomports -l . )" ]; then { echo "goimports errors:"; goimports -l . ; exit 1; }; fi @make --quiet lint @go test ./... | grep -v "\[no test" diff --git a/example/astx/lexer/lexer.go b/example/astx/lexer/lexer.go index a5a9c599..cc9f24de 100755 --- a/example/astx/lexer/lexer.go +++ b/example/astx/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/astx/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/bools/lexer/lexer.go b/example/bools/lexer/lexer.go index d77d0b87..73ba8ecf 100755 --- a/example/bools/lexer/lexer.go +++ b/example/bools/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/bools/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/calc/lexer/lexer.go b/example/calc/lexer/lexer.go index a73b5de8..7f6e5403 100755 --- a/example/calc/lexer/lexer.go +++ b/example/calc/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/calc/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/errormsg/lexer/lexer.go b/example/errormsg/lexer/lexer.go index 543f20d6..e775468f 100644 --- a/example/errormsg/lexer/lexer.go +++ b/example/errormsg/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/errormsg/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/errorrecovery/lexer/lexer.go b/example/errorrecovery/lexer/lexer.go index 11e23c40..714c1eeb 100755 --- a/example/errorrecovery/lexer/lexer.go +++ b/example/errorrecovery/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/errorrecovery/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/mail/lexer/lexer.go b/example/mail/lexer/lexer.go index c71fc349..0ed19738 100755 --- a/example/mail/lexer/lexer.go +++ b/example/mail/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/mail/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/rr/lexer/lexer.go b/example/rr/lexer/lexer.go index 2c5ca70d..c80abfe1 100755 --- a/example/rr/lexer/lexer.go +++ b/example/rr/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/rr/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/sr/lexer/lexer.go b/example/sr/lexer/lexer.go index 54dff071..dc2b9fb5 100755 --- a/example/sr/lexer/lexer.go +++ b/example/sr/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/sr/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/example/usercontext/lexer/lexer.go b/example/usercontext/lexer/lexer.go index 1bdd2142..ef02b93f 100644 --- a/example/usercontext/lexer/lexer.go +++ b/example/usercontext/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/example/usercontext/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index 86edd943..1e955916 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,5 @@ module github.com/goccmack/gocc -go 1.12 +go 1.19 -require ( - golang.org/x/mod v0.8.0 - golang.org/x/tools v0.6.0 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect -) +require golang.org/x/mod v0.8.0 diff --git a/go.sum b/go.sum index 9f883f8f..083110b4 100644 --- a/go.sum +++ b/go.sum @@ -1,50 +1,2 @@ -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= -golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.5.0 h1:+bSpV5HIeWkuvgaMfI3UmKRThoTA5ODJTUd8T17NO+4= -golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/config/config.go b/internal/config/config.go index e712f54f..55119bff 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -19,7 +19,6 @@ import ( "flag" "fmt" "go/build" - "io/ioutil" "os" "path" "path/filepath" @@ -260,7 +259,7 @@ func currentModule() (string, string, error) { } full := path.Join(parent, info.Name()) - data, err := ioutil.ReadFile(full) + data, err := os.ReadFile(full) if err != nil { return "", "", fmt.Errorf("reading file '%s': %s", full, err) } diff --git a/internal/frontend/token/token.go b/internal/frontend/token/token.go index 48d33a40..5a9402e4 100644 --- a/internal/frontend/token/token.go +++ b/internal/frontend/token/token.go @@ -3,7 +3,7 @@ package token import ( "bytes" "fmt" - "io/ioutil" + "os" "regexp" "strconv" "strings" @@ -130,7 +130,7 @@ func (this *TokenMap) AddToken(str string) { } func NewMapFromFile(file string) (*TokenMap, error) { - src, err := ioutil.ReadFile(file) + src, err := os.ReadFile(file) if err != nil { return nil, err } @@ -214,5 +214,5 @@ func (this *TokenMap) WriteFile(file string) error { for i := 1; i < len(this.tokenMap); i++ { out += this.TokenString(Type(i)) + "\n" } - return ioutil.WriteFile(file, []byte(out), 0644) + return os.WriteFile(file, []byte(out), 0644) } diff --git a/internal/io/io.go b/internal/io/io.go index b01eef81..3a55c836 100644 --- a/internal/io/io.go +++ b/internal/io/io.go @@ -15,7 +15,6 @@ package io import ( - "io/ioutil" "os" "path" ) @@ -28,7 +27,7 @@ func WriteFile(fpath string, data []byte) { if err := os.MkdirAll(dir, PermDir); err != nil { panic(err) } - if err := ioutil.WriteFile(fpath, data, PermFile); err != nil { + if err := os.WriteFile(fpath, data, PermFile); err != nil { panic(err) } } diff --git a/internal/lexer/gen/golang/lexer.go b/internal/lexer/gen/golang/lexer.go index d5793bd6..c7ac37af 100644 --- a/internal/lexer/gen/golang/lexer.go +++ b/internal/lexer/gen/golang/lexer.go @@ -66,7 +66,7 @@ package lexer import ( {{if .Debug}} "fmt" -{{end}} "io/ioutil" +{{end}} "os" "unicode/utf8" {{if .Debug}} "{{.UtilImport}}" @@ -109,7 +109,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/internal/test/t1/lexer/lexer.go b/internal/test/t1/lexer/lexer.go index 2f9be6d1..a02460af 100755 --- a/internal/test/t1/lexer/lexer.go +++ b/internal/test/t1/lexer/lexer.go @@ -3,7 +3,7 @@ package lexer import ( - "io/ioutil" + "os" "unicode/utf8" "github.com/goccmack/gocc/internal/test/t1/token" @@ -45,7 +45,7 @@ func (s *SourceContext) Source() string { } func NewLexerFile(fpath string) (*Lexer, error) { - src, err := ioutil.ReadFile(fpath) + src, err := os.ReadFile(fpath) if err != nil { return nil, err } diff --git a/internal/util/md/md.go b/internal/util/md/md.go index 0fcfbc94..f4945a58 100755 --- a/internal/util/md/md.go +++ b/internal/util/md/md.go @@ -17,15 +17,13 @@ Package md extracts code sections of markdown files */ package md -import ( - "io/ioutil" -) +import "os" /* GetSource returns code sections enclosed in triple backticks. */ func GetSource(mdfile string) (string, error) { - inbuf, err := ioutil.ReadFile(mdfile) + inbuf, err := os.ReadFile(mdfile) if err != nil { return "", err } diff --git a/main.go b/main.go index 0e9b0cf8..d7237281 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,6 @@ import ( "bytes" "flag" "fmt" - "io/ioutil" "os" "path" "strings" @@ -119,7 +118,7 @@ func getSource(cfg config.Config) []byte { } return []byte(str) } - srcBuffer, err := ioutil.ReadFile(cfg.SourceFile()) + srcBuffer, err := os.ReadFile(cfg.SourceFile()) if err != nil { fmt.Println(err) os.Exit(1)