Exemplo 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)
        {
            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);
        }
Exemplo 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 (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.");
        }
Exemplo n.º 3
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)
        {
            Asn1Node Result = null;

            foreach (UserDefinedItem Item in this.items)
            {
                Result = Item.Parse(Document, Macro);
            }

            return(Result);
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
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)
        {
            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.");
        }
Exemplo n.º 6
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.");
            }
        }
Exemplo n.º 7
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)
 {
     Document.AssertNextToken(this.value);
     return(new Values.Asn1StringValue(this.value));
 }
Exemplo n.º 8
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)
 {
     return(this.type.Parse(Document, Macro));
 }
Exemplo n.º 9
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 abstract Asn1Node Parse(Asn1Document Document, Asn1Macro Macro);