-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8af89d
commit 321d269
Showing
8 changed files
with
139 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using YangParser.Parser; | ||
|
||
namespace YangParser.SemanticModel; | ||
|
||
public class BelongsTo : Statement | ||
{ | ||
public BelongsTo(YangStatement statement) : base(statement) | ||
{ | ||
if (statement.Keyword != Keyword) | ||
throw new SemanticError($"Non-matching Keyword '{statement.Keyword}', expected {Keyword}", statement); | ||
} | ||
|
||
public const string Keyword = "belongs-to"; | ||
|
||
public override ChildRule[] PermittedChildren { get; } = | ||
[ | ||
new ChildRule(Prefix.Keyword, Cardinality.Required) | ||
]; | ||
|
||
public override string ToCode() | ||
{ | ||
return string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Linq; | ||
using YangParser.Parser; | ||
|
||
namespace YangParser.SemanticModel; | ||
|
||
public class ExtensionReference : Statement | ||
{ | ||
public ExtensionReference(YangStatement statement) : base(statement, false) | ||
{ | ||
SourceModulePrefix = statement.Prefix; | ||
ExtensionName = statement.Keyword; | ||
Argument = statement.Argument?.ToString() ?? string.Empty; | ||
} | ||
|
||
public string ExtensionName { get; } | ||
|
||
public string SourceModulePrefix { get; } | ||
|
||
public override string ToCode() | ||
{ | ||
var sourceModule = this.FindSourceFor(SourceModulePrefix); | ||
var source = sourceModule?.Extensions.FirstOrDefault(e => e.Argument == ExtensionName); | ||
if (source is null) | ||
{ | ||
throw new SemanticError( | ||
$"Could not find source extension for {SourceModulePrefix}:{ExtensionName} in module {sourceModule}", | ||
Source); | ||
} | ||
|
||
var children = Children.Select(c => c.ToCode()).ToArray(); | ||
var inheritance = string.IsNullOrWhiteSpace(SourceModulePrefix) | ||
? MakeName(ExtensionName) | ||
: SourceModulePrefix + ':' + MakeName(ExtensionName); | ||
var classNameSource = Argument.Contains('/') ? ExtensionName + Argument.GetHashCode() : Argument; | ||
if (source.TryGetChild<Argument>(out _)) | ||
{ | ||
return $$""" | ||
public {{MakeName(classNameSource)}}Extension {{MakeName(classNameSource)}}ExtensionValue { get; } | ||
{{DescriptionString}}{{AttributeString}} | ||
public class {{MakeName(classNameSource)}}Extension : {{inheritance}} | ||
{ | ||
public {{MakeName(classNameSource)}}Extension() : base("{{SingleLine(Argument).Replace("\n", "\\\n")}}") | ||
{ | ||
} | ||
{{Indent(string.Join("\n", children))}} | ||
} | ||
"""; | ||
} | ||
|
||
return $$""" | ||
public {{MakeName(classNameSource)}}Extension {{MakeName(classNameSource)}}ExtensionValue { get; } | ||
{{DescriptionString}}{{AttributeString}} | ||
public class {{MakeName(classNameSource)}}Extension : {{inheritance}} | ||
{ | ||
{{Indent(string.Join("\n", children))}} | ||
} | ||
"""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters