/// <summary> /// Parses the portion of the document at the current position, according to the /// instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro being executed.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { if (Document.namedNodes.TryGetValue(this.identifier, out Asn1Node Node)) { if (Node is Asn1TypeDefinition TypeDef) { return(TypeDef.Definition.Parse(Document, Macro)); } else if (Node is Asn1Type Type) { return(Type.Parse(Document, Macro)); } else { throw Document.SyntaxError("Type reference expected: " + this.identifier); } } foreach (SupportingSyntax Syntax in Macro.SupportingSyntax) { if (Syntax.Name == this.identifier) { return(Syntax.Parse(Document, Macro)); } } throw Document.SyntaxError("Supporting syntax for " + this.identifier + " not found."); }
/// <summary> /// Parses the portion of the document at the current position, according to the type. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro performing parsing.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { if (!(Macro.Document.namedNodes.TryGetValue(this.identifier, out Asn1Node Node))) { throw Document.SyntaxError("Type named " + this.identifier + " not found."); } if (!(Node is Asn1Type Type)) { throw Document.SyntaxError("Type expected."); } return(Type.Parse(Document, Macro)); }
/// <summary> /// Parses the portion of the document at the current position, according to the /// instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro being executed.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { int Bak = Document.pos; int BestPos = -1; Asn1Node Best = null; Asn1Node Option; foreach (UserDefinedItem Item in this.options) { Document.pos = Bak; try { Option = Item.Parse(Document, Macro); if (Best is null || Document.pos > BestPos) { BestPos = Document.pos; Best = Option; } } catch (Exception) { // Ignore } } if (BestPos < 0) { throw Document.SyntaxError("Invalid option."); } Document.pos = BestPos; return(Best); }
/// <summary> /// Parses the portion of the document at the current position, according to the type. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro performing parsing.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { if (Document.ParseValue() is Values.Asn1BooleanValue Value) { return(Value); } else { throw Document.SyntaxError("Boolean value expected."); } }
/// <summary> /// Parses a type from the portion of the document at the current position, /// according to the instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <returns>Parsed ASN.1 type node.</returns> public Asn1Type ParseType(Asn1Document Document) { if (this.typeNotation.Parse(Document, this) is Asn1Type Type) { return(Type); } else { throw Document.SyntaxError("Unable to evaluate type."); } }
/// <summary> /// Parses the portion of the document at the current position, according to the type. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro performing parsing.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { if (Document.ParseValue() is Values.Asn1FloatingPointValue Value) { return(Value); } else { throw Document.SyntaxError("String value expected."); } }
/// <summary> /// Parses the portion of the document at the current position, according to the /// instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <returns>Parsed ASN.1 node.</returns> public KeyValuePair <Asn1Type, Asn1Value> Parse(Asn1Document Document) { this.typeNotation.Parse(Document, this); Asn1Node Node = this.valueNotation.Parse(Document, this); if (!(Node is Asn1Value Value)) { throw Document.SyntaxError("Value expected."); } return(new KeyValuePair <Asn1Type, Asn1Value>(null, Value)); }
/// <summary> /// Parses the portion of the document at the current position, according to the /// instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro being executed.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { if (Macro.Document.namedNodes.TryGetValue(this.identifier, out Asn1Node Node)) { if (Node is Asn1TypeDefinition TypeDef) { return(TypeDef.Definition.Parse(Document, Macro)); } else if (Node is Asn1Type Type) { return(Type.Parse(Document, Macro)); } else if (Node is Asn1FieldDefinition FieldDef) { return(FieldDef.Type.Parse(Document, Macro)); } else { throw Document.SyntaxError("Type reference expected: " + this.identifier); } } if (Macro.supportingSyntax.TryGetValue(this.identifier, out SupportingSyntax Syntax)) { return(Syntax.Parse(Document, Macro)); } switch (this.identifier.ToLower()) { case "empty": return(null); case "type": return(Document.ParseType(this.Identifier, false)); case "value": return(Document.ParseValue()); default: throw Document.SyntaxError("Supporting syntax for " + this.identifier + " not found."); } }
/// <summary> /// Parses a value from the portion of the document at the current position, /// according to the instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <returns>Parsed ASN.1 value node.</returns> public Asn1Value ParseValue(Asn1Document Document) { this.typeNotation.Parse(Document, this); Document.AssertNextToken("::="); Asn1Node Node = this.valueNotation.Parse(Document, this); if (!(Node is Asn1Value Value)) { throw Document.SyntaxError("Value expected."); } return(Value); }
/// <summary> /// Parses the portion of the document at the current position, according to the /// instructions available in the macro. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro being executed.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { int Bak = Document.pos; foreach (UserDefinedItem Item in this.options) { Document.pos = Bak; try { return(Item.Parse(Document, Macro)); } catch (Exception) { // Ignore } } throw Document.SyntaxError("Invalid option."); }
/// <summary> /// Parses the portion of the document at the current position, according to the type. /// </summary> /// <param name="Document">ASN.1 document being parsed.</param> /// <param name="Macro">Macro performing parsing.</param> /// <returns>Parsed ASN.1 node.</returns> public override Asn1Node Parse(Asn1Document Document, Asn1Macro Macro) { int Bak = Document.pos; foreach (Asn1Node Choice in this.Nodes) { if (Choice is Asn1Type Type) { try { Document.pos = Bak; return(Type.Parse(Document, Macro)); } catch (Exception) { // Ignore } } } throw Document.SyntaxError("Unable to parse choices."); }