Just Tree Notation support in Go
https://treenotation.org/
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
1 year ago | |
---|---|---|
testdata | 1 year ago | |
LICENSE.md | 1 year ago | |
README.md | 1 year ago | |
doc.go | 1 year ago | |
go.mod | 1 year ago | |
go.sum | 1 year ago | |
tree.go | 1 year ago | |
tree_test.go | 1 year ago |
README.md
tree
The fast and simple Tree Notation parser.
Clean and unfiltered Go with single memory allocation and without any 3rd party
dependencies.
Usage
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"source.toby3d.me/toby3d/tree"
)
func main() {
// For example, load tree content from file.
file, err := os.Open(filepath.Join(".", "html.example"))
if err != nil {
log.Fatalf("cannot open file: %v", err)
}
defer file.Close()
// Parse file contents from plain Tree Notation into *tree.Node with
// *tree.Node childrens.
node := tree.Parse(file)
fmt.Printf("%#v", node)
// Output:
// html
// body
// div おはようございます
}
See package documentation and another examples
on pkg.go.dev.
Benchmark
$ GOMAXPROCS=1 go test -bench=Parse -benchmem -benchtime=10s
goos: linux
goarch: amd64
pkg: source.toby3d.me/toby3d/tree
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
BenchmarkParse 37139248 316.9 ns/op 4096 B/op 1 allocs/op
License
See LICENSE.md
Contact
Check my website or just drop email.