52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package engine
|
|
|
|
import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
|
|
|
func validateFinalSequenceIdentities(root *document.Node, policy sequencePolicy) []Diagnostic {
|
|
if root == nil || policy.selectorTrie == nil {
|
|
return nil
|
|
}
|
|
var diagnostics []Diagnostic
|
|
var visit func(*document.Node, Path, []*sequenceSelectorTrie)
|
|
visit = func(node *document.Node, path Path, states []*sequenceSelectorTrie) {
|
|
if node == nil {
|
|
return
|
|
}
|
|
if node.Kind == document.Sequence {
|
|
var fields []string
|
|
for _, state := range states {
|
|
if state.terminal {
|
|
fields = state.fields
|
|
break
|
|
}
|
|
}
|
|
if fields != nil {
|
|
_, issues := validateNormalizedSequenceIdentityFrom(node, path, fields, sequenceIdentityDiagnosticCodes{
|
|
invalid: CodeSequenceInvalid, conflict: CodeSequenceConflict,
|
|
}, 0, sequencePayloadRecord)
|
|
diagnostics = append(diagnostics, issues...)
|
|
}
|
|
return
|
|
}
|
|
if node.Kind != document.Mapping {
|
|
return
|
|
}
|
|
for _, entry := range node.Mapping {
|
|
next := make([]*sequenceSelectorTrie, 0, len(states)*2)
|
|
for _, state := range states {
|
|
if literal := state.literals[entry.Key]; literal != nil {
|
|
next = append(next, literal)
|
|
}
|
|
if state.wildcard != nil {
|
|
next = append(next, state.wildcard)
|
|
}
|
|
}
|
|
if len(next) != 0 {
|
|
visit(entry.Value, path.Key(entry.Key), next)
|
|
}
|
|
}
|
|
}
|
|
visit(root, Path{}, []*sequenceSelectorTrie{policy.selectorTrie})
|
|
return canonicalDiagnostics(diagnostics)
|
|
}
|