mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-14 12:35:35 +00:00
better optional traverse array hack
This commit is contained in:
parent
1085f11905
commit
3bd5e746da
@ -71,15 +71,16 @@ func (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Ope
|
|||||||
log.Debugf("deleting open bracket from opstack")
|
log.Debugf("deleting open bracket from opstack")
|
||||||
|
|
||||||
//and append a collect to the result
|
//and append a collect to the result
|
||||||
|
|
||||||
// hack - see if there's the optional traverse flag
|
// hack - see if there's the optional traverse flag
|
||||||
// on the close op - move it to the collect op.
|
// on the close op - move it to the traverse array op
|
||||||
// allows for .["cat"]?
|
// allows for .["cat"]?
|
||||||
prefs := traversePreferences{}
|
prefs := traversePreferences{}
|
||||||
closeTokenMatch := string(currentToken.Match.Bytes)
|
closeTokenMatch := string(currentToken.Match.Bytes)
|
||||||
if closeTokenMatch[len(closeTokenMatch)-1:] == "?" {
|
if closeTokenMatch[len(closeTokenMatch)-1:] == "?" {
|
||||||
prefs.OptionalTraverse = true
|
prefs.OptionalTraverse = true
|
||||||
}
|
}
|
||||||
result = append(result, &Operation{OperationType: collectOperator, Preferences: prefs})
|
result = append(result, &Operation{OperationType: collectOperator})
|
||||||
log.Debugf("put collect onto the result")
|
log.Debugf("put collect onto the result")
|
||||||
if opener != openCollect {
|
if opener != openCollect {
|
||||||
result = append(result, &Operation{OperationType: shortPipeOpType})
|
result = append(result, &Operation{OperationType: shortPipeOpType})
|
||||||
@ -87,9 +88,9 @@ func (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Ope
|
|||||||
}
|
}
|
||||||
|
|
||||||
//traverseArrayCollect is a sneaky op that needs to be included too
|
//traverseArrayCollect is a sneaky op that needs to be included too
|
||||||
//when closing a []
|
//when closing a ]
|
||||||
if len(opStack) > 0 && opStack[len(opStack)-1].Operation != nil && opStack[len(opStack)-1].Operation.OperationType == traverseArrayOpType {
|
if len(opStack) > 0 && opStack[len(opStack)-1].Operation != nil && opStack[len(opStack)-1].Operation.OperationType == traverseArrayOpType {
|
||||||
|
opStack[len(opStack)-1].Operation.Preferences = prefs
|
||||||
opStack, result = popOpToResult(opStack, result)
|
opStack, result = popOpToResult(opStack, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,11 +96,8 @@ func traverseArrayOperator(d *dataTreeNavigator, context Context, expressionNode
|
|||||||
}
|
}
|
||||||
prefs := traversePreferences{}
|
prefs := traversePreferences{}
|
||||||
|
|
||||||
// we could have .[blah]?
|
if expressionNode.Operation.Preferences != nil {
|
||||||
// and we sneakily put the traverse prefs on the RHS prefs
|
prefs = expressionNode.Operation.Preferences.(traversePreferences)
|
||||||
// dodgey :/
|
|
||||||
if expressionNode.Rhs != nil && expressionNode.Rhs.Operation.Preferences != nil {
|
|
||||||
prefs = expressionNode.Rhs.Operation.Preferences.(traversePreferences)
|
|
||||||
}
|
}
|
||||||
var indicesToTraverse = rhs.MatchingNodes.Front().Value.(*CandidateNode).Node.Content
|
var indicesToTraverse = rhs.MatchingNodes.Front().Value.(*CandidateNode).Node.Content
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user