Skip to content

Commit 2c7cce0

Browse files
committed
Line and Column working with Goccy, Fixed Anchor Map problem
1 parent 2bd08ea commit 2c7cce0

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pkg/yqlib/candidate_node_goccy_yaml.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
5151
}
5252

5353
o.Value = node.String()
54+
o.Line = node.GetToken().Position.Line
55+
o.Column = node.GetToken().Position.Column
56+
5457
switch node.Type() {
5558
case ast.IntegerType:
5659
o.Kind = ScalarNode
@@ -170,6 +173,7 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
170173
case ast.MergeKeyType:
171174
log.Debugf("UnmarshalYAML - a merge key")
172175
o.Kind = ScalarNode
176+
o.Tag = "!!merge" // note - I should be able to get rid of this.
173177
o.Value = "<<"
174178

175179
default:
@@ -181,22 +185,23 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
181185

182186
func (o *CandidateNode) goccyProcessMappingValueNode(mappingEntry *ast.MappingValueNode, cm yaml.CommentMap, anchorMap map[string]*CandidateNode) error {
183187
log.Debug("UnmarshalYAML MAP KEY entry %v", mappingEntry.Key)
184-
keyNode, err := o.goccyDecodeIntoChild(mappingEntry.Key, cm, anchorMap)
185-
if err != nil {
188+
189+
// AddKeyValueFirst because it clones the nodes, and we want to have the real refs when Unmarshalling
190+
// particularly for the anchorMap
191+
keyNode, valueNode := o.AddKeyValueChild(&CandidateNode{}, &CandidateNode{})
192+
193+
if err := keyNode.UnmarshalGoccyYAML(mappingEntry.Key, cm, anchorMap); err != nil {
186194
return err
187195
}
188-
keyNode.IsMapKey = true
189196

190197
log.Debug("UnmarshalYAML MAP VALUE entry %v", mappingEntry.Value)
191-
valueNode, err := o.goccyDecodeIntoChild(mappingEntry.Value, cm, anchorMap)
192-
if err != nil {
198+
if err := valueNode.UnmarshalGoccyYAML(mappingEntry.Value, cm, anchorMap); err != nil {
193199
return err
194200
}
195201

196202
if mappingEntry.FootComment != nil {
197203
valueNode.FootComment = mappingEntry.FootComment.String()
198204
}
199-
o.AddKeyValueChild(keyNode, valueNode)
200205

201206
return nil
202207
}

0 commit comments

Comments
 (0)