Validate final registered sequence identities
This commit is contained in:
51
internal/engine/final_identity.go
Normal file
51
internal/engine/final_identity.go
Normal file
@@ -0,0 +1,51 @@
|
||||
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)
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user