Skip to content

Commit

Permalink
- added support for Must
Browse files Browse the repository at this point in the history
  • Loading branch information
savaki committed Dec 9, 2016
1 parent 52b770a commit 0e6baec
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package jq

import (
"fmt"
"regexp"
"strconv"
"strings"
Expand All @@ -24,6 +25,15 @@ var (
reArray = regexp.MustCompile(`^\s*\[\s*(\d+)(\s*:\s*(\d+))?\s*]\s*$`)
)

// Must is a convenience method similar to template.Must
func Must(op Op, err error) Op {
if err != nil {
panic(fmt.Errorf("unable to parse selector; %v", err.Error()))
}

return op
}

// Parse takes a string representation of a selector and returns the corresponding Op definition
func Parse(selector string) (Op, error) {
segments := strings.Split(selector, ".")
Expand Down

0 comments on commit 0e6baec

Please sign in to comment.