mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 07:08:06 +00:00
7103b78d38
* toml wip * wip * Fixed auto parsing toml * Added build flag not to include toml * Parse toml docs and tests * minor updates
66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
package yqlib
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
logging "gopkg.in/op/go-logging.v1"
|
|
yaml "gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type DataTreeNavigator interface {
|
|
// given the context and a expressionNode,
|
|
// this will process the against the given expressionNode and return
|
|
// a new context of matching candidates
|
|
GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error)
|
|
|
|
DeeplyAssign(context Context, path []interface{}, rhsNode *yaml.Node) error
|
|
}
|
|
|
|
type dataTreeNavigator struct {
|
|
}
|
|
|
|
func NewDataTreeNavigator() DataTreeNavigator {
|
|
return &dataTreeNavigator{}
|
|
}
|
|
|
|
func (d *dataTreeNavigator) DeeplyAssign(context Context, path []interface{}, rhsNode *yaml.Node) error {
|
|
|
|
rhsCandidateNode := &CandidateNode{
|
|
Path: path,
|
|
Node: rhsNode,
|
|
}
|
|
|
|
assignmentOp := &Operation{OperationType: assignOpType, Preferences: assignPreferences{}}
|
|
|
|
rhsOp := &Operation{OperationType: valueOpType, CandidateNode: rhsCandidateNode}
|
|
|
|
assignmentOpNode := &ExpressionNode{
|
|
Operation: assignmentOp,
|
|
LHS: createTraversalTree(path, traversePreferences{}, false),
|
|
RHS: &ExpressionNode{Operation: rhsOp},
|
|
}
|
|
|
|
_, err := d.GetMatchingNodes(context, assignmentOpNode)
|
|
return err
|
|
}
|
|
|
|
func (d *dataTreeNavigator) GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error) {
|
|
if expressionNode == nil {
|
|
log.Debugf("getMatchingNodes - nothing to do")
|
|
return context, nil
|
|
}
|
|
log.Debugf("Processing Op: %v", expressionNode.Operation.toString())
|
|
if log.IsEnabledFor(logging.DEBUG) {
|
|
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
|
|
log.Debug(NodeToString(el.Value.(*CandidateNode)))
|
|
}
|
|
}
|
|
log.Debug(">>")
|
|
handler := expressionNode.Operation.OperationType.Handler
|
|
if handler != nil {
|
|
return handler(d, context, expressionNode)
|
|
}
|
|
return Context{}, fmt.Errorf("Unknown operator %v", expressionNode.Operation.OperationType)
|
|
|
|
}
|