Clean up lint (#56)
The only real change in this commit is that MaxInt is made private. Everything else should be gofmt'ing, docs and cleanup of lint.
This commit is contained in:
committed by
Thomas Pelletier
parent
9d93af61de
commit
6e26017b00
@@ -299,7 +299,7 @@ func (l *tomlLexer) lexKey() tomlLexStateFn {
|
||||
|
||||
func (l *tomlLexer) lexComment() tomlLexStateFn {
|
||||
for next := l.peek(); next != '\n' && next != eof; next = l.peek() {
|
||||
if (next == '\r' && l.follow("\r\n")) {
|
||||
if next == '\r' && l.follow("\r\n") {
|
||||
break
|
||||
}
|
||||
l.next()
|
||||
|
||||
@@ -87,7 +87,6 @@ func TestMultipleKeyGroupsComment(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
func TestSimpleWindowsCRLF(t *testing.T) {
|
||||
testFlow(t, "a=4\r\nb=2", []token{
|
||||
token{Position{1, 1}, tokenKey, "a"},
|
||||
|
||||
+3
-3
@@ -109,7 +109,7 @@ func TestPathSliceStart(t *testing.T) {
|
||||
assertPath(t,
|
||||
"$[123:]",
|
||||
buildPath(
|
||||
newMatchSliceFn(123, MaxInt, 1),
|
||||
newMatchSliceFn(123, maxInt, 1),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ func TestPathSliceStartStep(t *testing.T) {
|
||||
assertPath(t,
|
||||
"$[123::7]",
|
||||
buildPath(
|
||||
newMatchSliceFn(123, MaxInt, 7),
|
||||
newMatchSliceFn(123, maxInt, 7),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ func TestPathSliceStep(t *testing.T) {
|
||||
assertPath(t,
|
||||
"$[::7]",
|
||||
buildPath(
|
||||
newMatchSliceFn(0, MaxInt, 7),
|
||||
newMatchSliceFn(0, maxInt, 7),
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,30 +4,32 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Type of a user-defined filter function, for use with Query.SetFilter().
|
||||
// NodeFilterFn represents a user-defined filter function, for use with
|
||||
// Query.SetFilter().
|
||||
//
|
||||
// The return value of the function must indicate if 'node' is to be included
|
||||
// at this stage of the TOML path. Returning true will include the node, and
|
||||
// returning false will exclude it.
|
||||
// The return value of the function must indicate if 'node' is to be included
|
||||
// at this stage of the TOML path. Returning true will include the node, and
|
||||
// returning false will exclude it.
|
||||
//
|
||||
// NOTE: Care should be taken to write script callbacks such that they are safe
|
||||
// to use from multiple goroutines.
|
||||
// NOTE: Care should be taken to write script callbacks such that they are safe
|
||||
// to use from multiple goroutines.
|
||||
type NodeFilterFn func(node interface{}) bool
|
||||
|
||||
// The result of Executing a Query
|
||||
// QueryResult is the result of Executing a Query.
|
||||
type QueryResult struct {
|
||||
items []interface{}
|
||||
positions []Position
|
||||
}
|
||||
|
||||
// appends a value/position pair to the result set
|
||||
// appends a value/position pair to the result set.
|
||||
func (r *QueryResult) appendResult(node interface{}, pos Position) {
|
||||
r.items = append(r.items, node)
|
||||
r.positions = append(r.positions, pos)
|
||||
}
|
||||
|
||||
// Set of values within a QueryResult. The order of values is not guaranteed
|
||||
// to be in document order, and may be different each time a query is executed.
|
||||
// Values is a set of values within a QueryResult. The order of values is not
|
||||
// guaranteed to be in document order, and may be different each time a query is
|
||||
// executed.
|
||||
func (r *QueryResult) Values() []interface{} {
|
||||
values := make([]interface{}, len(r.items))
|
||||
for i, v := range r.items {
|
||||
@@ -41,8 +43,8 @@ func (r *QueryResult) Values() []interface{} {
|
||||
return values
|
||||
}
|
||||
|
||||
// Set of positions for values within a QueryResult. Each index in Positions()
|
||||
// corresponds to the entry in Value() of the same index.
|
||||
// Positions is a set of positions for values within a QueryResult. Each index
|
||||
// in Positions() corresponds to the entry in Value() of the same index.
|
||||
func (r *QueryResult) Positions() []Position {
|
||||
return r.positions
|
||||
}
|
||||
@@ -86,13 +88,13 @@ func (q *Query) appendPath(next pathFn) {
|
||||
next.setNext(newTerminatingFn()) // init the next functor
|
||||
}
|
||||
|
||||
// Compiles a TOML path expression. The returned Query can be used to match
|
||||
// elements within a TomlTree and its descendants.
|
||||
// CompileQuery compiles a TOML path expression. The returned Query can be used
|
||||
// to match elements within a TomlTree and its descendants.
|
||||
func CompileQuery(path string) (*Query, error) {
|
||||
return parseQuery(lexQuery(path))
|
||||
}
|
||||
|
||||
// Executes a query against a TomlTree, and returns the result of the query.
|
||||
// Execute executes a query against a TomlTree, and returns the result of the query.
|
||||
func (q *Query) Execute(tree *TomlTree) *QueryResult {
|
||||
result := &QueryResult{
|
||||
items: []interface{}{},
|
||||
@@ -110,8 +112,8 @@ func (q *Query) Execute(tree *TomlTree) *QueryResult {
|
||||
return result
|
||||
}
|
||||
|
||||
// Sets a user-defined filter function. These may be used inside "?(..)" query
|
||||
// expressions to filter TOML document elements within a query.
|
||||
// SetFilter sets a user-defined filter function. These may be used inside
|
||||
// "?(..)" query expressions to filter TOML document elements within a query.
|
||||
func (q *Query) SetFilter(name string, fn NodeFilterFn) {
|
||||
if q.filters == &defaultFilterFunctions {
|
||||
// clone the static table
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func assertArrayContainsInAnyOrder(t *testing.T, array []interface{}, objects ...interface{}) {
|
||||
if (len(array) != len(objects)) {
|
||||
if len(array) != len(objects) {
|
||||
t.Fatalf("array contains %d objects but %d are expected", len(array), len(objects))
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func assertArrayContainsInAnyOrder(t *testing.T, array []interface{}, objects ..
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryExample(t *testing.T) {
|
||||
func TestQueryExample(t *testing.T) {
|
||||
config, _ := Load(`
|
||||
[[book]]
|
||||
title = "The Stand"
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const MaxInt = int(^uint(0) >> 1)
|
||||
const maxInt = int(^uint(0) >> 1)
|
||||
|
||||
type queryParser struct {
|
||||
flow chan token
|
||||
@@ -203,7 +203,7 @@ loop: // labeled loop for easy breaking
|
||||
|
||||
func (p *queryParser) parseSliceExpr() queryParserStateFn {
|
||||
// init slice to grab all elements
|
||||
start, end, step := 0, MaxInt, 1
|
||||
start, end, step := 0, maxInt, 1
|
||||
|
||||
// parse optional start
|
||||
tok := p.getToken()
|
||||
|
||||
@@ -29,6 +29,7 @@ func newTomlTree() *TomlTree {
|
||||
}
|
||||
}
|
||||
|
||||
// TreeFromMap initializes a new TomlTree object using the given map.
|
||||
func TreeFromMap(m map[string]interface{}) *TomlTree {
|
||||
return &TomlTree{
|
||||
values: m,
|
||||
@@ -347,12 +348,13 @@ func (t *TomlTree) toToml(indent, keyspace string) string {
|
||||
return result
|
||||
}
|
||||
|
||||
// Query compiles and executes a query on a tree and returns the query result.
|
||||
func (t *TomlTree) Query(query string) (*QueryResult, error) {
|
||||
if q, err := CompileQuery(query); err != nil {
|
||||
q, err := CompileQuery(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return q.Execute(t), nil
|
||||
}
|
||||
return q.Execute(t), nil
|
||||
}
|
||||
|
||||
// ToString generates a human-readable representation of the current tree.
|
||||
|
||||
Reference in New Issue
Block a user