summaryrefslogtreecommitdiff
path: root/json/json.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-09 21:18:14 +1000
committerAdam Scarr <adam@vektah.net>2017-08-09 21:19:41 +1000
commit47badae641b9cd8862f327864d2143a57b8e30af (patch)
tree930e6621051ec4da5e4fd028f98447e88978837d /json/json.go
parent8b2f10f2384c1efe4492f68b055415be6ead3f0e (diff)
Add godoc
Diffstat (limited to 'json/json.go')
-rw-r--r--json/json.go21
1 files changed, 5 insertions, 16 deletions
diff --git a/json/json.go b/json/json.go
index e2ab252..2748108 100644
--- a/json/json.go
+++ b/json/json.go
@@ -1,6 +1,5 @@
package json
-import "errors"
import . "github.com/vektah/goparsify"
var (
@@ -12,22 +11,22 @@ var (
_number = NumberLit()
_properties = Some(Seq(StringLit(`"`), ":", &_value), ",")
- _array = Map(Seq("[", Some(&_value, ","), "]"), func(n Node) Node {
+ _array = Map(Seq("[", Some(&_value, ","), "]"), func(n Result) Result {
ret := []interface{}{}
for _, child := range n.Child[1].Child {
ret = append(ret, child.Result)
}
- return Node{Result: ret}
+ return Result{Result: ret}
})
- _object = Map(Seq("{", _properties, "}"), func(n Node) Node {
+ _object = Map(Seq("{", _properties, "}"), func(n Result) Result {
ret := map[string]interface{}{}
for _, prop := range n.Child[1].Child {
ret[prop.Child[0].Result.(string)] = prop.Child[2].Result
}
- return Node{Result: ret}
+ return Result{Result: ret}
})
)
@@ -36,15 +35,5 @@ func init() {
}
func Unmarshal(input string) (interface{}, error) {
- result, remaining, err := ParseString(_value, input)
-
- if err != nil {
- return result, err
- }
-
- if remaining != "" {
- return result, errors.New("left unparsed: " + remaining)
- }
-
- return result, err
+ return Run(_value, input)
}