Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Asn1Macro.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
5
7{
12 {
13 internal readonly Dictionary<string, SupportingSyntax> supportingSyntax;
14 internal readonly SupportingSyntax[] supportingSyntaxArray;
15 private readonly UserDefinedItem typeNotation;
16 private readonly UserDefinedItem valueNotation;
17 private readonly Asn1Document document;
18 private readonly string name;
19
30 {
31 this.name = Name;
32 this.typeNotation = TypeNotation;
33 this.valueNotation = ValueNotation;
34 this.supportingSyntaxArray = SupportingSyntax;
35 this.document = Document;
36
37 this.supportingSyntax = new Dictionary<string, SupportingSyntax>();
38
39 foreach (SupportingSyntax Syntax in SupportingSyntax)
40 this.supportingSyntax[Syntax.Name] = Syntax;
41 }
42
46 public string Name => this.name;
47
51 public UserDefinedItem TypeNotation => this.typeNotation;
52
56 public UserDefinedItem ValueNotation => this.valueNotation;
57
61 public SupportingSyntax[] SupportingSyntax => this.supportingSyntaxArray;
62
66 public Asn1Document Document => this.document;
67
75 {
76 this.typeNotation.Parse(Document, this);
77
78 Document.AssertNextToken("::=");
79
80 Asn1Node Node = this.valueNotation.Parse(Document, this);
81
82 if (!(Node is Asn1Value Value))
83 throw Document.SyntaxError("Value expected.");
84
85 return Value;
86 }
87
95 {
96 if (this.typeNotation.Parse(Document, this) is Asn1Type Type)
97 return Type;
98 else
99 throw Document.SyntaxError("Unable to evaluate type.");
100 }
101
109 public override Task ExportCSharp(StringBuilder Output, CSharpExportState State, int Indent, CSharpExportPass Pass)
110 {
111 return Task.CompletedTask; // Don't export macro.
112 }
113
119 {
120 if (this.valueNotation is UserDefinedSpecifiedPart Part)
121 return Part.Type;
122 else
123 return new Types.Asn1Any();
124 }
125
126 }
127}
Represents an ASN.1 document.
Definition: Asn1Document.cs:21
Base class for all ASN.1 nodes.
Definition: Asn1Node.cs:38
Abstract base class for ASN.1 types.
Definition: Asn1Type.cs:13
Abstract base class for values.
Definition: Asn1Value.cs:11
Asn1Value ParseValue(Asn1Document Document)
Parses a value from the portion of the document at the current position, according to the instruction...
Definition: Asn1Macro.cs:74
SupportingSyntax[] SupportingSyntax
Supporting syntax
Definition: Asn1Macro.cs:61
Asn1Document Document
ASN.1 document defining macro.
Definition: Asn1Macro.cs:66
UserDefinedItem TypeNotation
Type notation
Definition: Asn1Macro.cs:51
Asn1Macro(string Name, UserDefinedItem TypeNotation, UserDefinedItem ValueNotation, SupportingSyntax[] SupportingSyntax, Asn1Document Document)
ASN.1 Macro
Definition: Asn1Macro.cs:28
override Task ExportCSharp(StringBuilder Output, CSharpExportState State, int Indent, CSharpExportPass Pass)
Exports to C#
Definition: Asn1Macro.cs:109
UserDefinedItem ValueNotation
Value notation
Definition: Asn1Macro.cs:56
Asn1Type ParseType(Asn1Document Document)
Parses a type from the portion of the document at the current position, according to the instructions...
Definition: Asn1Macro.cs:94
Asn1Type GetValueType()
Gets the ASN.1 type corresponding to the value.
Definition: Asn1Macro.cs:118
Abstract base class for user-defined parts in macros
CSharpExportPass
Defines different C# export passes.
Definition: Asn1Node.cs:12