processAxis processes a query for the XPath axis node.
(root *axisNode, flags flag, props *builderProp)
| 70 | |
| 71 | // processAxis processes a query for the XPath axis node. |
| 72 | func (b *builder) processAxis(root *axisNode, flags flag, props *builderProp) (query, error) { |
| 73 | var ( |
| 74 | err error |
| 75 | qyInput query |
| 76 | qyOutput query |
| 77 | ) |
| 78 | b.firstInput = nil |
| 79 | predicate := axisPredicate(root) |
| 80 | |
| 81 | if root.Input == nil { |
| 82 | qyInput = &contextQuery{} |
| 83 | *props = builderProps.None |
| 84 | } else { |
| 85 | inputFlags := flagsEnum.None |
| 86 | if (flags & flagsEnum.Filter) == 0 { |
| 87 | if root.AxisType == "child" && (root.Input.Type() == nodeAxis) { |
| 88 | if input := root.Input.(*axisNode); input.AxisType == "descendant-or-self" { |
| 89 | var qyGrandInput query |
| 90 | if input.Input != nil { |
| 91 | qyGrandInput, err = b.processNode(input.Input, flagsEnum.SmartDesc, props) |
| 92 | if err != nil { |
| 93 | return nil, err |
| 94 | } |
| 95 | } else { |
| 96 | qyGrandInput = &contextQuery{} |
| 97 | } |
| 98 | qyOutput = &descendantQuery{name: root.LocalName, Input: qyGrandInput, Predicate: predicate, Self: false} |
| 99 | *props |= builderProps.NonFlat |
| 100 | return qyOutput, nil |
| 101 | } |
| 102 | } |
| 103 | if root.AxisType == "descendant" || root.AxisType == "descendant-or-self" { |
| 104 | inputFlags |= flagsEnum.SmartDesc |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | qyInput, err = b.processNode(root.Input, inputFlags, props) |
| 109 | if err != nil { |
| 110 | return nil, err |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | switch root.AxisType { |
| 115 | case "ancestor": |
| 116 | qyOutput = &ancestorQuery{name: root.LocalName, Input: qyInput, Predicate: predicate} |
| 117 | *props |= builderProps.NonFlat |
| 118 | case "ancestor-or-self": |
| 119 | qyOutput = &ancestorQuery{name: root.LocalName, Input: qyInput, Predicate: predicate, Self: true} |
| 120 | *props |= builderProps.NonFlat |
| 121 | case "attribute": |
| 122 | qyOutput = &attributeQuery{name: root.LocalName, Input: qyInput, Predicate: predicate} |
| 123 | case "child": |
| 124 | if (*props & builderProps.NonFlat) == 0 { |
| 125 | qyOutput = &childQuery{name: root.LocalName, Input: qyInput, Predicate: predicate} |
| 126 | } else { |
| 127 | qyOutput = &cachedChildQuery{name: root.LocalName, Input: qyInput, Predicate: predicate} |
| 128 | } |
| 129 | case "descendant": |
no test coverage detected