Compare commits

..

1 Commits

Author SHA1 Message Date
Mark
30451c67d7
Merge 82f3e1497e into 6251e95af8 2025-09-08 10:35:13 +00:00
6 changed files with 0 additions and 56 deletions

View File

@ -129,8 +129,6 @@ func (dec *yamlDecoder) Decode() (*CandidateNode, error) {
return nil, err
} else if err != nil {
return nil, err
} else if len(yamlNode.Content) == 0 {
return nil, errors.New("yaml node has no content")
}
candidateNode := CandidateNode{document: dec.documentIndex}

View File

@ -56,29 +56,6 @@ will output
sam
```
## Get parents
Match all parents
Given a sample.yml file of:
```yaml
a:
b:
c: cat
```
then
```bash
yq '.a.b.c | parents' sample.yml
```
will output
```yaml
- c: cat
- b:
c: cat
- a:
b:
c: cat
```
## N-th parent
You can optionally supply the number of levels to go up for the parent, the default being 1.

View File

@ -130,7 +130,6 @@ var participleYqRules = []*participleYqRule{
simpleOp("contains", containsOpType),
simpleOp("split", splitStringOpType),
simpleOp("parents", getParentsOpType),
{"ParentWithLevel", `parent\([0-9]+\)`, parentWithLevel(), 0},
{"ParentWithDefaultLevel", `parent`, parentWithDefaultLevel(), 0},

View File

@ -128,7 +128,6 @@ var getKindOpType = &operationType{Type: "GET_KIND", NumArgs: 0, Precedence: 50,
var getKeyOpType = &operationType{Type: "GET_KEY", NumArgs: 0, Precedence: 50, Handler: getKeyOperator}
var isKeyOpType = &operationType{Type: "IS_KEY", NumArgs: 0, Precedence: 50, Handler: isKeyOperator}
var getParentOpType = &operationType{Type: "GET_PARENT", NumArgs: 0, Precedence: 50, Handler: getParentOperator}
var getParentsOpType = &operationType{Type: "GET_PARENTS", NumArgs: 0, Precedence: 50, Handler: getParentsOperator}
var getCommentOpType = &operationType{Type: "GET_COMMENT", NumArgs: 0, Precedence: 50, Handler: getCommentsOperator}
var getAnchorOpType = &operationType{Type: "GET_ANCHOR", NumArgs: 0, Precedence: 50, Handler: getAnchorOperator}

View File

@ -6,26 +6,6 @@ type parentOpPreferences struct {
Level int
}
func getParentsOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("getParentsOperator")
var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
parentsList := &CandidateNode{Kind: SequenceNode, Tag: "!!seq"}
parent := candidate.Parent
for parent != nil {
parentsList.AddChild(parent)
parent = parent.Parent
}
results.PushBack(parentsList)
}
return context.ChildContext(results), nil
}
func getParentOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("getParentOperator")

View File

@ -29,15 +29,6 @@ var parentOperatorScenarios = []expressionScenario{
"D0, P[b name], (!!str)::sam\n",
},
},
{
description: "Get parents",
subdescription: "Match all parents",
document: "{a: {b: {c: cat} } }",
expression: `.a.b.c | parents`,
expected: []string{
"D0, P[], (!!seq)::- {c: cat}\n- {b: {c: cat}}\n- {a: {b: {c: cat}}}\n",
},
},
{
description: "N-th parent",
subdescription: "You can optionally supply the number of levels to go up for the parent, the default being 1.",