diff --git a/Compiler.Tests/ParsingTests.cs b/Compiler.Tests/ParsingTests.cs index fa49ff8..0123f5a 100644 --- a/Compiler.Tests/ParsingTests.cs +++ b/Compiler.Tests/ParsingTests.cs @@ -75,7 +75,11 @@ import three { prefix b; } grouping A { - uses b:A; + uses b:A { + refine target { + default 80; + } + } container C { uses C; } @@ -134,6 +138,7 @@ leaf module-set-id { } leaf test { type operator; } } + leaf target { type int32; } } } """; @@ -175,6 +180,7 @@ public void GroupingTest() } Assert.IsNotType(statement); } + output.WriteLine(compilationUnit.ToCode()); Log.Clear(); } diff --git a/YangParser/SemanticModel/Grouping.cs b/YangParser/SemanticModel/Grouping.cs index 2f790dd..714f936 100644 --- a/YangParser/SemanticModel/Grouping.cs +++ b/YangParser/SemanticModel/Grouping.cs @@ -117,6 +117,24 @@ public IStatement[] WithUse(Uses use) } Parent.Replace(copy, []); + foreach (var refinement in use.Children.OfType()) + { + var path = refinement.Argument.Split('/'); + var current = copy; + foreach (var element in path) + { + var prefix = element.Prefix(out var name); + var origin = current; + current = origin.Children.FirstOrDefault(c => c.Argument == name); + if (current is null) + { + Log.Write($"Could not find part '{name}' of path {refinement.Argument} in source {origin}"); + break; //Target not present, nothing to refine. + } + } + + current?.Insert(refinement.Children); + } return copy.Children; }