diff --git a/YangParser/SemanticModel/Action.cs b/YangParser/SemanticModel/Action.cs new file mode 100644 index 0000000..a14e633 --- /dev/null +++ b/YangParser/SemanticModel/Action.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; + +namespace YangParser.SemanticModel; + +public class Action : Statement +{ + + public Action(YangStatement statement) + { + if (statement.Keyword != Keyword) + throw new InvalidOperationException($"Non-matching Keyword '{statement.Keyword}', expected {Keyword}"); + Argument = statement.Argument!.ToString(); + ValidateChildren(statement); + Children = statement.Children.Select(StatementFactory.Create).ToArray(); + } + + public const string Keyword = "action"; + + public override ChildRule[] PermittedChildren { get; } = + [ + new ChildRule(Description.Keyword), + new ChildRule(Grouping.Keyword, Cardinality.ZeroOrMore), + new ChildRule(FeatureFlag.Keyword, Cardinality.ZeroOrMore), + new ChildRule(Input.Keyword), + new ChildRule(Output.Keyword), + new ChildRule(Reference.Keyword), + new ChildRule(Status.Keyword), + new ChildRule(TypeDefinition.Keyword, Cardinality.ZeroOrMore), + ]; +} \ No newline at end of file diff --git a/YangParser/SemanticModel/Builtins/BuiltinType.cs b/YangParser/SemanticModel/Builtins/BuiltinType.cs new file mode 100644 index 0000000..f7f9b38 --- /dev/null +++ b/YangParser/SemanticModel/Builtins/BuiltinType.cs @@ -0,0 +1,45 @@ +namespace YangParser.SemanticModel.Builtins; + +public class BuiltinType(string name, string? correspondingCSharpType) +{ + public string Name => name; + public string? CorrespondingCSharpType => correspondingCSharpType; +} + +public class Binary() : BuiltinType("binary", "byte[]"); + +public class Bits() : BuiltinType("bits", null); + +public class Boolean() : BuiltinType("boolean", "bool"); + +public class Decimal64() : BuiltinType("decimal64", "double"); + +public class Empty() : BuiltinType("empty", null); + +public class Enumeration() : BuiltinType("enumeration", "enum"); + +public class IdentityReference() : BuiltinType("identityref", null); + +public class InstanceIdentifier() : BuiltinType("instance-identifier", null); + +public class Int8() : BuiltinType("int8", "sbyte"); + +public class Int16() : BuiltinType("int16", "short"); + +public class Int32() : BuiltinType("int32", "int"); + +public class Int64() : BuiltinType("int64", "long"); + +public class LeafReference() : BuiltinType("leafref", null); + +public class String() : BuiltinType("string", "string"); + +public class Uint8() : BuiltinType("uint8", "byte"); + +public class Uint16() : BuiltinType("uint16", "ushort"); + +public class Uint32() : BuiltinType("uint32", "uint"); + +public class Uint64() : BuiltinType("uint64", "ulong"); + +public class Union() : BuiltinType("union", null); \ No newline at end of file diff --git a/YangParser/SemanticModel/Rpc.cs b/YangParser/SemanticModel/Rpc.cs index cc0ce91..9f852ee 100644 --- a/YangParser/SemanticModel/Rpc.cs +++ b/YangParser/SemanticModel/Rpc.cs @@ -19,12 +19,12 @@ public Rpc(YangStatement statement) public override ChildRule[] PermittedChildren { get; } = [ new ChildRule(Description.Keyword), - new ChildRule(Grouping.Keyword), - new ChildRule(FeatureFlag.Keyword), + new ChildRule(Grouping.Keyword, Cardinality.ZeroOrMore), + new ChildRule(FeatureFlag.Keyword, Cardinality.ZeroOrMore), new ChildRule(Input.Keyword), new ChildRule(Output.Keyword), new ChildRule(Reference.Keyword), - new ChildRule(StateData.Keyword), - new ChildRule(TypeDefinition.Keyword), + new ChildRule(Status.Keyword), + new ChildRule(TypeDefinition.Keyword, Cardinality.ZeroOrMore), ]; } \ No newline at end of file