From 8bb323c76c69e6410ea6052bbf977cf43849f2e9 Mon Sep 17 00:00:00 2001 From: caran Date: Wed, 29 May 2024 14:34:45 +0200 Subject: [PATCH] AnyData & AnyXML --- YangParser/SemanticModel/AnyData.cs | 31 +++++++++++++++++++ YangParser/SemanticModel/AnyXml.cs | 24 ++------------ .../SemanticModel/ExtensionReference.cs | 4 +-- YangParser/SemanticModel/Type.cs | 7 +++++ 4 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 YangParser/SemanticModel/AnyData.cs diff --git a/YangParser/SemanticModel/AnyData.cs b/YangParser/SemanticModel/AnyData.cs new file mode 100644 index 0000000..ecd10fc --- /dev/null +++ b/YangParser/SemanticModel/AnyData.cs @@ -0,0 +1,31 @@ +using YangParser.Parser; + +namespace YangParser.SemanticModel; + +public class AnyData : Statement +{ + public AnyData(YangStatement statement) : base(statement) + { + if (statement.Keyword != Keyword) + throw new SemanticError($"Non-matching Keyword '{statement.Keyword}', expected {Keyword}", statement); + } + + public const string Keyword = "anydata"; + + public override ChildRule[] PermittedChildren { get; } = + [ + new ChildRule(Config.Keyword), + new ChildRule(Description.Keyword), + new ChildRule(FeatureFlag.Keyword, Cardinality.ZeroOrMore), + new ChildRule(Mandatory.Keyword), + new ChildRule(Must.Keyword, Cardinality.ZeroOrMore), + new ChildRule(Reference.Keyword), + new ChildRule(Status.Keyword), + new ChildRule(When.Keyword) + ]; + + public override string ToCode() + { + return "public string? Data { get; }"; + } +} \ No newline at end of file diff --git a/YangParser/SemanticModel/AnyXml.cs b/YangParser/SemanticModel/AnyXml.cs index 46c5a69..de41c16 100644 --- a/YangParser/SemanticModel/AnyXml.cs +++ b/YangParser/SemanticModel/AnyXml.cs @@ -10,7 +10,6 @@ public AnyXml(YangStatement statement) : base(statement) { if (statement.Keyword != Keyword) throw new SemanticError($"Non-matching Keyword '{statement.Keyword}', expected {Keyword}", statement); - } public const string Keyword = "anyxml"; @@ -26,28 +25,9 @@ public AnyXml(YangStatement statement) : base(statement) new ChildRule(Status.Keyword), new ChildRule(When.Keyword) ]; -} -public class AnyData : Statement -{ - public AnyData(YangStatement statement) : base(statement) + public override string ToCode() { - if (statement.Keyword != Keyword) - throw new SemanticError($"Non-matching Keyword '{statement.Keyword}', expected {Keyword}", statement); - + return "public string? XML { get; }"; } - - public const string Keyword = "anydata"; - - public override ChildRule[] PermittedChildren { get; } = - [ - new ChildRule(Config.Keyword), - new ChildRule(Description.Keyword), - new ChildRule(FeatureFlag.Keyword, Cardinality.ZeroOrMore), - new ChildRule(Mandatory.Keyword), - new ChildRule(Must.Keyword, Cardinality.ZeroOrMore), - new ChildRule(Reference.Keyword), - new ChildRule(Status.Keyword), - new ChildRule(When.Keyword) - ]; } \ No newline at end of file diff --git a/YangParser/SemanticModel/ExtensionReference.cs b/YangParser/SemanticModel/ExtensionReference.cs index 1663bfc..de7974c 100644 --- a/YangParser/SemanticModel/ExtensionReference.cs +++ b/YangParser/SemanticModel/ExtensionReference.cs @@ -35,7 +35,7 @@ public override string ToCode() if (source.TryGetChild(out _)) { return $$""" - public {{MakeName(classNameSource)}}Extension {{MakeName(classNameSource)}}ExtensionValue { get; } + public {{MakeName(classNameSource)}}Extension? {{MakeName(classNameSource)}}ExtensionValue { get; } {{DescriptionString}}{{AttributeString}} public class {{MakeName(classNameSource)}}Extension : {{inheritance}} { @@ -48,7 +48,7 @@ public class {{MakeName(classNameSource)}}Extension : {{inheritance}} } return $$""" - public {{MakeName(classNameSource)}}Extension {{MakeName(classNameSource)}}ExtensionValue { get; } + public {{MakeName(classNameSource)}}Extension? {{MakeName(classNameSource)}}ExtensionValue { get; } {{DescriptionString}}{{AttributeString}} public class {{MakeName(classNameSource)}}Extension : {{inheritance}} { diff --git a/YangParser/SemanticModel/Type.cs b/YangParser/SemanticModel/Type.cs index 5a153cc..25976c3 100644 --- a/YangParser/SemanticModel/Type.cs +++ b/YangParser/SemanticModel/Type.cs @@ -31,6 +31,11 @@ public Type(YangStatement statement) : base(statement) new ChildRule(Keyword, Cardinality.ZeroOrMore), ]; + public override string ToCode() + { + return string.Empty; + } + public string? Definition { get @@ -42,6 +47,7 @@ public string? Definition m_definition = BuiltinTypeReference.DefaultPattern(this, [], [], TypeName(this), Name!); return m_definition; } + m_name = typeName; m_definition = definition; return m_definition; @@ -59,6 +65,7 @@ public string? Name m_name = typeName; return m_name; } + var prefix = Argument.Prefix(out var value); var reference = this.FindReference(Argument); if (reference is TypeDefinition def)