Example #1
0
        public void TestRanges()
        {
            const string test = "SomeEnum ::= OCTET STRING ( SIZE (5 | 8 .. 20 | 31 .. 60 ))";
            Lexer lexer = new Lexer();
            StringReader reader = new StringReader(test);
            lexer.Parse(reader);
            string name = lexer.GetNextSymbol().ToString();
            lexer.GetNextSymbol().Expect(Symbol.Assign);
            lexer.GetNextSymbol().Expect(Symbol.Octet);
            lexer.GetNextSymbol().Expect(Symbol.String);

            OctetStringType i = new OctetStringType("module", "name", lexer);
            Assert.IsTrue(i.Contains(8));
            Assert.IsTrue(i.Contains(5));
            Assert.IsTrue(i.Contains(15));
            Assert.IsTrue(i.Contains(20));
            Assert.IsTrue(i.Contains(35));
            Assert.IsFalse(i.Contains(4));
            Assert.IsFalse(i.Contains(-9));
            Assert.IsFalse(i.Contains(25));
            Assert.IsFalse(i.Contains(61));
        }
Example #2
0
        private static ITypeAssignment ParseSyntax(string module, string name, IEnumerator <Symbol> enumerator, ref Symbol temp)
        {
            ITypeAssignment syntax;

            temp.Expect(Symbol.Syntax);
            temp = enumerator.NextNonEOLSymbol();

            if (temp == Symbol.Bits)
            {
                syntax = new BitsType(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                syntax = new IntegerType(module, name, enumerator, ref temp);
            }
            else if (temp == Symbol.Octet)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.String);
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Opaque)
            {
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.IpAddress)
            {
                syntax = new IpAddressType(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Counter64)
            {
                syntax = new Counter64Type(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                syntax = new UnsignedType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Object)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.Identifier);
                syntax = new ObjectIdentifierType(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Sequence)
            {
                temp = enumerator.NextNonEOLSymbol();

                if (temp == Symbol.Of)
                {
                    temp   = enumerator.NextNonEOLSymbol();
                    syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
                }
                else
                {
                    syntax = new Sequence(string.Empty, string.Empty, enumerator);
                    temp   = enumerator.NextNonEOLSymbol();
                }
            }
            else
            {
                syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
            }

            return(syntax);
        }
Example #3
0
        private static ITypeAssignment ParseSyntax(string module, string name, IEnumerator<Symbol> enumerator, ref Symbol temp)
        {
            ITypeAssignment syntax;

            temp.Expect(Symbol.Syntax);
            temp = enumerator.NextNonEOLSymbol();

            if (temp == Symbol.Bits)
            {
                syntax = new BitsType(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                syntax = new IntegerType(module, name, enumerator, ref temp);
            }
            else if (temp == Symbol.Octet)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.String);
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Opaque)
            {
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.IpAddress)
            {
                syntax = new IpAddressType(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Counter64)
            {
                syntax = new Counter64Type(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                syntax = new UnsignedType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Object)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.Identifier);
                syntax = new ObjectIdentifierType(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Sequence)
            {
                temp = enumerator.NextNonEOLSymbol();

                if (temp == Symbol.Of)
                {
                    temp = enumerator.NextNonEOLSymbol();
                    syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
                }
                else
                {
                    syntax = new Sequence(string.Empty, string.Empty, enumerator);
                    temp = enumerator.NextNonEOLSymbol();
                }
            }
            else
            {
                syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
            }

            return syntax;
        }