1
0
Fork 0

Comments on selector parsing

This commit is contained in:
Gregory Eremin 2015-02-26 23:27:59 +07:00
parent ca9d198b6b
commit 9c4d04ab99
1 changed files with 8 additions and 6 deletions

View File

@ -87,10 +87,15 @@ func parseSelectors(sels []string) map[string]*context {
return ctxs return ctxs
} }
// Format: .bananas#0.weight
// There are two selector types:
// * object property: .prop
// * array index: #1
// Greedy selectors are supported for both types: .* and #*
func parseSelector(sel string) []expectation { func parseSelector(sel string) []expectation {
tmp := strings.Replace(sel, ".", "/.", -1) tmp := strings.Replace(sel, ".", "/.", -1) // "/.bananas#0/.weight"
tmp = strings.Replace(tmp, "#", "/#", -1) tmp = strings.Replace(tmp, "#", "/#", -1) // "/.bananas/#0/.weight"
parts := strings.Split(tmp[1:], "/") parts := strings.Split(tmp[1:], "/") // [".bananas", "#0", ".weight"]
exps := []expectation{} exps := []expectation{}
for _, part := range parts { for _, part := range parts {
@ -111,9 +116,6 @@ func parseSelector(sel string) []expectation {
if len(part) > 2 { if len(part) > 2 {
panic("Invalid selector: " + sel) panic("Invalid selector: " + sel)
} }
}
if c.greedy {
} else if c.typ == object { } else if c.typ == object {
c.key = part[1:] c.key = part[1:]
} else if i, err := strconv.ParseInt(part[1:], 10, 64); err == nil { } else if i, err := strconv.ParseInt(part[1:], 10, 64); err == nil {