Ejemplo n.º 1
0
        public MibModule(string name, Lexer lexer)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            
            if (lexer == null)
            {
                throw new ArgumentNullException("lexer");
            }
            
            _name = name.ToUpperInvariant(); // all module name are uppercase.
            Symbol temp = lexer.GetNextNonEOLSymbol();
            temp.Expect(Symbol.Definitions);
            temp = lexer.GetNextNonEOLSymbol();
            temp.Expect(Symbol.Assign);
            temp = lexer.GetNextSymbol();
            temp.Expect(Symbol.Begin);
            temp = lexer.GetNextNonEOLSymbol();
            if (temp == Symbol.Imports)
            {
                _imports = ParseDependents(lexer);
            }
            else if (temp == Symbol.Exports)
            {
                _exports = ParseExports(lexer);
            }
            else if (temp == Symbol.End)
            {
                return;
            }

            ParseEntities(_tokens, temp, _name, lexer);
        }
Ejemplo n.º 2
0
 public BitsType(string module, string name, Lexer lexer)
 {
     _module = module;
     _name   = name;
     lexer.GetNextNonEOLSymbol().Expect(Symbol.OpenBracket);
     _map = DecodeEnumerations(lexer);
 }
Ejemplo n.º 3
0
        private static IConstruct ParseOthers(string module, IList <Symbol> header, Lexer lexer)
        {
            Symbol current = lexer.GetNextNonEOLSymbol();

            if (current == Symbol.Sequence)
            {
                return(new Sequence(module, header[0].ToString(), lexer));
            }

            if (current == Symbol.Choice)
            {
                return(new Choice(module, header[0].ToString(), lexer));
            }

            if (current == Symbol.Integer)
            {
                return(new IntegerType(module, header[0].ToString(), lexer));
            }

            if (current == Symbol.TextualConvention)
            {
                return(new TextualConvention(module, header[0].ToString(), lexer));
            }

            return(new TypeAssignment(module, header[0].ToString(), current, lexer));
        }
Ejemplo n.º 4
0
        public IntegerType(string module, string name, Lexer lexer)
        {
            _name = name;

            Symbol temp = lexer.CheckNextNonEOLSymbol();
            if (temp == Symbol.OpenBracket)
            {
                lexer.GetNextNonEOLSymbol();
                _isEnumeration = true;
                _map = DecodeEnumerations(lexer);
            }
            else if (temp == Symbol.OpenParentheses)
            {
                lexer.GetNextNonEOLSymbol();
                _isEnumeration = false;
                _ranges = DecodeRanges(lexer);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a <see cref="MibDocument"/> instance.
 /// </summary>
 /// <param name="lexer"></param>
 public MibDocument(Lexer lexer)
 {
     Symbol temp;
     while ((temp = lexer.GetNextNonEOLSymbol()) != null)
     {
         temp.ValidateIdentifier();
         _modules.Add(new MibModule(temp.ToString(), lexer));                
     }
 }
Ejemplo n.º 6
0
        public IntegerType(string module, string name, Lexer lexer)
        {
            _name = name;

            Symbol temp = lexer.CheckNextNonEOLSymbol();

            if (temp == Symbol.OpenBracket)
            {
                lexer.GetNextNonEOLSymbol();
                _isEnumeration = true;
                _map           = DecodeEnumerations(lexer);
            }
            else if (temp == Symbol.OpenParentheses)
            {
                lexer.GetNextNonEOLSymbol();
                _isEnumeration = false;
                _ranges        = DecodeRanges(lexer);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a <see cref="MibDocument"/> instance.
        /// </summary>
        /// <param name="lexer"></param>
        public MibDocument(Lexer lexer)
        {
            Symbol temp;

            while ((temp = lexer.GetNextNonEOLSymbol()) != null)
            {
                temp.ValidateIdentifier();
                _modules.Add(new MibModule(temp.ToString(), lexer));
            }
        }
Ejemplo n.º 8
0
 public Sequence(string module, string name, Lexer lexer)
 {
     _name = name;
     // parse between ( )
     Symbol temp = lexer.GetNextNonEOLSymbol(); 
     int bracketSection = 0;
     temp.Expect(Symbol.OpenBracket);
     bracketSection++;
     while (bracketSection > 0)
     {
         temp = lexer.GetNextNonEOLSymbol();
         if (temp == Symbol.OpenBracket)
         {
             bracketSection++;
         }
         else if (temp == Symbol.CloseBracket)
         {
             bracketSection--;
         }
     }
 }
Ejemplo n.º 9
0
        public UnsignedType(string module, string name, Lexer lexer)
        {
            _module = module;
            _name = name;

            Symbol temp = lexer.CheckNextNonEOLSymbol();
            if (temp == Symbol.OpenParentheses)
            {
                lexer.GetNextNonEOLSymbol();
                _ranges = DecodeRanges(lexer);
            }
        }
Ejemplo n.º 10
0
        public UnsignedType(string module, string name, Lexer lexer)
        {
            _module = module;
            _name   = name;

            Symbol temp = lexer.CheckNextNonEOLSymbol();

            if (temp == Symbol.OpenParentheses)
            {
                lexer.GetNextNonEOLSymbol();
                _ranges = DecodeRanges(lexer);
            }
        }
Ejemplo n.º 11
0
        public Sequence(string module, string name, Lexer lexer)
        {
            _name = name;
            // parse between ( )
            Symbol temp           = lexer.GetNextNonEOLSymbol();
            int    bracketSection = 0;

            temp.Expect(Symbol.OpenBracket);
            bracketSection++;
            while (bracketSection > 0)
            {
                temp = lexer.GetNextNonEOLSymbol();
                if (temp == Symbol.OpenBracket)
                {
                    bracketSection++;
                }
                else if (temp == Symbol.CloseBracket)
                {
                    bracketSection--;
                }
            }
        }
Ejemplo n.º 12
0
        public MibModule(string name, Lexer lexer)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (lexer == null)
            {
                throw new ArgumentNullException("lexer");
            }

            _name = name.ToUpperInvariant(); // all module name are uppercase.
            Symbol temp = lexer.GetNextNonEOLSymbol();

            temp.Expect(Symbol.Definitions);
            temp = lexer.GetNextNonEOLSymbol();
            temp.Expect(Symbol.Assign);
            temp = lexer.GetNextSymbol();
            temp.Expect(Symbol.Begin);
            temp = lexer.GetNextNonEOLSymbol();
            if (temp == Symbol.Imports)
            {
                _imports = ParseDependents(lexer);
            }
            else if (temp == Symbol.Exports)
            {
                _exports = ParseExports(lexer);
            }
            else if (temp == Symbol.End)
            {
                return;
            }

            ParseEntities(_tokens, temp, _name, lexer);
        }
        public TextualConvention(string module, string name, Lexer lexer)
        {
            _name = name;

            Symbol temp = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.DisplayHint)
            {
                // TODO: this needs decoding to a useful format.
                _displayHint = new DisplayHint(lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' }));
                temp         = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Status);
            try
            {
                _status = StatusHelper.CreateStatus(lexer.GetNextNonEOLSymbol().ToString());
                temp    = lexer.GetNextNonEOLSymbol();
            }
            catch (ArgumentException)
            {
                temp.Throw("Invalid status");
            }

            temp.Expect(Symbol.Description);
            _description = lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' });
            temp         = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.Reference)
            {
                _reference = lexer.GetNextNonEOLSymbol().ToString();
                temp       = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Syntax);

            /*
             * RFC2579 definition:
             *       Syntax ::=   -- Must be one of the following:
             *                    -- a base type (or its refinement), or
             *                    -- a BITS pseudo-type
             *               type
             *             | "BITS" "{" NamedBits "}"
             *
             * From section 3.5:
             *      The data structure must be one of the alternatives defined
             *      in the ObjectSyntax CHOICE or the BITS construct.  Note
             *      that this means that the SYNTAX clause of a Textual
             *      Convention can not refer to a previously defined Textual
             *      Convention.
             *
             *      The SYNTAX clause of a TEXTUAL CONVENTION macro may be
             *      sub-typed in the same way as the SYNTAX clause of an
             *      OBJECT-TYPE macro.
             *
             * Therefore the possible values are (grouped by underlying type):
             *      INTEGER, Integer32
             *      OCTET STRING, Opaque
             *      OBJECT IDENTIFIER
             *      IpAddress
             *      Counter64
             *      Unsigned32, Counter32, Gauge32, TimeTicks
             *      BITS
             * With appropriate sub-typing.
             */

            temp = lexer.GetNextNonEOLSymbol();
            if (temp == Symbol.Bits)
            {
                _syntax = new BitsType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                _syntax = new IntegerType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Octet)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.String);
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Opaque)
            {
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.IpAddress)
            {
                _syntax = new IpAddressType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Counter64)
            {
                _syntax = new Counter64Type(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                _syntax = new UnsignedType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Object)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.Identifier);
                _syntax = new ObjectIdentifierType(module, string.Empty, lexer);
            }
            else
            {
                //temp.Throw("illegal syntax for textual convention");
                _syntax = new CustomType(module, string.Empty, lexer);
            }
        }
Ejemplo n.º 14
0
        private static IConstruct ParseOthers(string module, IList<Symbol> header, Lexer lexer)
        {
            Symbol current = lexer.GetNextNonEOLSymbol();
            
            if (current == Symbol.Sequence)
            {
                return new Sequence(module, header[0].ToString(), lexer);
            }

            if (current == Symbol.Choice)
            {
                return new Choice(module, header[0].ToString(), lexer);
            }

            if (current == Symbol.Integer)
            {
                return new IntegerType(module, header[0].ToString(), lexer);
            }

            if (current == Symbol.TextualConvention)
            {
                return new TextualConvention(module, header[0].ToString(), lexer);
            }

            return new TypeAssignment(module, header[0].ToString(), current, lexer);
        }
Ejemplo n.º 15
0
        public TextualConvention(string module, string name, Lexer lexer)
        {
            _name = name;

            Symbol temp = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.DisplayHint)
            {
                // TODO: this needs decoding to a useful format.
                _displayHint = new DisplayHint(lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' }));
                temp = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Status);
            try
            {
                _status = StatusHelper.CreateStatus(lexer.GetNextNonEOLSymbol().ToString());
                temp = lexer.GetNextNonEOLSymbol();
            }
            catch (ArgumentException)
            {
                temp.Throw("Invalid status");
            }

            temp.Expect(Symbol.Description);
            _description = lexer.GetNextNonEOLSymbol().ToString().Trim(new[] { '"' });
            temp = lexer.GetNextNonEOLSymbol();

            if (temp == Symbol.Reference)
            {
                _reference = lexer.GetNextNonEOLSymbol().ToString();
                temp = lexer.GetNextNonEOLSymbol();
            }

            temp.Expect(Symbol.Syntax);

            /* 
             * RFC2579 definition:
             *       Syntax ::=   -- Must be one of the following:
             *                    -- a base type (or its refinement), or
             *                    -- a BITS pseudo-type
             *               type
             *             | "BITS" "{" NamedBits "}"
             *
             * From section 3.5:
             *      The data structure must be one of the alternatives defined
             *      in the ObjectSyntax CHOICE or the BITS construct.  Note
             *      that this means that the SYNTAX clause of a Textual
             *      Convention can not refer to a previously defined Textual
             *      Convention.
             *      
             *      The SYNTAX clause of a TEXTUAL CONVENTION macro may be
             *      sub-typed in the same way as the SYNTAX clause of an
             *      OBJECT-TYPE macro.
             * 
             * Therefore the possible values are (grouped by underlying type):
             *      INTEGER, Integer32
             *      OCTET STRING, Opaque
             *      OBJECT IDENTIFIER
             *      IpAddress
             *      Counter64
             *      Unsigned32, Counter32, Gauge32, TimeTicks
             *      BITS
             * With appropriate sub-typing.
             */

            temp = lexer.GetNextNonEOLSymbol();
            if (temp == Symbol.Bits)
            {
                _syntax = new BitsType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                _syntax = new IntegerType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Octet)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.String);
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Opaque)
            {
                _syntax = new OctetStringType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.IpAddress)
            {
                _syntax = new IpAddressType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Counter64)
            {
                _syntax = new Counter64Type(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                _syntax = new UnsignedType(module, string.Empty, lexer);
            }
            else if (temp == Symbol.Object)
            {
                temp = lexer.GetNextSymbol();
                temp.Expect(Symbol.Identifier);
                _syntax = new ObjectIdentifierType(module, string.Empty, lexer);
            }
            else
            {
                //temp.Throw("illegal syntax for textual convention");
                _syntax = new CustomType(module, string.Empty, lexer);
            }
        }