mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-12 19:25:37 +00:00
Working around goccy
This commit is contained in:
parent
ed5685319d
commit
08e95ebebf
@ -16,7 +16,7 @@ func (o *CandidateNode) goccyDecodeIntoChild(childNode ast.Node, cm yaml.Comment
|
|||||||
return newChild, err
|
return newChild, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap) error {
|
func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, anchorMap map[string]*CandidateNode) error {
|
||||||
log.Debugf("UnmarshalYAML %v", node)
|
log.Debugf("UnmarshalYAML %v", node)
|
||||||
log.Debugf("UnmarshalYAML %v", node.Type().String())
|
log.Debugf("UnmarshalYAML %v", node.Type().String())
|
||||||
log.Debugf("UnmarshalYAML Node Value: %v", node.String())
|
log.Debugf("UnmarshalYAML Node Value: %v", node.String())
|
||||||
@ -49,6 +49,13 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap) er
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
o.Anchor = node.
|
||||||
|
|
||||||
|
if o.Anchor != "" {
|
||||||
|
anchorMap[o.Anchor] = o
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.Ali
|
||||||
|
|
||||||
o.Value = node.String()
|
o.Value = node.String()
|
||||||
switch node.Type() {
|
switch node.Type() {
|
||||||
@ -92,7 +99,7 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap) er
|
|||||||
// to solve the multiline > problem
|
// to solve the multiline > problem
|
||||||
o.Value = astLiteral.Value.Value
|
o.Value = astLiteral.Value.Value
|
||||||
case ast.TagType:
|
case ast.TagType:
|
||||||
if err := o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, cm); err != nil {
|
if err := o.UnmarshalGoccyYAML(node.(*ast.TagNode).Value, cm, anchorMap); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
o.Tag = node.(*ast.TagNode).Start.Value
|
o.Tag = node.(*ast.TagNode).Start.Value
|
||||||
|
@ -17,6 +17,7 @@ type goccyYamlDecoder struct {
|
|||||||
cm yaml.CommentMap
|
cm yaml.CommentMap
|
||||||
bufferRead bytes.Buffer
|
bufferRead bytes.Buffer
|
||||||
readAnything bool
|
readAnything bool
|
||||||
|
anchorMap map[string]*CandidateNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGoccyYAMLDecoder() Decoder {
|
func NewGoccyYAMLDecoder() Decoder {
|
||||||
@ -26,6 +27,7 @@ func NewGoccyYAMLDecoder() Decoder {
|
|||||||
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
|
func (dec *goccyYamlDecoder) Init(reader io.Reader) error {
|
||||||
dec.cm = yaml.CommentMap{}
|
dec.cm = yaml.CommentMap{}
|
||||||
dec.readAnything = false
|
dec.readAnything = false
|
||||||
|
dec.anchorMap = make(map[string]*CandidateNode)
|
||||||
readerToUse := io.TeeReader(reader, &dec.bufferRead)
|
readerToUse := io.TeeReader(reader, &dec.bufferRead)
|
||||||
dec.decoder = *yaml.NewDecoder(readerToUse, yaml.CommentToMap(dec.cm), yaml.UseOrderedMap())
|
dec.decoder = *yaml.NewDecoder(readerToUse, yaml.CommentToMap(dec.cm), yaml.UseOrderedMap())
|
||||||
return nil
|
return nil
|
||||||
@ -57,7 +59,7 @@ func (dec *goccyYamlDecoder) Decode() (*CandidateNode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
candidateNode := &CandidateNode{}
|
candidateNode := &CandidateNode{}
|
||||||
if err := candidateNode.UnmarshalGoccyYAML(ast, dec.cm); err != nil {
|
if err := candidateNode.UnmarshalGoccyYAML(ast, dec.cm, dec.anchorMap); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,13 @@ var yamlFormatScenarios = []formatScenario{
|
|||||||
input: "[null]",
|
input: "[null]",
|
||||||
expected: "[null]\n",
|
expected: "[null]\n",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
description: "simple anchor map",
|
||||||
|
skipDoc: true,
|
||||||
|
input: "a: &remember mike\nb: *remember",
|
||||||
|
expression: "explode(.)",
|
||||||
|
expected: "a: mike\nb: mike\n",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
description: "multi document anchor map",
|
description: "multi document anchor map",
|
||||||
skipDoc: true,
|
skipDoc: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user