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. Everything should be unicode safe by default, but you can opt out of unicode whitespace for a decent ~20% performance boost. ```go Run(parser, input, ASCIIWhitespace) ``` ### benchmarks I dont have many benchmarks set up yet, but the json parser is 50% faster than the stdlib. ``` $ go test -bench=. -benchmem -benchtime=5s ./json -run=none BenchmarkUnmarshalParsec-8 100000 65682 ns/op 50464 B/op 1318 allocs/op BenchmarkUnmarshalParsify-8 200000 32656 ns/op 42094 B/op 220 allocs/op BenchmarkUnmarshalStdlib-8 200000 48023 ns/op 13952 B/op 262 allocs/op PASS ok github.com/vektah/goparsify/json 24.314s ``` Most of the remaining small allocs are from putting things in `interface{}` and are pretty unavoidable. https://www.darkcoding.net/software/go-the-price-of-interface/ is a good read. ### debugging parsers When a parser isnt working as you intended you can build with debugging and enable logging to get a detailed log of exactly what the parser is doing. 1. First build with debug using `-tags debug` 2. enable logging by calling `EnableLogging(os.Stdout)` in your code This works great with tests, eg in the goparsify source tree ``` adam:goparsify(master)$ go test -tags debug ./html -v === RUN TestParse html.go:48 |
hellohello
hello
hello
hello
hello
hello
hello
hello
found > html.go:43 | hello
] html.go:24 | hello
html.go:48 |
| < found < html.go:20 | color="blue">w | identifier found p html.go:33 | color="blue">w | attrs { html.go:32 | color="blue">w | attr { html.go:20 | ="blue">world | identifier found color html.go:32 | "blue">world
worldworldworldworldworldworld found > html.go:43 | world