2017-09-11 23:00:31 +00:00
|
|
|
package hclwrite
|
2017-06-06 15:53:13 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-11 23:40:37 +00:00
|
|
|
"github.com/hashicorp/hcl2/hcl/hclsyntax"
|
2017-06-06 15:53:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type nativeNodeSorter struct {
|
2017-09-11 23:40:37 +00:00
|
|
|
Nodes []hclsyntax.Node
|
2017-06-06 15:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s nativeNodeSorter) Len() int {
|
|
|
|
return len(s.Nodes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s nativeNodeSorter) Less(i, j int) bool {
|
|
|
|
rangeI := s.Nodes[i].Range()
|
|
|
|
rangeJ := s.Nodes[j].Range()
|
|
|
|
return rangeI.Start.Byte < rangeJ.Start.Byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s nativeNodeSorter) Swap(i, j int) {
|
|
|
|
s.Nodes[i], s.Nodes[j] = s.Nodes[j], s.Nodes[i]
|
|
|
|
}
|