Ejemplo n.º 1
0
        /// <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)
        {
            switch (this.Identifier.ToUpper())
            {
            case "TYPE": return(Document.ParseType(this.Identifier, false));

            case "VALUE": return(Document.ParseValue());

            default: return(this.type.Parse(Document, Macro));
            }
        }
Ejemplo n.º 2
0
        /// <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.");
            }
        }