This commit is contained in:
eson 2020-09-21 18:55:32 +08:00
parent 414d979931
commit a9054b9704

View File

@ -50,13 +50,14 @@ type Predicates struct {
} }
type Node struct { type Node struct {
Name []rune Name []rune // Axis
Value []rune Value []rune // Name(Axis)::Value
Next *Node Next *Node
Sel Selection Sel Selection
Pred Predicates Pred Predicates
} }
// compile 编译
func compile(spath string) (head *Node, tail *Node) { func compile(spath string) (head *Node, tail *Node) {
var path []rune = []rune(strings.TrimSpace(spath)) var path []rune = []rune(strings.TrimSpace(spath))
path = append(path, ' ') path = append(path, ' ')
@ -107,6 +108,13 @@ func getAxes(path []rune, limit int, ii *int, cur *Node) {
switch c { switch c {
case '[': case '[':
case '/': case '/':
case ':':
if path[i+1] == ':' {
i++
return
}
panic("':' error")
case '@': // case '@': //
cur.Sel = SelAttribute cur.Sel = SelAttribute
cur.Name = getAttributeName(path, limit, ii) cur.Name = getAttributeName(path, limit, ii)
@ -123,6 +131,9 @@ func getAxes(path []rune, limit int, ii *int, cur *Node) {
cur.Value = path[s:e] cur.Value = path[s:e]
cur.Sel = SelMethod cur.Sel = SelMethod
return return
case '\\': // 转义
i++
fallthrough
default: default:
cur.Name = append(cur.Name, c) cur.Name = append(cur.Name, c)
} }