Just Tree Notation support in Go https://treenotation.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Maxim Lebedev 90f9bd2d5b
🏷️ Added Delim type
8 months ago
testdata 🔖 Released v0.1.0 8 months ago
LICENSE.md 📄 Added license file 8 months ago
README.md 📝 Added pkg.go.dev badge in README.md 8 months ago
doc.go 💡 Added import comment in doc.go 8 months ago
go.mod 🎉 Initial commit 8 months ago
go.sum 🔖 Released v0.1.0 8 months ago
tree.go 🏷️ Added Delim type 8 months ago
tree_test.go 🔖 Released v0.1.0 8 months ago

README.md

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.