From 60c1a4a58015a43d40472782776fc9f637e47da3 Mon Sep 17 00:00:00 2001 From: Lukas Jarosch Date: Wed, 14 Feb 2024 20:19:05 +0100 Subject: [PATCH] refactor: cleanup --- reference.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/reference.go b/reference.go index c75b823..3f816ee 100644 --- a/reference.go +++ b/reference.go @@ -18,7 +18,8 @@ var ( // See: https://regex101.com/r/lIuuep/1 ReferenceRegex = regexp.MustCompile(`\${(?P[\w-]+(?:\:[\w-]+)*)}`) - ErrUndefinedReference = fmt.Errorf("undefined reference") + ErrUndefinedReference = fmt.Errorf("undefined reference") + ErrReferenceSourceIsNil = fmt.Errorf("reference source is nil") ) // Reference is a reference to a value with a different path. @@ -35,29 +36,18 @@ func (ref Reference) Name() string { type ResolvedReference struct { Reference - // TargetValue is the value to which the TargetPath points to - // This can be [data.NilValue]. In that case there is no target - // value but a target reference. + // TargetValue is the value to which the TargetPath points to. + // If TargetReference is not nil, this value must be [data.NilValue]. TargetValue data.Value // TargetReference is non-nil if the Reference points to another [Reference] + // If the Reference just points to a scalar value, this will be nil. TargetReference *Reference } -// ReferenceParser is responsible for discovering and resolving references. -type ReferenceParser struct { - source ReferenceSourceWalker -} - type ReferenceSourceWalker interface { WalkValues(func(path data.Path, value data.Value) error) error } -type ReferenceSourceGetter interface { - GetPath(path data.Path) (data.Value, error) -} - -var ErrReferenceSourceIsNil = fmt.Errorf("source is nil") - func ParseReferences(source ReferenceSourceWalker) ([]Reference, error) { if source == nil { return nil, ErrReferenceSourceIsNil @@ -82,6 +72,10 @@ func ParseReferences(source ReferenceSourceWalker) ([]Reference, error) { return references, nil } +type ReferenceSourceGetter interface { + GetPath(path data.Path) (data.Value, error) +} + func ResolveReferences(references []Reference, resolveSource ReferenceSourceGetter) ([]ResolvedReference, error) { if resolveSource == nil { return nil, ErrReferenceSourceIsNil