From 5fa7eb841e7004250ecd88c6c5755006a0fe5e42 Mon Sep 17 00:00:00 2001 From: Jesse Portnoy Date: Sun, 16 Jul 2023 02:12:12 +0100 Subject: [PATCH] - Guard aginst non-existing syn highlighter file - Create mod file in `examples` dir --- README.md | 8 ++++++-- examples/go.mod | 15 +++++++++++++++ examples/go.sum | 16 ++++++++++++++++ examples/syncat.go | 6 +++++- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 examples/go.mod create mode 100644 examples/go.sum diff --git a/README.md b/README.md index 5750ddb..292d767 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,17 @@ func main() { import "fmt" // A hello world program -func main() { +func helloWorld() { fmt.Println("Hello world") }` // Load the go syntax file // Make sure that the syntax_files directory is in the current directory - syntaxFile, _ := ioutil.ReadFile("highlight/syntax_files/go.yaml") + syntaxFile, lerr := ioutil.ReadFile("highlight/syntax_files/go.yaml") + if lerr != nil { + fmt.Println(lerr) + return + } // Parse it into a `*highlight.Def` syntaxDef, err := highlight.ParseDef(syntaxFile) diff --git a/examples/go.mod b/examples/go.mod new file mode 100644 index 0000000..2cd13bb --- /dev/null +++ b/examples/go.mod @@ -0,0 +1,15 @@ +module examples + +go 1.19 + +require ( + github.com/fatih/color v1.15.0 + github.com/zyedidia/highlight v0.0.0-20200217010119-291680feaca1 +) + +require ( + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect + golang.org/x/sys v0.6.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/examples/go.sum b/examples/go.sum new file mode 100644 index 0000000..22bff5e --- /dev/null +++ b/examples/go.sum @@ -0,0 +1,16 @@ +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/zyedidia/highlight v0.0.0-20200217010119-291680feaca1 h1:8oQDIgT8V1yyEoEvvoXkSfoJgSst+dUEwunxq8fbs1c= +github.com/zyedidia/highlight v0.0.0-20200217010119-291680feaca1/go.mod h1:c1r+Ob9tUTPB0FKWO1+x+Hsc/zNa45WdGq7Y38Ybip0= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/examples/syncat.go b/examples/syncat.go index c9a7c33..78ba538 100644 --- a/examples/syncat.go +++ b/examples/syncat.go @@ -19,7 +19,11 @@ func main() { var defs []*highlight.Def gopath := os.Getenv("GOPATH") - files, _ := ioutil.ReadDir(gopath + "/src/github.com/zyedidia/highlight/syntax_files") + files, lerr := ioutil.ReadDir(gopath + "/src/github.com/zyedidia/highlight/syntax_files") + if lerr != nil { + fmt.Println(lerr) + return + } for _, f := range files { if strings.HasSuffix(f.Name(), ".yaml") {