Rename TomlTree to Tree (#159)

Avoid stutter.

Fixes #55
This commit is contained in:
Thomas Pelletier
2017-05-10 17:53:23 -07:00
committed by GitHub
parent 23f644976a
commit 685a1f1cb7
20 changed files with 170 additions and 170 deletions
+3 -3
View File
@@ -112,7 +112,7 @@
// There are several filters provided with the library:
//
// tree
// Allows nodes of type TomlTree.
// Allows nodes of type Tree.
// int
// Allows nodes of type int64.
// float
@@ -138,7 +138,7 @@
//
// Compiled Queries
//
// Queries may be executed directly on a TomlTree object, or compiled ahead
// Queries may be executed directly on a Tree object, or compiled ahead
// of time and executed discretely. The former is more convienent, but has the
// penalty of having to recompile the query expression each time.
//
@@ -163,7 +163,7 @@
//
// // define the filter, and assign it to the query
// query.SetFilter("bazOnly", func(node interface{}) bool{
// if tree, ok := node.(*TomlTree); ok {
// if tree, ok := node.(*Tree); ok {
// return tree.Has("baz")
// }
// return false // reject all other node types
+12 -12
View File
@@ -42,7 +42,7 @@ func newMatchKeyFn(name string) *matchKeyFn {
}
func (f *matchKeyFn) call(node interface{}, ctx *queryContext) {
if array, ok := node.([]*toml.TomlTree); ok {
if array, ok := node.([]*toml.Tree); ok {
for _, tree := range array {
item := tree.Get(f.Name)
if item != nil {
@@ -50,7 +50,7 @@ func (f *matchKeyFn) call(node interface{}, ctx *queryContext) {
f.next.call(item, ctx)
}
}
} else if tree, ok := node.(*toml.TomlTree); ok {
} else if tree, ok := node.(*toml.Tree); ok {
item := tree.Get(f.Name)
if item != nil {
ctx.lastPosition = tree.GetPosition(f.Name)
@@ -72,7 +72,7 @@ func newMatchIndexFn(idx int) *matchIndexFn {
func (f *matchIndexFn) call(node interface{}, ctx *queryContext) {
if arr, ok := node.([]interface{}); ok {
if f.Idx < len(arr) && f.Idx >= 0 {
if treesArray, ok := node.([]*toml.TomlTree); ok {
if treesArray, ok := node.([]*toml.Tree); ok {
if len(treesArray) > 0 {
ctx.lastPosition = treesArray[0].Position()
}
@@ -107,7 +107,7 @@ func (f *matchSliceFn) call(node interface{}, ctx *queryContext) {
}
// loop and gather
for idx := realStart; idx < realEnd; idx += f.Step {
if treesArray, ok := node.([]*toml.TomlTree); ok {
if treesArray, ok := node.([]*toml.Tree); ok {
if len(treesArray) > 0 {
ctx.lastPosition = treesArray[0].Position()
}
@@ -127,7 +127,7 @@ func newMatchAnyFn() *matchAnyFn {
}
func (f *matchAnyFn) call(node interface{}, ctx *queryContext) {
if tree, ok := node.(*toml.TomlTree); ok {
if tree, ok := node.(*toml.Tree); ok {
for _, k := range tree.Keys() {
v := tree.Get(k)
ctx.lastPosition = tree.GetPosition(k)
@@ -164,17 +164,17 @@ func newMatchRecursiveFn() *matchRecursiveFn {
func (f *matchRecursiveFn) call(node interface{}, ctx *queryContext) {
originalPosition := ctx.lastPosition
if tree, ok := node.(*toml.TomlTree); ok {
var visit func(tree *toml.TomlTree)
visit = func(tree *toml.TomlTree) {
if tree, ok := node.(*toml.Tree); ok {
var visit func(tree *toml.Tree)
visit = func(tree *toml.Tree) {
for _, k := range tree.Keys() {
v := tree.Get(k)
ctx.lastPosition = tree.GetPosition(k)
f.next.call(v, ctx)
switch node := v.(type) {
case *toml.TomlTree:
case *toml.Tree:
visit(node)
case []*toml.TomlTree:
case []*toml.Tree:
for _, subtree := range node {
visit(subtree)
}
@@ -205,7 +205,7 @@ func (f *matchFilterFn) call(node interface{}, ctx *queryContext) {
f.Pos.String(), f.Name))
}
switch castNode := node.(type) {
case *toml.TomlTree:
case *toml.Tree:
for _, k := range castNode.Keys() {
v := castNode.Get(k)
if fn(v) {
@@ -213,7 +213,7 @@ func (f *matchFilterFn) call(node interface{}, ctx *queryContext) {
f.next.call(v, ctx)
}
}
case []*toml.TomlTree:
case []*toml.Tree:
for _, v := range castNode {
if fn(v) {
if len(castNode) > 0 {
+1 -1
View File
@@ -36,7 +36,7 @@ func valueString(root interface{}) string {
}
sort.Strings(items)
result = "[" + strings.Join(items, ", ") + "]"
case *toml.TomlTree:
case *toml.Tree:
// workaround for unreliable map key ordering
items := []string{}
for _, k := range node.Keys() {
+6 -6
View File
@@ -53,7 +53,7 @@ type queryContext struct {
type pathFn interface {
setNext(next pathFn)
// it is the caller's responsibility to set the ctx.lastPosition before invoking call()
// node can be one of: *toml.TomlTree, []*toml.TomlTree, or a scalar
// node can be one of: *toml.Tree, []*toml.Tree, or a scalar
call(node interface{}, ctx *queryContext)
}
@@ -84,13 +84,13 @@ func (q *Query) appendPath(next pathFn) {
}
// Compile compiles a TOML path expression. The returned Query can be used
// to match elements within a TomlTree and its descendants. See Execute.
// to match elements within a Tree and its descendants. See Execute.
func Compile(path string) (*Query, error) {
return parseQuery(lexQuery(path))
}
// Execute executes a query against a TomlTree, and returns the result of the query.
func (q *Query) Execute(tree *toml.TomlTree) *Result {
// Execute executes a query against a Tree, and returns the result of the query.
func (q *Query) Execute(tree *toml.Tree) *Result {
result := &Result{
items: []interface{}{},
positions: []toml.Position{},
@@ -109,7 +109,7 @@ func (q *Query) Execute(tree *toml.TomlTree) *Result {
}
// CompileAndExecute is a shorthand for Compile(path) followed by Execute(tree).
func CompileAndExecute(path string, tree *toml.TomlTree) (*Result, error) {
func CompileAndExecute(path string, tree *toml.Tree) (*Result, error) {
query, err := Compile(path)
if err != nil {
return nil, err
@@ -132,7 +132,7 @@ func (q *Query) SetFilter(name string, fn NodeFilterFn) {
var defaultFilterFunctions = map[string]NodeFilterFn{
"tree": func(node interface{}) bool {
_, ok := node.(*toml.TomlTree)
_, ok := node.(*toml.Tree)
return ok
},
"int": func(node interface{}) bool {
+4 -4
View File
@@ -99,13 +99,13 @@ func ExampleNodeFilterFn_filterExample() {
// define the filter, and assign it to the query
query.SetFilter("bazOnly", func(node interface{}) bool {
if tree, ok := node.(*toml.TomlTree); ok {
if tree, ok := node.(*toml.Tree); ok {
return tree.Has("baz")
}
return false // reject all other node types
})
// results contain only the 'struct_two' TomlTree
// results contain only the 'struct_two' Tree
query.Execute(tree)
}
@@ -147,8 +147,8 @@ func TestTomlQuery(t *testing.T) {
t.Errorf("Expected resultset of 1, got %d instead: %v", len(values), values)
}
if tt, ok := values[0].(*toml.TomlTree); !ok {
t.Errorf("Expected type of TomlTree: %T", values[0])
if tt, ok := values[0].(*toml.Tree); !ok {
t.Errorf("Expected type of Tree: %T", values[0])
} else if tt.Get("a") != int64(1) {
t.Errorf("Expected 'a' with a value 1: %v", tt.Get("a"))
} else if tt.Get("b") != int64(2) {