diff --git a/calc/calc.go b/calc/calc.go index 574ea84..3c4ad4f 100644 --- a/calc/calc.go +++ b/calc/calc.go @@ -64,7 +64,7 @@ func init() { value = Any(number, groupExpr) } -func Calc(input string) (float64, error) { +func calc(input string) (float64, error) { result, err := Run(y, input) if err != nil { return 0, err diff --git a/calc/calc_test.go b/calc/calc_test.go index 13b2f5b..765e85a 100644 --- a/calc/calc_test.go +++ b/calc/calc_test.go @@ -7,48 +7,48 @@ import ( ) func TestNumbers(t *testing.T) { - result, err := Calc(`1`) + result, err := calc(`1`) require.NoError(t, err) require.EqualValues(t, 1, result) } func TestAddition(t *testing.T) { - result, err := Calc(`1+1`) + result, err := calc(`1+1`) require.NoError(t, err) require.EqualValues(t, 2, result) } func TestSubtraction(t *testing.T) { - result, err := Calc(`1-1`) + result, err := calc(`1-1`) require.NoError(t, err) require.EqualValues(t, 0, result) } func TestDivision(t *testing.T) { - result, err := Calc(`1/2`) + result, err := calc(`1/2`) require.NoError(t, err) require.EqualValues(t, .5, result) } func TestMultiplication(t *testing.T) { - result, err := Calc(`1*2`) + result, err := calc(`1*2`) require.NoError(t, err) require.EqualValues(t, 2, result) } func TestOrderOfOperations(t *testing.T) { - result, err := Calc(`1+10*2`) + result, err := calc(`1+10*2`) require.NoError(t, err) require.EqualValues(t, 21, result) } func TestParenthesis(t *testing.T) { - result, err := Calc(`(1+10)*2`) + result, err := calc(`(1+10)*2`) require.NoError(t, err) require.EqualValues(t, 22, result) } func TestRecursive(t *testing.T) { - result, err := Calc(`(1+(2*(3-(4/(5)))))`) + result, err := calc(`(1+(2*(3-(4/(5)))))`) require.NoError(t, err) require.EqualValues(t, 5.4, result) } diff --git a/combinator_test.go b/combinator_test.go index 9dbf8e5..b197105 100644 --- a/combinator_test.go +++ b/combinator_test.go @@ -134,7 +134,7 @@ func TestMap(t *testing.T) { return Result{Result: htmlTag{n.Child[1].Token}} }) - t.Run("sucess", func(t *testing.T) { + t.Run("success", func(t *testing.T) { result, _ := runParser("", parser) require.Equal(t, htmlTag{"html"}, result.Result) }) @@ -149,7 +149,7 @@ func TestMap(t *testing.T) { func TestBind(t *testing.T) { parser := Bind("true", true) - t.Run("sucess", func(t *testing.T) { + t.Run("success", func(t *testing.T) { result, _ := runParser("true", parser) require.Equal(t, true, result.Result) }) @@ -187,7 +187,7 @@ func TestMerge(t *testing.T) { bracer = Seq("(", Maybe(&bracer), ")") parser := Merge(bracer) - t.Run("sucess", func(t *testing.T) { + t.Run("success", func(t *testing.T) { result, _ := runParser("((()))", parser) require.Equal(t, "((()))", result.Token) }) diff --git a/debug/frames.go b/debug/frames.go index 88a48f0..2110dcd 100644 --- a/debug/frames.go +++ b/debug/frames.go @@ -18,9 +18,9 @@ func getPackageName(f runtime.Frame) string { if parts[pl-2][0] == '(' { return strings.Join(parts[0:pl-2], ".") - } else { - return strings.Join(parts[0:pl-1], ".") } + + return strings.Join(parts[0:pl-1], ".") } func getVarName(filename string, lineNo int) string { diff --git a/html/html.go b/html/html.go index 4e2197d..5fe9480 100644 --- a/html/html.go +++ b/html/html.go @@ -4,11 +4,11 @@ import ( . "github.com/vektah/goparsify" ) -func Parse(input string) (result interface{}, err error) { +func parse(input string) (result interface{}, err error) { return Run(tag, input) } -type Tag struct { +type htmlTag struct { Name string Attributes map[string]string Body []interface{} @@ -49,7 +49,7 @@ var ( func init() { tag = Map(Seq(tstart, Cut(), elements, tend), func(node Result) Result { openTag := node.Child[0] - return Result{Result: Tag{ + return Result{Result: htmlTag{ Name: openTag.Child[1].Token, Attributes: openTag.Child[3].Result.(map[string]string), Body: node.Child[2].Result.([]interface{}), diff --git a/html/html_test.go b/html/html_test.go index f614b4d..7649fdd 100644 --- a/html/html_test.go +++ b/html/html_test.go @@ -7,10 +7,10 @@ import ( ) func TestParse(t *testing.T) { - result, err := Parse(`hello

world

`) + result, err := parse(`hello

world

`) require.NoError(t, err) - require.Equal(t, Tag{Name: "body", Attributes: map[string]string{}, Body: []interface{}{ + require.Equal(t, htmlTag{Name: "body", Attributes: map[string]string{}, Body: []interface{}{ "hello ", - Tag{Name: "p", Attributes: map[string]string{"color": "blue"}, Body: []interface{}{"world"}}, + htmlTag{Name: "p", Attributes: map[string]string{"color": "blue"}, Body: []interface{}{"world"}}, }}, result) } diff --git a/json/json.go b/json/json.go index 52166f8..0707f0a 100644 --- a/json/json.go +++ b/json/json.go @@ -36,6 +36,6 @@ func init() { _value = Any(_null, _true, _false, _string, _number, _array, _object) } -func Unmarshal(input string) (interface{}, error) { +func unmarshal(input string) (interface{}, error) { return Run(_value, input, ASCIIWhitespace) } diff --git a/json/json_test.go b/json/json_test.go index f020a40..0ff3833 100644 --- a/json/json_test.go +++ b/json/json_test.go @@ -11,31 +11,31 @@ import ( func TestUnmarshal(t *testing.T) { t.Run("basic types", func(t *testing.T) { - result, err := Unmarshal(`true`) + result, err := unmarshal(`true`) require.NoError(t, err) require.Equal(t, true, result) - result, err = Unmarshal(`false`) + result, err = unmarshal(`false`) require.NoError(t, err) require.Equal(t, false, result) - result, err = Unmarshal(`null`) + result, err = unmarshal(`null`) require.NoError(t, err) require.Equal(t, nil, result) - result, err = Unmarshal(`"true"`) + result, err = unmarshal(`"true"`) require.NoError(t, err) require.Equal(t, "true", result) }) t.Run("array", func(t *testing.T) { - result, err := Unmarshal(`[true, null, false, -1.23e+4]`) + result, err := unmarshal(`[true, null, false, -1.23e+4]`) require.NoError(t, err) require.Equal(t, []interface{}{true, nil, false, -1.23e+4}, result) }) t.Run("object", func(t *testing.T) { - result, err := Unmarshal(`{"true":true, "false":false, "null": null, "number": 404} `) + result, err := unmarshal(`{"true":true, "false":false, "null": null, "number": 404} `) require.NoError(t, err) require.Equal(t, map[string]interface{}{"true": true, "false": false, "null": nil, "number": int64(404)}, result) }) @@ -54,7 +54,7 @@ func BenchmarkUnmarshalParsec(b *testing.B) { func BenchmarkUnmarshalParsify(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := Unmarshal(benchmarkString) + _, err := unmarshal(benchmarkString) require.NoError(b, err) } goparsify.DumpDebugStats() diff --git a/json/profile/json.go b/json/profile/json.go index b7d9733..e6ae771 100644 --- a/json/profile/json.go +++ b/json/profile/json.go @@ -48,7 +48,7 @@ func main() { } for i := 0; i < max; i++ { - _, err := json.Unmarshal(benchmarkString) + _, err := json.unmarshal(benchmarkString) if err != nil { panic(err) } diff --git a/parser.go b/parser.go index bc65e6d..319b324 100644 --- a/parser.go +++ b/parser.go @@ -171,7 +171,7 @@ func parseRepetition(defaultMin, defaultMax int, repetition ...int) (min int, ma min = repetition[0] max = repetition[1] default: - panic(fmt.Errorf("Dont know what %d repetion args mean", len(repetition))) + panic(fmt.Errorf("Dont know what %d repetition args mean", len(repetition))) } return min, max } diff --git a/readme.md b/readme.md index e82e556..99745bf 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -goparsify [![CircleCI](https://circleci.com/gh/Vektah/goparsify/tree/master.svg?style=shield)](https://circleci.com/gh/Vektah/goparsify/tree/master) [![godoc](http://b.repl.ca/v1/godoc-reference-blue.png)](https://godoc.org/github.com/Vektah/goparsify) +goparsify [![CircleCI](https://circleci.com/gh/Vektah/goparsify/tree/master.svg?style=shield)](https://circleci.com/gh/Vektah/goparsify/tree/master) [![godoc](http://b.repl.ca/v1/godoc-reference-blue.png)](https://godoc.org/github.com/Vektah/goparsify) [![Go Report Card](https://goreportcard.com/badge/github.com/vektah/goparsify)](https://goreportcard.com/report/github.com/vektah/goparsify) ========= A parser-combinator library for building easy to test, read and maintain parsers using functional composition.