fieldPathToPathAST converts an omni analysis.FieldPath to a base.PathAST. The omni analysis represents array access as a separate Selector with Name=indexText and ArrayIndex>=0, following the preceding property selector. The base.PathAST representation merges these: an ArraySelector carries the pro
(fp analysis.FieldPath)
| 95 | // property name AND the index. So we fold consecutive (ItemSelector, ArraySelector) |
| 96 | // pairs into a single base.ArraySelector. |
| 97 | func fieldPathToPathAST(fp analysis.FieldPath) *base.PathAST { |
| 98 | if len(fp) == 0 { |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | // Merge omni selectors into base nodes, folding array indices into the |
| 103 | // preceding item selector. |
| 104 | nodes := mergeSelectors(fp) |
| 105 | if len(nodes) == 0 { |
| 106 | return nil |
| 107 | } |
| 108 | |
| 109 | pathAST := base.NewPathAST(nodes[0]) |
| 110 | current := pathAST.Root |
| 111 | for i := 1; i < len(nodes); i++ { |
| 112 | current.SetNext(nodes[i]) |
| 113 | current = nodes[i] |
| 114 | } |
| 115 | return pathAST |
| 116 | } |
| 117 | |
| 118 | // mergeSelectors converts omni selectors to base.SelectorNode values, |
| 119 | // merging an array selector into the preceding item selector when possible. |
no test coverage detected