Skip to content

Commit

Permalink
Merge pull request #85 from goccy/feature/fix-format
Browse files Browse the repository at this point in the history
Fix format for encoding complexity string literal
  • Loading branch information
goccy authored Mar 2, 2020
2 parents 0669816 + 202c0fc commit 5010b01
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ func (n *StringNode) String() string {
}
block := strings.TrimSuffix(strings.TrimSuffix(strings.Join(values, lbc), fmt.Sprintf("%s %s", lbc, space)), fmt.Sprintf(" %s", space))
return fmt.Sprintf("%s%s%s", header, lbc, block)
} else if len(n.Value) > 0 && (n.Value[0] == '{' || n.Value[0] == '[') {
return fmt.Sprintf(`'%s'`, n.Value)
}

return n.Value
}

Expand Down Expand Up @@ -872,6 +873,8 @@ func (n *AnchorNode) String() string {
value := n.Value.String()
if len(strings.Split(value, "\n")) > 1 {
return fmt.Sprintf("&%s\n%s", n.Name.String(), value)
} else if _, ok := n.Value.(*SequenceNode); ok {
return fmt.Sprintf("&%s\n%s", n.Name.String(), value)
}
return fmt.Sprintf("&%s %s", n.Name.String(), value)
}
Expand Down

0 comments on commit 5010b01

Please sign in to comment.