tabnas/path (Go port)
Go port of the @tabnas/path Tabnas parser
plugin. It adds property-path tracking to the
Tabnas parser so that rule actions can
see the path (keys and indices) leading to the current value.
The TypeScript version is canonical; this package tracks it.
- Module path:
github.com/tabnas/path/go
- Package name:
tabnaspath
Install
go get github.com/tabnas/path/go
The Tabnas engine ships no grammar of its own — you bring a grammar that
defines the val / map / pair / list / elem rules. Install the
grammar first, then Path on top. A minimal grammar fixture
(installGrammar) lives in path_test.go.
Tiny example
import (
"fmt"
"strings"
tabnas "github.com/tabnas/parser/go"
tabnaspath "github.com/tabnas/path/go"
)
func main() {
j := tabnas.Make()
installGrammar(j) // defines val/map/pair/list/elem
_ = j.Use(tabnaspath.Path, nil) // install Path after the grammar
j.Rule("val", func(rs *tabnas.RuleSpec, _ *tabnas.Parser) {
rs.AddAC(func(r *tabnas.Rule, ctx *tabnas.Context) {
path, _ := r.K["path"].([]any)
parts := make([]string, len(path))
for i, p := range path {
parts[i] = fmt.Sprintf("%v", p)
}
if m, ok := r.Node.(map[string]any); ok {
m["$"] = "<" + strings.Join(parts, ",") + ">"
}
})
})
result, _ := j.Parse("{x:{a:1}}")
m := result.(map[string]any)
// m["$"] == "<>" (root path is empty)
x := m["x"].(map[string]any)
// x["$"] == "<x>" (nested map at key x)
_, _ = m, x
}
Documentation
The docs follow the Diátaxis four-quadrant structure:
- Tutorial — zero to a working path-tracking parser, step
by step.
- How-to guides — recipes: read the path, classify segments,
use
r.K["key"], seed a base path.
- Reference — exported identifiers, the
Rule.K keys,
the function refs, meta input.
- Concepts — how it works, the engine relationship, and a
"Differences from the TS version" section.
The canonical TypeScript implementation lives in ../ts/ with its
own docs.
License
MIT. Copyright (c) Richard Rodger.