Skip to content

Commit

Permalink
Refinement implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed May 30, 2024
1 parent 99db906 commit 72355e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Compiler.Tests/ParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ import three {
prefix b;
}
grouping A {
uses b:A;
uses b:A {
refine target {
default 80;
}
}
container C {
uses C;
}
Expand Down Expand Up @@ -134,6 +138,7 @@ leaf module-set-id {
}
leaf test { type operator; }
}
leaf target { type int32; }
}
}
""";
Expand Down Expand Up @@ -175,6 +180,7 @@ public void GroupingTest()
}
Assert.IsNotType<Uses>(statement);
}
output.WriteLine(compilationUnit.ToCode());

Log.Clear();
}
Expand Down
18 changes: 18 additions & 0 deletions YangParser/SemanticModel/Grouping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ public IStatement[] WithUse(Uses use)
}

Parent.Replace(copy, []);
foreach (var refinement in use.Children.OfType<Refine>())
{
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;
}
Expand Down

0 comments on commit 72355e1

Please sign in to comment.