MCPcopy Create free account
hub / github.com/antchfx/xpath / parseNodeTest

Method parseNodeTest

parse.go:458–514  ·  view source on GitHub ↗

NodeTest ::= NameTest | nodeType '(' ')' | 'processing-instruction' '(' Literal ')'

(n node, axeTyp string, matchType NodeType)

Source from the content-addressed store, hash-verified

456
457// NodeTest ::= NameTest | nodeType '(' ')' | 'processing-instruction' '(' Literal ')'
458func (p *parser) parseNodeTest(n node, axeTyp string, matchType NodeType) (opnd node) {
459 switch p.r.typ {
460 case itemName:
461 if p.r.canBeFunc && isNodeType(p.r) {
462 var prop string
463 switch p.r.name {
464 case "comment", "text", "processing-instruction", "node":
465 prop = p.r.name
466 }
467 var name string
468 p.next()
469 p.skipItem(itemLParens)
470 if prop == "processing-instruction" && p.r.typ != itemRParens {
471 checkItem(p.r, itemString)
472 name = p.r.strval
473 p.next()
474 }
475 p.skipItem(itemRParens)
476 switch prop {
477 case "comment":
478 matchType = CommentNode
479 case "text":
480 matchType = TextNode
481 case "processing-instruction":
482 case "node":
483 matchType = allNode
484 default:
485 matchType = RootNode
486 }
487
488 opnd = newAxisNode(axeTyp, matchType, name, "", prop, n)
489 } else {
490 prefix := p.r.prefix
491 name := p.r.name
492 p.next()
493 if p.r.name == "*" {
494 name = ""
495 }
496 opnd = newAxisNode(axeTyp, matchType, name, prefix, "", n, func(a *axisNode) {
497 if prefix != "" && p.namespaces != nil {
498 if ns, ok := p.namespaces[prefix]; ok {
499 a.hasNamespaceURI = true
500 a.namespaceURI = ns
501 } else {
502 panic(fmt.Sprintf("prefix %s not defined.", prefix))
503 }
504 }
505 })
506 }
507 case itemStar:
508 opnd = newAxisNode(axeTyp, matchType, "", "", "", n)
509 p.next()
510 default:
511 panic("expression must evaluate to a node-set")
512 }
513 return opnd
514}
515

Callers 1

parseStepMethod · 0.95

Calls 5

nextMethod · 0.95
skipItemMethod · 0.95
isNodeTypeFunction · 0.85
checkItemFunction · 0.85
newAxisNodeFunction · 0.85

Tested by

no test coverage detected