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

chore: replace ioutil with io/os #134

Merged
merged 1 commit into from
Mar 6, 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
8 changes: 4 additions & 4 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build ignore
// +build ignore

package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -181,7 +181,7 @@ func command(name, inputFile, outputFile string, arg ...string) {

if inputFile != "" {
fmt.Printf(" < %s", inputFile)
input, err := ioutil.ReadFile(inputFile)
input, err := os.ReadFile(inputFile)
if err != nil {
panic(err)
}
Expand All @@ -204,7 +204,7 @@ func command(name, inputFile, outputFile string, arg ...string) {
if err != nil {
panic(err)
}
err = ioutil.WriteFile(outputFile, output, 0600)
err = os.WriteFile(outputFile, output, 0600)
if err != nil {
panic(err)
}
Expand All @@ -224,7 +224,7 @@ func delete(file string) {
}

func deleteFilesWithSuffix(suffix string) {
files, err := ioutil.ReadDir(".")
files, err := os.ReadDir(".")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const (
// VERSION is the version of peg
VERSION = "unknown"
// BUILDTIME is the build time of peg
BUILDTIME = "2024-01-10T10:51:19"
BUILDTIME = "2024-02-26T12:28:35"
// COMMIT is the commit hash of peg
COMMIT = "047adc6e3cbbd46edaadb58ff9abc399c429ddc0"
COMMIT = "a4f5c509ba3254cae4204db9c02d36ca2f733d53"
// IS_TAGGED is there a version
IS_TAGGED = false
)
4 changes: 2 additions & 2 deletions cmd/peg-bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
package main

import (
"io/ioutil"
"io"
"log"
"os"

"github.com/pointlander/peg/tree"
)

func main() {
buffer, err := ioutil.ReadAll(os.Stdin)
buffer, err := io.ReadAll(os.Stdin)
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions grammars/c/c_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main

import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -187,7 +188,7 @@ func TestCParsing_Long(t *testing.T) {
log.Fatal(err)
}

buffer, err := ioutil.ReadAll(file)
buffer, err := io.ReadAll(file)
if err != nil {
log.Fatal(err)
}
Expand All @@ -204,5 +205,5 @@ func TestCParsing_Long(t *testing.T) {
}

func TestCParsing_WideString(t *testing.T) {
parseC_4t(t, `wchar_t *msg = L"Hello";`);
parseC_4t(t, `wchar_t *msg = L"Hello";`)
}
1 change: 1 addition & 0 deletions grammars/calculator/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main
Expand Down
1 change: 1 addition & 0 deletions grammars/calculator/calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main
Expand Down
1 change: 1 addition & 0 deletions grammars/calculator_ast/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main
Expand Down
1 change: 1 addition & 0 deletions grammars/calculator_ast/calculator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main
Expand Down
5 changes: 3 additions & 2 deletions grammars/fexl/fexl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main

import (
"io/ioutil"
"os"
"testing"
)

func TestFexl(t *testing.T) {
buffer, err := ioutil.ReadFile("doc/try.fxl")
buffer, err := os.ReadFile("doc/try.fxl")
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions grammars/java/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main

import (
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestJava(t *testing.T) {
log.Fatal(err)
}

buffer, err := ioutil.ReadAll(file)
buffer, err := io.ReadAll(file)
if err != nil {
log.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions grammars/long_test/long_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build grammars
// +build grammars

package main
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -53,7 +52,7 @@ func main() {
}
file := flag.Arg(0)

buffer, err := ioutil.ReadFile(file)
buffer, err := os.ReadFile(file)
if err != nil {
log.Fatal(err)
}
Expand Down
37 changes: 18 additions & 19 deletions peg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"testing"

Expand All @@ -22,7 +21,7 @@ Grammar <- !.
}

p = &Peg{Tree: tree.New(false, false, false), Buffer: buffer}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
err = p.Parse()
if err != nil {
t.Error(err)
Expand All @@ -35,7 +34,7 @@ type T Peg {}
Grammar <- !.
`
p := &Peg{Tree: tree.New(false, false, false), Buffer: buffer}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
err := p.Parse()
if err == nil {
t.Error("packagenospace was parsed without error")
Expand All @@ -49,21 +48,21 @@ typenospace Peg {}
Grammar <- !.
`
p := &Peg{Tree: tree.New(false, false, false), Buffer: buffer}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
err := p.Parse()
if err == nil {
t.Error("typenospace was parsed without error")
}
}

func TestSame(t *testing.T) {
buffer, err := ioutil.ReadFile("peg.peg")
buffer, err := os.ReadFile("peg.peg")
if err != nil {
t.Error(err)
}

p := &Peg{Tree: tree.New(true, true, false), Buffer: string(buffer)}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
if err = p.Parse(); err != nil {
t.Error(err)
}
Expand All @@ -73,7 +72,7 @@ func TestSame(t *testing.T) {
out := &bytes.Buffer{}
p.Compile("peg.peg.go", []string{"./peg", "-inline", "-switch", "peg.peg"}, out)

bootstrap, err := ioutil.ReadFile("peg.peg.go")
bootstrap, err := os.ReadFile("peg.peg.go")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -115,13 +114,13 @@ Begin <- Begin 'x'

for i, buffer := range tt {
p := &Peg{Tree: tree.New(false, false, false), Buffer: buffer}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
if err := p.Parse(); err != nil {
t.Fatal(err)
}
p.Execute()

f, err := ioutil.TempFile("", "peg")
f, err := os.CreateTemp("", "peg")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -152,7 +151,7 @@ var files = [...]string{
func BenchmarkInitOnly(b *testing.B) {
pegs := []string{}
for _, file := range files {
input, err := ioutil.ReadFile(file)
input, err := os.ReadFile(file)
if err != nil {
b.Error(err)
}
Expand All @@ -163,21 +162,21 @@ func BenchmarkInitOnly(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, peg := range pegs {
p := &Peg{Tree: tree.New(true, true, false), Buffer: peg}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
}
}
}

func BenchmarkParse(b *testing.B) {
pegs := make([]*Peg, len(files))
for i, file := range files {
input, err := ioutil.ReadFile(file)
input, err := os.ReadFile(file)
if err != nil {
b.Error(err)
}

p := &Peg{Tree: tree.New(true, true, false), Buffer: string(input)}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
pegs[i] = p
}

Expand All @@ -197,13 +196,13 @@ func BenchmarkParse(b *testing.B) {
func BenchmarkResetAndParse(b *testing.B) {
pegs := make([]*Peg, len(files))
for i, file := range files {
input, err := ioutil.ReadFile(file)
input, err := os.ReadFile(file)
if err != nil {
b.Error(err)
}

p := &Peg{Tree: tree.New(true, true, false), Buffer: string(input)}
p.Init(Size(1<<15))
p.Init(Size(1 << 15))
pegs[i] = p
}

Expand All @@ -221,7 +220,7 @@ func BenchmarkResetAndParse(b *testing.B) {
func BenchmarkInitAndParse(b *testing.B) {
strs := []string{}
for _, file := range files {
input, err := ioutil.ReadFile(file)
input, err := os.ReadFile(file)
if err != nil {
b.Error(err)
}
Expand All @@ -232,7 +231,7 @@ func BenchmarkInitAndParse(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, str := range strs {
peg := &Peg{Tree: tree.New(true, true, false), Buffer: str}
peg.Init(Size(1<<15))
peg.Init(Size(1 << 15))
if err := peg.Parse(); err != nil {
b.Error(err)
}
Expand All @@ -243,7 +242,7 @@ func BenchmarkInitAndParse(b *testing.B) {
func BenchmarkInitResetAndParse(b *testing.B) {
strs := []string{}
for _, file := range files {
input, err := ioutil.ReadFile(file)
input, err := os.ReadFile(file)
if err != nil {
b.Error(err)
}
Expand All @@ -254,7 +253,7 @@ func BenchmarkInitResetAndParse(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, str := range strs {
peg := &Peg{Tree: tree.New(true, true, false), Buffer: str}
peg.Init(Size(1<<15))
peg.Init(Size(1 << 15))
if err := peg.Parse(); err != nil {
b.Error(err)
}
Expand Down
Loading