Just Tree Notation support in Go https://treenotation.org/
Find a file
2022-01-07 02:04:30 +05:00
testdata 🔖 Released v0.1.0 2022-01-06 23:55:55 +05:00
doc.go 💡 Added import comment in doc.go 2022-01-07 01:00:48 +05:00
go.mod 🎉 Initial commit 2022-01-06 18:47:00 +05:00
go.sum 🔖 Released v0.1.0 2022-01-06 23:55:55 +05:00
LICENSE.md 📄 Added license file 2022-01-07 00:32:14 +05:00
README.md 📝 Added pkg.go.dev badge in README.md 2022-01-07 00:38:44 +05:00
tree.go 🏷️ Added Delim type 2022-01-07 02:04:30 +05:00
tree_test.go 🔖 Released v0.1.0 2022-01-06 23:55:55 +05:00

tree

Go Reference

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.