Move query to its own subpackage (#152)

Move all the query system to its own package. The reason is to
avoid it to rely on unexported methods and structures, and move
it out of the main package since this is really not a core
feature. It is still tied to the toml.TomlTree and toml.Position
structures for now.

* Move query mechanism to its own subpackage
* Rename QueryResult to Result to avoid stutter
* Add query.CompileAndExecute

Fixes #116
This commit is contained in:
Thomas Pelletier
2017-05-07 17:14:13 -07:00
committed by GitHub
parent 64bc956d5e
commit 23f644976a
17 changed files with 665 additions and 532 deletions
+5 -9
View File
@@ -36,6 +36,11 @@ func TreeFromMap(m map[string]interface{}) (*TomlTree, error) {
return result.(*TomlTree), nil
}
// Position returns the position of the tree.
func (t *TomlTree) Position() Position {
return t.position
}
// Has returns a boolean indicating if the given key exists.
func (t *TomlTree) Has(key string) bool {
if key == "" {
@@ -247,15 +252,6 @@ func (t *TomlTree) createSubTree(keys []string, pos Position) error {
return nil
}
// Query compiles and executes a query on a tree and returns the query result.
func (t *TomlTree) Query(query string) (*QueryResult, error) {
q, err := CompileQuery(query)
if err != nil {
return nil, err
}
return q.Execute(t), nil
}
// LoadReader creates a TomlTree from any io.Reader.
func LoadReader(reader io.Reader) (tree *TomlTree, err error) {
defer func() {