%1.2
This commit is contained in:
parent
414d979931
commit
a9054b9704
15
main_test.go
15
main_test.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user