Skip to content

Commit

Permalink
Added builtin types
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed May 16, 2024
1 parent 3155309 commit 34d2abd
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
31 changes: 31 additions & 0 deletions YangParser/SemanticModel/Action.cs
Original file line number Diff line number Diff line change
@@ -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),
];
}
45 changes: 45 additions & 0 deletions YangParser/SemanticModel/Builtins/BuiltinType.cs
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 4 additions & 4 deletions YangParser/SemanticModel/Rpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
];
}

0 comments on commit 34d2abd

Please sign in to comment.