mirror of
https://github.com/google/go-jsonnet.git
synced 2025-08-08 07:17:12 +02:00
Sort FreeVariables slice (#148)
* sort FreeVariables slice * regenerate the standard library AST
This commit is contained in:
parent
b04e73e163
commit
ce84685fb0
4278
ast/stdast.go
4278
ast/stdast.go
File diff suppressed because it is too large
Load Diff
34
ast/util.go
34
ast/util.go
@ -1,7 +1,41 @@
|
||||
/*
|
||||
Copyright 2016 Google Inc. All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package ast
|
||||
|
||||
import "sort"
|
||||
|
||||
func (i *IdentifierSet) Append(idents Identifiers) {
|
||||
for _, ident := range idents {
|
||||
i.Add(ident)
|
||||
}
|
||||
}
|
||||
|
||||
// ToOrderedSlice returns the elements of the current set as a ordered slice
|
||||
func (set IdentifierSet) ToOrderedSlice() []Identifier {
|
||||
var s []Identifier
|
||||
for v := range set {
|
||||
s = append(s, v)
|
||||
}
|
||||
sort.Sort(identifierSorter(s))
|
||||
return s
|
||||
}
|
||||
|
||||
type identifierSorter []Identifier
|
||||
|
||||
func (s identifierSorter) Len() int { return len(s) }
|
||||
func (s identifierSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s identifierSorter) Less(i, j int) bool { return s[i] < s[j] }
|
||||
|
@ -145,7 +145,7 @@ func analyzeVisit(a ast.Node, inObject bool, vars ast.IdentifierSet) error {
|
||||
default:
|
||||
panic(fmt.Sprintf("Unexpected node %#v", a))
|
||||
}
|
||||
a.SetFreeVariables(s.freeVars.ToSlice())
|
||||
a.SetFreeVariables(s.freeVars.ToOrderedSlice())
|
||||
return s.err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user