Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
     }
 }
        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);
        }
Esempio n. 5
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;
        }
        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);
            }
        }
        /// <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));
            }
        }
Esempio n. 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);
        }
Esempio n. 9
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;
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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);
            }
        }
        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);
        }
        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 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);
        }
Esempio n. 16
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;
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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);
        }
Esempio n. 20
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");
        }
Esempio n. 21
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);
        }
Esempio n. 22
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");
        }
Esempio n. 23
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");
        }
Esempio n. 24
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;
        }
Esempio n. 25
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;
        }
Esempio n. 26
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;
        }
Esempio n. 27
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;
        }
Esempio n. 28
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));
        }