private static string ParseAugments(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Augments)
            {
                string augment = null;

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenBracket);

                current = symbols.NextNonEOLSymbol();
                augment = current.ToString();

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseBracket);

                return(augment);
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return(null);
        }
Beispiel #2
0
        private static string ParseDescription(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.Description);

            return symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' });
        }
Beispiel #3
0
        private static string ParseAugments(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Augments)
            {
                string augment = null;

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenBracket);

                current = symbols.NextNonEOLSymbol();
                augment = current.ToString();

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseBracket);

                return augment;
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }
            
            return null;
        }
Beispiel #4
0
        private static string ParseDescription(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.Description);

            return(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }));
        }
Beispiel #5
0
        /// <summary>
        /// Creates a <see cref="Choice"/> instance.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="name"></param>
        /// <param name="lexer"></param>
        public Choice(IModule module, string name, ISymbolEnumerator symbols)
            : base(module, name)
        {
            while (symbols.NextNonEOLSymbol() != Symbol.OpenBracket)
            {
            }

            while (symbols.NextNonEOLSymbol() != Symbol.CloseBracket)
            {
            }
        }
Beispiel #6
0
        /// <summary>
        /// Creates a <see cref="Choice"/> instance.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="name"></param>
        /// <param name="lexer"></param>
        public Choice(IModule module, string name, ISymbolEnumerator symbols)
            : base(module, name)
        {
            while (symbols.NextNonEOLSymbol() != Symbol.OpenBracket)
            {
            }

            while (symbols.NextNonEOLSymbol() != Symbol.CloseBracket)
            {
            }
        }
Beispiel #7
0
        private static DisplayHint ParseDisplayHint(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.DisplayHint)
            {
                return(new DisplayHint(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' })));
            }

            symbols.PutBack(current);
            return(null);
        }
Beispiel #8
0
        private static DisplayHint ParseDisplayHint(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.DisplayHint)
            {
                return new DisplayHint(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }));
            }

            symbols.PutBack(current);
            return null;
        }
Beispiel #9
0
        public Macro(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name = preAssignSymbols[0].ToString();
            
            while (symbols.NextNonEOLSymbol() != Symbol.Begin)
            {                
            }

            while (symbols.NextNonEOLSymbol() != Symbol.End)
            {
            }
        }
Beispiel #10
0
        public Macro(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name   = preAssignSymbols[0].ToString();

            while (symbols.NextNonEOLSymbol() != Symbol.Begin)
            {
            }

            while (symbols.NextNonEOLSymbol() != Symbol.End)
            {
            }
        }
        private static string ParseUnits(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Units)
            {
                return(symbols.NextNonEOLSymbol().ToString());
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return(null);
        }
        private static string ParseDescription(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Description)
            {
                return(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }));
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return(null);
        }
Beispiel #13
0
        private static Status ParseStatus(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.Status);

            try
            {
                return (Status)Enum.Parse(typeof(Status), symbols.NextNonEOLSymbol().ToString());
            }
            catch (ArgumentException)
            {
                current.Assert(false, "Invalid/Unknown status");
            }

            return Status.current;
        }
Beispiel #14
0
        /// <summary>
        /// Creates an <see cref="IntegerType"/> instance.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="name"></param>
        /// <param name="enumerator"></param>
        public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Types?t = GetExactType(type);

            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            _isEnumeration = false;

            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.OpenBracket)
            {
                _isEnumeration = true;
                symbols.PutBack(current);
                _map = Lexer.DecodeEnumerations(symbols);
            }
            else if (current == Symbol.OpenParentheses)
            {
                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Creates an <see cref="IntegerType"/> instance.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="name"></param>
        /// <param name="enumerator"></param>
        public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base (module, name)
        {
            Types? t = GetExactType(type);
            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            _isEnumeration = false;

            Symbol current = symbols.NextNonEOLSymbol();
            if (current == Symbol.OpenBracket)
            {
                _isEnumeration = true;
                symbols.PutBack(current);
                _map = Lexer.DecodeEnumerations(symbols);
            }
            else if (current == Symbol.OpenParentheses)
            {
                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
        private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.Syntax);

            return(Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true));
        }
Beispiel #17
0
        private static Status ParseStatus(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.Status);

            try
            {
                return((Status)Enum.Parse(typeof(Status), symbols.NextNonEOLSymbol().ToString()));
            }
            catch (ArgumentException)
            {
                current.Assert(false, "Invalid/Unknown status");
            }

            return(Status.current);
        }
Beispiel #18
0
        private static string ParseDefVal(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.DefVal)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenBracket);

                string defVal = null;
                current = symbols.NextNonEOLSymbol();

                if (current == Symbol.OpenBracket)
                {
                    int depth = 1;
                    // TODO: decode this.
                    while (depth > 0)
                    {
                        current = symbols.NextNonEOLSymbol();
                        if (current == Symbol.OpenBracket)
                        {
                            depth++;
                        }
                        else if (current == Symbol.CloseBracket)
                        {
                            depth--;
                        }
                    }
                }
                else
                {
                    defVal = current.ToString();
                    current = symbols.NextNonEOLSymbol();
                    current.Expect(Symbol.CloseBracket);
                }

                return defVal;
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return null;
        }
        private static IList <string> ParseIndices(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Index)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenBracket);

                List <string> indices = new List <string>();

                while (current != Symbol.CloseBracket)
                {
                    current = symbols.NextNonEOLSymbol();

                    bool lastIndex = false;
                    if (current == Symbol.Implied)
                    {
                        current   = symbols.NextNonEOLSymbol();
                        lastIndex = true; // 'IMPLIED' may only be used for last index
                    }

                    current.Assert((current != Symbol.Comma) && (current != Symbol.CloseBracket), "Expected index name but found symbol!");
                    indices.Add(current.ToString());

                    current = symbols.NextNonEOLSymbol();
                    if (lastIndex)
                    {
                        current.Expect(Symbol.CloseBracket);
                    }
                    else
                    {
                        current.Expect(Symbol.Comma, Symbol.CloseBracket);
                    }
                }

                return(indices);
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return(null);
        }
        private static string ParseDefVal(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.DefVal)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenBracket);

                string defVal = null;
                current = symbols.NextNonEOLSymbol();

                if (current == Symbol.OpenBracket)
                {
                    int depth = 1;
                    // TODO: decode this.
                    while (depth > 0)
                    {
                        current = symbols.NextNonEOLSymbol();
                        if (current == Symbol.OpenBracket)
                        {
                            depth++;
                        }
                        else if (current == Symbol.CloseBracket)
                        {
                            depth--;
                        }
                    }
                }
                else
                {
                    defVal  = current.ToString();
                    current = symbols.NextNonEOLSymbol();
                    current.Expect(Symbol.CloseBracket);
                }

                return(defVal);
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return(null);
        }
Beispiel #21
0
        private static string ParseReference(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Reference)
            {
                string reference = symbols.NextNonEOLSymbol().ToString();
                if ((reference.Length >= 2) && reference.StartsWith("\"") && reference.EndsWith("\""))
                {
                    return reference.Substring(1, reference.Length-2);
                }

                return reference;
            }

            symbols.PutBack(current);
            return null;
        }
Beispiel #22
0
        private static string ParseReference(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Reference)
            {
                string reference = symbols.NextNonEOLSymbol().ToString();
                if ((reference.Length >= 2) && reference.StartsWith("\"") && reference.EndsWith("\""))
                {
                    return(reference.Substring(1, reference.Length - 2));
                }

                return(reference);
            }

            symbols.PutBack(current);
            return(null);
        }
        private void ParseProperties(SymbolList header)
        {
            ISymbolEnumerator headerSymbols = header.GetSymbolEnumerator();
            Symbol            temp          = headerSymbols.NextNonEOLSymbol();

            // Skip name
            temp = headerSymbols.NextNonEOLSymbol();
            temp.Expect(Symbol.ObjectType);

            _syntax      = ParseSyntax(Module, headerSymbols);
            _units       = ParseUnits(headerSymbols);
            _access      = ParseAccess(headerSymbols);
            _status      = ParseStatus(headerSymbols);
            _description = ParseDescription(headerSymbols);
            _reference   = ParseReference(headerSymbols);
            _indices     = ParseIndices(headerSymbols);
            _augments    = ParseAugments(headerSymbols);
            _defVal      = ParseDefVal(headerSymbols);
        }
Beispiel #24
0
        public TrapType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name = preAssignSymbols[0].ToString();

            Symbol valueSymbol = symbols.NextNonEOLSymbol();

            bool succeeded = int.TryParse(valueSymbol.ToString(), out _value);
            valueSymbol.Assert(succeeded, "not a decimal");
        }
        private static MaxAccess ParseAccess(ISymbolEnumerator symbols)
        {
            MaxAccess access = MaxAccess.notAccessible;

            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.MaxAccess, Symbol.Access);

            current = symbols.NextNonEOLSymbol();
            switch (current.ToString())
            {
            case "not-accessible":
                access = MaxAccess.notAccessible;
                break;

            case "accessible-for-notify":
                access = MaxAccess.accessibleForNotify;
                break;

            case "read-only":
                access = MaxAccess.readOnly;
                break;

            case "read-write":
                access = MaxAccess.readWrite;
                break;

            case "read-create":
                access = MaxAccess.readCreate;
                break;

            case "write-only":
                access = MaxAccess.readWrite;
                break;

            default:
                current.Assert(false, "Invalid/Unknown access");
                break;
            }

            return(access);
        }
        public TrapType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            _module = module;
            _name   = preAssignSymbols[0].ToString();

            Symbol valueSymbol = symbols.NextNonEOLSymbol();

            bool succeeded = int.TryParse(valueSymbol.ToString(), out _value);

            valueSymbol.Assert(succeeded, "not a decimal");
        }
Beispiel #27
0
        private void ParseEntities(ISymbolEnumerator symbols)
        {
            Symbol     temp   = symbols.NextNonEOLSymbol();
            SymbolList buffer = new SymbolList();

            while (temp != Symbol.End)
            {
                if (temp == Symbol.Assign)
                {
                    ParseEntity(buffer, symbols);
                    buffer.Clear();
                    // skip linebreaks behind an entity
                    temp = symbols.NextNonEOLSymbol();
                }
                else
                {
                    buffer.Add(temp);
                    temp = symbols.NextSymbol();
                }
            }
        }
Beispiel #28
0
 /// <summary>
 /// Creates a <see cref="Sequence" /> instance.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="name">The name.</param>
 /// <param name="symbols">The enumerator.</param>
 public Sequence(IModule module, string name, ISymbolEnumerator symbols)
     : base(module, name)
 {
     // parse between ( )
     Symbol temp = symbols.NextNonEOLSymbol();
     int bracketSection = 0;
     temp.Expect(Symbol.OpenBracket);
     bracketSection++;
     while (bracketSection > 0)
     {
         temp = symbols.NextNonEOLSymbol();
         if (temp == Symbol.OpenBracket)
         {
             bracketSection++;
         }
         else if (temp == Symbol.CloseBracket)
         {
             bracketSection--;
         }
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MibDocument"/> class.
        /// </summary>
        /// <param name="lexer">The lexer.</param>
        public MibDocument(Lexer lexer)
        {
            ISymbolEnumerator symbols = lexer.GetEnumerator();

            Symbol current;

            while ((current = symbols.NextNonEOLSymbol()) != null)
            {
                symbols.PutBack(current);
                _modules.Add(new MibModule(symbols));
            }
        }
        /// <summary>
        /// Creates a <see cref="Sequence" /> instance.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="symbols">The enumerator.</param>
        public Sequence(IModule module, string name, ISymbolEnumerator symbols)
            : base(module, name)
        {
            // parse between ( )
            Symbol temp           = symbols.NextNonEOLSymbol();
            int    bracketSection = 0;

            temp.Expect(Symbol.OpenBracket);
            bracketSection++;
            while (bracketSection > 0)
            {
                temp = symbols.NextNonEOLSymbol();
                if (temp == Symbol.OpenBracket)
                {
                    bracketSection++;
                }
                else if (temp == Symbol.CloseBracket)
                {
                    bracketSection--;
                }
            }
        }
Beispiel #31
0
        public MibModule(ISymbolEnumerator symbols)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException("lexer");
            }

            Symbol temp = symbols.NextNonEOLSymbol();

            temp.AssertIsValidIdentifier();
            _name = temp.ToString().ToUpperInvariant(); // all module names are uppercase

            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Definitions);

            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Assign);

            temp = symbols.NextSymbol();
            temp.Expect(Symbol.Begin);

            temp = symbols.NextNonEOLSymbol();
            if (temp == Symbol.Imports)
            {
                _imports = ParseDependents(symbols);
            }
            else if (temp == Symbol.Exports)
            {
                _exports = ParseExports(symbols);
            }
            else
            {
                symbols.PutBack(temp);
            }

            ParseEntities(symbols);
        }
Beispiel #32
0
        public MibModule(ISymbolEnumerator symbols)
        {
            if (symbols == null)
            {
                throw new ArgumentNullException("lexer");
            }

            Symbol temp = symbols.NextNonEOLSymbol();
            temp.AssertIsValidIdentifier();
            _name = temp.ToString().ToUpperInvariant(); // all module names are uppercase
            
            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Definitions);
            
            temp = symbols.NextNonEOLSymbol();
            temp.Expect(Symbol.Assign);
            
            temp = symbols.NextSymbol();
            temp.Expect(Symbol.Begin);
            
            temp = symbols.NextNonEOLSymbol();
            if (temp == Symbol.Imports)
            {
                _imports = ParseDependents(symbols);
            }
            else if (temp == Symbol.Exports)
            {
                _exports = ParseExports(symbols);
            }
            else
            {
                symbols.PutBack(temp);
            }

            ParseEntities(symbols);
        }
Beispiel #33
0
 public OctetStringType(IModule module, string name, ISymbolEnumerator symbols)
     : base(module, name)
 {
     Symbol current = symbols.NextNonEOLSymbol();
     if (current == Symbol.OpenParentheses)
     {
         symbols.PutBack(current);
         _size = Lexer.DecodeRanges(symbols);
         current.Assert(_size.IsSizeDeclaration, "SIZE keyword is required for ranges of octet string!");
     }
     else
     {
         symbols.PutBack(current);
         _size   = new ValueRanges(isSizeDecl: true);
     }
 }
        public OctetStringType(IModule module, string name, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.OpenParentheses)
            {
                symbols.PutBack(current);
                _size = Lexer.DecodeRanges(symbols);
                current.Assert(_size.IsSizeDeclaration, "SIZE keyword is required for ranges of octet string!");
            }
            else
            {
                symbols.PutBack(current);
                _size = new ValueRanges(isSizeDecl: true);
            }
        }
Beispiel #35
0
        public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Types? t = GetExactType(type);
            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            Symbol current = symbols.NextNonEOLSymbol();
            if (current == Symbol.OpenParentheses)
            {
                current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values

                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
Beispiel #36
0
        private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            current.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.
             */

            return(Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true));
        }
Beispiel #37
0
        public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols)
            : base(module, name)
        {
            Types?t = GetExactType(type);

            type.Assert(t.HasValue, "Unknown symbol for unsigned type!");
            _type = t.Value;

            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.OpenParentheses)
            {
                current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values

                symbols.PutBack(current);
                _ranges = Lexer.DecodeRanges(symbols);
                current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!");
            }
            else
            {
                symbols.PutBack(current);
            }
        }
Beispiel #38
0
        public static ValueMap DecodeEnumerations(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.OpenBracket);

            ValueMap map = new ValueMap();

            do
            {
                current = symbols.NextNonEOLSymbol();
                string identifier = current.ToString();

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenParentheses);

                current = symbols.NextNonEOLSymbol();
                Int64 enumValue;
                if (Int64.TryParse(current.ToString(), out enumValue))
                {
                    try
                    {
                        // Have to include the number as it seems repeated identifiers are allowed ??
                        map.Add(enumValue, String.Format("{0}({1})", identifier, enumValue));
                    }
                    catch (ArgumentException ex)
                    {
                        current.Assert(false, ex.Message);
                    }
                }
                else
                {
                    // Need to get "DefinedValue".
                }

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);

                current = symbols.NextNonEOLSymbol();
            } while (current == Symbol.Comma);

            current.Expect(Symbol.CloseBracket);

            return(map);
        }
Beispiel #39
0
        private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();
            current.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.
             */

            return Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true);
        }
Beispiel #40
0
        public static ITypeAssignment ParseBasicTypeDef(IModule module, string name, ISymbolEnumerator symbols, bool isMacroSyntax = false)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Bits)
            {
                return(new BitsType(module, name, symbols));
            }
            if (IntegerType.IsIntegerType(current))
            {
                return(new IntegerType(module, name, current, symbols));
            }
            if (UnsignedType.IsUnsignedType(current))
            {
                return(new UnsignedType(module, name, current, symbols));
            }
            if (current == Symbol.Opaque)
            {
                return(new OpaqueType(module, name, symbols));
            }
            if (current == Symbol.IpAddress)
            {
                return(new IpAddressType(module, name, symbols));
            }
            if (current == Symbol.TextualConvention)
            {
                return(new TextualConvention(module, name, symbols));
            }
            if (current == Symbol.Octet)
            {
                Symbol next = symbols.NextNonEOLSymbol();

                if (next == Symbol.String)
                {
                    return(new OctetStringType(module, name, symbols));
                }

                symbols.PutBack(next);
            }
            if (current == Symbol.Object)
            {
                Symbol next = symbols.NextNonEOLSymbol();

                if (next == Symbol.Identifier)
                {
                    return(new ObjectIdentifierType(module, name, symbols));
                }

                symbols.PutBack(next);
            }
            if (current == Symbol.Sequence)
            {
                Symbol next = symbols.NextNonEOLSymbol();

                if (next == Symbol.Of)
                {
                    return(new SequenceOf(module, name, symbols));
                }
                else
                {
                    symbols.PutBack(next);
                    return(new Sequence(module, name, symbols));
                }
            }
            if (current == Symbol.Choice)
            {
                return(new Choice(module, name, symbols));
            }


            return(new TypeAssignment(module, name, current, symbols, isMacroSyntax));
        }
Beispiel #41
0
        private void ParseEntities(ISymbolEnumerator symbols)
        {
            Symbol     temp   = symbols.NextNonEOLSymbol();
            SymbolList buffer = new SymbolList();

            while (temp != Symbol.End)
            {
                if (temp == Symbol.Assign)
                {
                    ParseEntity(buffer, symbols);
                    buffer.Clear();
                    // skip linebreaks behind an entity
                    temp = symbols.NextNonEOLSymbol();
                }
                else
                {
                    buffer.Add(temp);
                    temp = symbols.NextSymbol();
                }
            }
        }
Beispiel #42
0
        /// <summary>
        /// Creates an <see cref="TypeAssignment" />.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
        public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
        {
            _module = module;
            _name   = name;

            SymbolList typeSymbols = new SymbolList();
            typeSymbols.Add(type);

            Symbol current = symbols.NextSymbol();
            while (current != Symbol.EOL)
            {
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                    break;
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                    break;
                }

                typeSymbols.Add(current);
                current = symbols.NextSymbol();
            }

            _type = typeSymbols.Join(" ");

            if ((_ranges == null) && (_map == null))
            {
                current = symbols.NextNonEOLSymbol();
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                }
                else if (current != null)
                {
                    symbols.PutBack(current);
                }
            }

            if (isMacroSyntax)
            {
                // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
                return;
            }

            // outside macro Syntax clause we  wait for two consecutive linebreaks with a following valid identifier as end condition         
            Symbol previous = current;
            Symbol veryPrevious = null;

            while ((current = symbols.NextSymbol()) != null)
            {
                if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
                {
                    symbols.PutBack(current);
                    return;
                }

                veryPrevious = previous;
                previous = current;
            }
            
            previous.Assert(false, "end of file reached");
        }
Beispiel #43
0
        public static ValueRanges DecodeRanges(ISymbolEnumerator symbols)
        {
            ValueRanges result = new ValueRanges();

            Symbol startSymbol = symbols.NextNonEOLSymbol();
            Symbol current = startSymbol;
            current.Expect(Symbol.OpenParentheses);

            while (current != Symbol.CloseParentheses)
            {
                Symbol value1Symbol = symbols.NextNonEOLSymbol();

                if ((value1Symbol == Symbol.Size) && !result.IsSizeDeclaration)
                {
                    result.IsSizeDeclaration = true;
                    symbols.NextNonEOLSymbol().Expect(Symbol.OpenParentheses);
                    continue;
                }

                // check for valid number
                Int64? value1 = DecodeNumber(value1Symbol);
                if (!value1.HasValue)
                {
                    value1Symbol.Assert(false, "Invalid range declaration!");                    
                }

                // process next symbol
                ValueRange range;
                current = symbols.NextNonEOLSymbol();

                if (current == Symbol.DoubleDot)
                {
                    // its a continous range
                    Symbol value2Symbol = symbols.NextNonEOLSymbol();
                    Int64? value2 = DecodeNumber(value2Symbol);
                    value2Symbol.Assert(value2.HasValue && (value2.Value >= value1.Value), "Invalid range declaration!");

                    if (value2.Value == value1.Value)
                    {
                        range = new ValueRange(value1.Value, null);
                    }
                    else
                    {
                        range = new ValueRange(value1.Value, value2.Value);
                    }

                    current = symbols.NextNonEOLSymbol();
                }
                else
                {
                    // its a single number
                    range = new ValueRange(value1.Value, null);
                }

                // validate range
                if (result.IsSizeDeclaration)
                {
                    value1Symbol.Assert(range.Start >= 0, "Invalid range declaration! Size must be greater than 0");
                }

                result.Add(range);
                
                // check next symbol
                current.Expect(Symbol.Pipe, Symbol.CloseParentheses);
            }

            if (result.IsSizeDeclaration)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);
            }

            // validate ranges in between
            for (int i=0; i<result.Count; i++)
            {
                for (int k=i+1; k<result.Count; k++)
                {
                    startSymbol.Assert(!result[i].IntersectsWith(result[k]), "Invalid range declaration! Overlapping of ranges!");
                }
            }

            return result;
        }
Beispiel #44
0
        public static ITypeAssignment ParseBasicTypeDef(IModule module, string name, ISymbolEnumerator symbols, bool isMacroSyntax = false)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Bits)
            {
                return new BitsType(module, name, symbols);
            }
            if (IntegerType.IsIntegerType(current))
            {
                return new IntegerType(module, name, current, symbols);
            }
            if (UnsignedType.IsUnsignedType(current))
            {
                return new UnsignedType(module, name, current, symbols);
            }
            if (current == Symbol.Opaque)
            {
                return new OpaqueType(module, name, symbols);
            }
            if (current == Symbol.IpAddress)
            {
                return new IpAddressType(module, name, symbols);
            }
            if (current == Symbol.TextualConvention)
            {
                return new TextualConvention(module, name, symbols);
            }
            if (current == Symbol.Octet)
            {
                Symbol next = symbols.NextNonEOLSymbol();

                if (next == Symbol.String)
                {
                    return new OctetStringType(module, name, symbols);
                }

                symbols.PutBack(next);
            }
            if (current == Symbol.Object)
            {
                Symbol next = symbols.NextNonEOLSymbol();

                if (next == Symbol.Identifier)
                {
                    return new ObjectIdentifierType(module, name, symbols);
                }

                symbols.PutBack(next);
            }
            if (current == Symbol.Sequence)
            {
                Symbol next = symbols.NextNonEOLSymbol();

                if (next == Symbol.Of)
                {
                    return new SequenceOf(module, name, symbols);
                }
                else
                {
                    symbols.PutBack(next);
                    return new Sequence(module, name, symbols);
                }
            }
            if (current == Symbol.Choice)
            {
                return new Choice(module, name, symbols);
            }


            return new TypeAssignment(module, name, current, symbols, isMacroSyntax);
        }
Beispiel #45
0
        private static IList<string> ParseIndices(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Index)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenBracket);

                List<string> indices = new List<string>();

                while (current != Symbol.CloseBracket)
                {
                   current = symbols.NextNonEOLSymbol();
                   
                   bool lastIndex = false;
                    if (current == Symbol.Implied)
                    {
                        current = symbols.NextNonEOLSymbol();
                        lastIndex = true; // 'IMPLIED' may only be used for last index 
                    }

                    current.Assert((current != Symbol.Comma) && (current != Symbol.CloseBracket), "Expected index name but found symbol!");
                    indices.Add(current.ToString());

                    current = symbols.NextNonEOLSymbol();
                    if (lastIndex)
                    {
                       current.Expect(Symbol.CloseBracket);
                    }
                    else
                    {
                       current.Expect(Symbol.Comma, Symbol.CloseBracket);
                    }
                }

                return indices;
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return null;
        }
Beispiel #46
0
 public SequenceOf(IModule module, string name, ISymbolEnumerator sym)
     : base(module, name)
 {
     _type = sym.NextNonEOLSymbol().ToString();
 }
Beispiel #47
0
        private void ParseEntity(SymbolList preAssignSymbols, ISymbolEnumerator symbols)
        {
            if ((preAssignSymbols == null) || (preAssignSymbols.Count == 0))
            {
                Symbol s = symbols.NextSymbol();
                if (s != null)
                {
                    s.Assert(false, "Invalid Entity declaration");
                }
                else
                {
                    throw new MibException("Invalid Entity declaration");
                }
            }

            // check for a valid identifier
            preAssignSymbols[0].AssertIsValidIdentifier();

            if (preAssignSymbols.Count == 1)
            {
                // its a typedef
                _tokens.Add(Lexer.ParseBasicTypeDef(this, preAssignSymbols[0].ToString(), symbols, isMacroSyntax: false));
                return;
            }

            ISymbolEnumerator preAssignSymbolsEnumerator = preAssignSymbols.GetSymbolEnumerator();

            preAssignSymbolsEnumerator.NextNonEOLSymbol(); // returns identifier
            Symbol type = preAssignSymbolsEnumerator.NextNonEOLSymbol();

            // parse declarations
            if (type == Symbol.Object)
            {
                Symbol next = preAssignSymbolsEnumerator.NextNonEOLSymbol();

                if (next == Symbol.Identifier)
                {
                    _tokens.Add(new OidValueAssignment(this, preAssignSymbols, symbols));
                    return;
                }
                else if (next != null)
                {
                    preAssignSymbolsEnumerator.PutBack(next);
                }
            }
            if (type == Symbol.ModuleIdentity)
            {
                _tokens.Add(new ModuleIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectType)
            {
                _tokens.Add(new ObjectType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectGroup)
            {
                _tokens.Add(new ObjectGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationGroup)
            {
                _tokens.Add(new NotificationGroup(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ModuleCompliance)
            {
                _tokens.Add(new ModuleCompliance(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.NotificationType)
            {
                _tokens.Add(new NotificationType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.ObjectIdentity)
            {
                _tokens.Add(new ObjectIdentity(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.Macro)
            {
                _tokens.Add(new Macro(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.TrapType)
            {
                _tokens.Add(new TrapType(this, preAssignSymbols, symbols));
                return;
            }
            if (type == Symbol.AgentCapabilities)
            {
                _tokens.Add(new AgentCapabilities(this, preAssignSymbols, symbols));
                return;
            }

            preAssignSymbols[1].Assert(false, "Unknown/Invalid declaration");
        }
Beispiel #48
0
        private static string ParseDescription(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Description)
            {
                return symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' });
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return null;
        }
Beispiel #49
0
        private static MaxAccess ParseAccess(ISymbolEnumerator symbols)
        {
            MaxAccess access = MaxAccess.notAccessible;

            Symbol current = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.MaxAccess, Symbol.Access);

            current = symbols.NextNonEOLSymbol();
            switch (current.ToString())
            {
                case "not-accessible":
                    access = MaxAccess.notAccessible;
                    break;
                case "accessible-for-notify":
                    access = MaxAccess.accessibleForNotify;
                    break;
                case "read-only":
                    access = MaxAccess.readOnly;
                    break;
                case "read-write":
                    access = MaxAccess.readWrite;
                    break;
                case "read-create":
                    access = MaxAccess.readCreate;
                    break;
                case "write-only":
                    access = MaxAccess.readWrite;
                    break;
                default:
                    current.Assert(false, "Invalid/Unknown access");
                    break;
            }

            return access;
        }
Beispiel #50
0
        private static string ParseUnits(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();

            if (current == Symbol.Units)
            {
                return symbols.NextNonEOLSymbol().ToString();
            }
            else if (current != null)
            {
                symbols.PutBack(current);
            }

            return null;
        }
Beispiel #51
0
        private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.Syntax);

            return Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true);
        }
Beispiel #52
0
        public static void ParseOidValue(ISymbolEnumerator symbols, out string parent, out uint value)
        {
            parent = null;
            value = 0;
            
            Symbol current  = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.OpenBracket);

            Symbol previous = null;
            StringBuilder longParent = new StringBuilder();

            current = symbols.NextNonEOLSymbol();
            longParent.Append(current);

            while ((current = symbols.NextNonEOLSymbol()) != null)
            {
                bool succeeded;

                if (current == Symbol.OpenParentheses)
                {
                    longParent.Append(current);
                    
                    current = symbols.NextNonEOLSymbol();
                    succeeded = UInt32.TryParse(current.ToString(), out value);
                    current.Assert(succeeded, "not a decimal");
                    longParent.Append(current);
                    current = symbols.NextNonEOLSymbol();
                    current.Expect(Symbol.CloseParentheses);
                    longParent.Append(current);
                    continue;
                }

                if (current == Symbol.CloseBracket)
                {
                    parent = longParent.ToString();
                    return;
                }

                succeeded = UInt32.TryParse(current.ToString(), out value);
                if (succeeded)
                {
                    // numerical way
                    while ((current = symbols.NextNonEOLSymbol()) != Symbol.CloseBracket)
                    {
                        longParent.Append(".").Append(value);
                        succeeded = UInt32.TryParse(current.ToString(), out value);
                        current.Assert(succeeded, "not a decimal");
                    }

                    current.Expect(Symbol.CloseBracket);
                    parent = longParent.ToString();
                    return;
                }

                longParent.Append(".");
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenParentheses);
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                succeeded = UInt32.TryParse(current.ToString(), out value);
                current.Assert(succeeded, "not a decimal");
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);
                longParent.Append(current);
                previous = current;
            }

            throw MibException.Create("end of file reached", previous);
        }
Beispiel #53
0
        public static void ParseOidValue(ISymbolEnumerator symbols, out string parent, out uint value)
        {
            parent = null;
            value  = 0;

            Symbol current = symbols.NextNonEOLSymbol();

            current.Expect(Symbol.OpenBracket);

            Symbol        previous   = null;
            StringBuilder longParent = new StringBuilder();

            current = symbols.NextNonEOLSymbol();
            longParent.Append(current);

            while ((current = symbols.NextNonEOLSymbol()) != null)
            {
                bool succeeded;

                if (current == Symbol.OpenParentheses)
                {
                    longParent.Append(current);

                    current   = symbols.NextNonEOLSymbol();
                    succeeded = UInt32.TryParse(current.ToString(), out value);
                    current.Assert(succeeded, "not a decimal");
                    longParent.Append(current);
                    current = symbols.NextNonEOLSymbol();
                    current.Expect(Symbol.CloseParentheses);
                    longParent.Append(current);
                    continue;
                }

                if (current == Symbol.CloseBracket)
                {
                    parent = longParent.ToString();
                    return;
                }

                succeeded = UInt32.TryParse(current.ToString(), out value);
                if (succeeded)
                {
                    // numerical way
                    while ((current = symbols.NextNonEOLSymbol()) != Symbol.CloseBracket)
                    {
                        longParent.Append(".").Append(value);
                        succeeded = UInt32.TryParse(current.ToString(), out value);
                        current.Assert(succeeded, "not a decimal");
                    }

                    current.Expect(Symbol.CloseBracket);
                    parent = longParent.ToString();
                    return;
                }

                longParent.Append(".");
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenParentheses);
                longParent.Append(current);
                current   = symbols.NextNonEOLSymbol();
                succeeded = UInt32.TryParse(current.ToString(), out value);
                current.Assert(succeeded, "not a decimal");
                longParent.Append(current);
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);
                longParent.Append(current);
                previous = current;
            }

            throw MibException.Create("end of file reached", previous);
        }
Beispiel #54
0
        public static ValueMap DecodeEnumerations(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.OpenBracket);

            ValueMap map = new ValueMap();
            do
            {
                current = symbols.NextNonEOLSymbol();
                string identifier = current.ToString();

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenParentheses);

                current = symbols.NextNonEOLSymbol();
                Int64 enumValue;
                if (Int64.TryParse(current.ToString(), out enumValue))
                {
                    try
                    {
                        // Have to include the number as it seems repeated identifiers are allowed ??
                        map.Add(enumValue, String.Format("{0}({1})", identifier, enumValue));
                    }
                    catch (ArgumentException ex)
                    {
                        current.Assert(false, ex.Message);
                    }
                }
                else
                {
                    // Need to get "DefinedValue".
                }

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);

                current = symbols.NextNonEOLSymbol();
            } while (current == Symbol.Comma);

            current.Expect(Symbol.CloseBracket);

            return map;
        }
Beispiel #55
0
        public static ValueRanges DecodeRanges(ISymbolEnumerator symbols)
        {
            ValueRanges result = new ValueRanges();

            Symbol startSymbol = symbols.NextNonEOLSymbol();
            Symbol current     = startSymbol;

            current.Expect(Symbol.OpenParentheses);

            while (current != Symbol.CloseParentheses)
            {
                Symbol value1Symbol = symbols.NextNonEOLSymbol();

                if ((value1Symbol == Symbol.Size) && !result.IsSizeDeclaration)
                {
                    result.IsSizeDeclaration = true;
                    symbols.NextNonEOLSymbol().Expect(Symbol.OpenParentheses);
                    continue;
                }

                // check for valid number
                Int64?value1 = DecodeNumber(value1Symbol);
                if (!value1.HasValue)
                {
                    value1Symbol.Assert(false, "Invalid range declaration!");
                }

                // process next symbol
                ValueRange range;
                current = symbols.NextNonEOLSymbol();

                if (current == Symbol.DoubleDot)
                {
                    // its a continous range
                    Symbol value2Symbol = symbols.NextNonEOLSymbol();
                    Int64? value2       = DecodeNumber(value2Symbol);
                    value2Symbol.Assert(value2.HasValue && (value2.Value >= value1.Value), "Invalid range declaration!");

                    if (value2.Value == value1.Value)
                    {
                        range = new ValueRange(value1.Value, null);
                    }
                    else
                    {
                        range = new ValueRange(value1.Value, value2.Value);
                    }

                    current = symbols.NextNonEOLSymbol();
                }
                else
                {
                    // its a single number
                    range = new ValueRange(value1.Value, null);
                }

                // validate range
                if (result.IsSizeDeclaration)
                {
                    value1Symbol.Assert(range.Start >= 0, "Invalid range declaration! Size must be greater than 0");
                }

                result.Add(range);

                // check next symbol
                current.Expect(Symbol.Pipe, Symbol.CloseParentheses);
            }

            if (result.IsSizeDeclaration)
            {
                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);
            }

            // validate ranges in between
            for (int i = 0; i < result.Count; i++)
            {
                for (int k = i + 1; k < result.Count; k++)
                {
                    startSymbol.Assert(!result[i].IntersectsWith(result[k]), "Invalid range declaration! Overlapping of ranges!");
                }
            }

            return(result);
        }
Beispiel #56
0
        /// <summary>
        /// Creates an <see cref="TypeAssignment" />.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="type">The type.</param>
        /// <param name="symbols">The symbols.</param>
        /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
        public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
        {
            _module = module;
            _name   = name;

            SymbolList typeSymbols = new SymbolList();

            typeSymbols.Add(type);

            Symbol current = symbols.NextSymbol();

            while (current != Symbol.EOL)
            {
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                    break;
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                    break;
                }

                typeSymbols.Add(current);
                current = symbols.NextSymbol();
            }

            _type = typeSymbols.Join(" ");

            if ((_ranges == null) && (_map == null))
            {
                current = symbols.NextNonEOLSymbol();
                if (current == Symbol.OpenParentheses)
                {
                    // parse range of unknown type
                    symbols.PutBack(current);
                    _ranges = Lexer.DecodeRanges(symbols);
                }
                else if (current == Symbol.OpenBracket)
                {
                    symbols.PutBack(current);
                    _map = Lexer.DecodeEnumerations(symbols);
                }
                else if (current != null)
                {
                    symbols.PutBack(current);
                }
            }

            if (isMacroSyntax)
            {
                // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
                return;
            }

            // outside macro Syntax clause we  wait for two consecutive linebreaks with a following valid identifier as end condition
            Symbol previous     = current;
            Symbol veryPrevious = null;

            while ((current = symbols.NextSymbol()) != null)
            {
                if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
                {
                    symbols.PutBack(current);
                    return;
                }

                veryPrevious = previous;
                previous     = current;
            }

            previous.Assert(false, "end of file reached");
        }
 public SequenceOf(IModule module, string name, ISymbolEnumerator sym)
     : base(module, name)
 {
     _type = sym.NextNonEOLSymbol().ToString();
 }