Exemple #1
0
        public void TestSeekOnANTLRInputStream()
        {
            Encoding encoding = Encoding.Unicode;

            byte[]       buffer        = encoding.GetBytes("One\r\nTwo\r\nThree");
            MemoryStream grammarStream = new MemoryStream(buffer);

            ANTLRInputStream stream = new ANTLRInputStream(grammarStream, encoding);

            Assert.AreEqual('O', stream.LA(1));
            Assert.AreEqual(0, stream.Index());
            Assert.AreEqual(0, stream.CharPositionInLine);
            Assert.AreEqual(1, stream.Line);

            stream.Seek(6);
            Assert.AreEqual('w', stream.LA(1));
            Assert.AreEqual(6, stream.Index());
            Assert.AreEqual(1, stream.CharPositionInLine);
            Assert.AreEqual(2, stream.Line);

            stream.Seek(11);
            Assert.AreEqual('h', stream.LA(1));
            Assert.AreEqual(11, stream.Index());
            Assert.AreEqual(1, stream.CharPositionInLine);
            Assert.AreEqual(3, stream.Line);

            // seeking backwards leaves state info (other than index in stream) unchanged
            stream.Seek(1);
            Assert.AreEqual('n', stream.LA(1));
            Assert.AreEqual(1, stream.Index());
            Assert.AreEqual(1, stream.CharPositionInLine);
            Assert.AreEqual(3, stream.Line);
        }
Exemple #2
0
        public void TestConsumeAllCharactersInAnANTLRInputStream()
        {
            Encoding encoding = Encoding.Unicode;

            byte[]       grammarStrBuffer = encoding.GetBytes(grammarStr);
            MemoryStream grammarStream    = new MemoryStream(grammarStrBuffer);

            ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode);

            while (inputStream.Index() < inputStream.Size())
            {
                Console.Out.Write((char)inputStream.LA(1));
                inputStream.Consume();
            }
            Assert.AreEqual(inputStream.Index(), inputStream.Size());
        }
Exemple #3
0
        public void TestResetOnANTLRInputStream()
        {
            Encoding encoding = Encoding.Unicode;

            byte[]       buffer        = encoding.GetBytes("One\r\nTwo");
            MemoryStream grammarStream = new MemoryStream(buffer);

            ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, encoding);

            Assert.AreEqual(0, inputStream.Index());
            Assert.AreEqual(0, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);

            inputStream.Consume();                      // O
            inputStream.Consume();                      // n

            Assert.AreEqual('e', inputStream.LA(1));
            Assert.AreEqual(2, inputStream.Index());

            inputStream.Reset();
            Assert.AreEqual('O', inputStream.LA(1));
            Assert.AreEqual(0, inputStream.Index());
            Assert.AreEqual(0, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);
            inputStream.Consume();                      // O

            Assert.AreEqual('n', inputStream.LA(1));
            Assert.AreEqual(1, inputStream.Index());
            Assert.AreEqual(1, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);
            inputStream.Consume();                      // n

            Assert.AreEqual('e', inputStream.LA(1));
            Assert.AreEqual(2, inputStream.Index());
            Assert.AreEqual(2, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);
            inputStream.Consume();                      // e
        }
Exemple #4
0
        public void TestConsumeAndIndexOnANTLRInputStream()
        {
            Encoding encoding = Encoding.Unicode;

            byte[]       grammarStrBuffer = encoding.GetBytes(grammarStr);
            MemoryStream grammarStream    = new MemoryStream(grammarStrBuffer);

            ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode);

            Assert.AreEqual(0, inputStream.Index());

            inputStream.Consume();
            Assert.AreEqual(1, inputStream.Index());

            inputStream.Consume();
            Assert.AreEqual(2, inputStream.Index());

            while (inputStream.Index() < inputStream.Size())
            {
                inputStream.Consume();
            }
            Assert.AreEqual(inputStream.Index(), inputStream.Size());
        }
Exemple #5
0
        public void TestConsumeOnANTLRInputStream()
        {
            Encoding encoding = Encoding.Unicode;

            byte[]       buffer        = encoding.GetBytes("One\r\nTwo");
            MemoryStream grammarStream = new MemoryStream(buffer);

            ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode);

            Assert.AreEqual(0, inputStream.Index());
            Assert.AreEqual(0, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);

            inputStream.Consume();                      // O
            Assert.AreEqual(1, inputStream.Index());
            Assert.AreEqual(1, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);

            inputStream.Consume();                      // n
            Assert.AreEqual(2, inputStream.Index());
            Assert.AreEqual(2, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);

            inputStream.Consume();                      // e
            Assert.AreEqual(3, inputStream.Index());
            Assert.AreEqual(3, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);

            inputStream.Consume();                      // \r
            Assert.AreEqual(4, inputStream.Index());
            Assert.AreEqual(4, inputStream.CharPositionInLine);
            Assert.AreEqual(1, inputStream.Line);

            inputStream.Consume();                      // \n
            Assert.AreEqual(5, inputStream.Index());
            Assert.AreEqual(0, inputStream.CharPositionInLine);
            Assert.AreEqual(2, inputStream.Line);

            inputStream.Consume();                      // T
            Assert.AreEqual(6, inputStream.Index());
            Assert.AreEqual(1, inputStream.CharPositionInLine);
            Assert.AreEqual(2, inputStream.Line);

            inputStream.Consume();                      // w
            Assert.AreEqual(7, inputStream.Index());
            Assert.AreEqual(2, inputStream.CharPositionInLine);
            Assert.AreEqual(2, inputStream.Line);

            inputStream.Consume();                      // o
            Assert.AreEqual(8, inputStream.Index());
            Assert.AreEqual(3, inputStream.CharPositionInLine);
            Assert.AreEqual(2, inputStream.Line);

            inputStream.Consume();                      // EOF
            Assert.AreEqual(8, inputStream.Index());
            Assert.AreEqual(3, inputStream.CharPositionInLine);
            Assert.AreEqual(2, inputStream.Line);

            inputStream.Consume();                      // EOF
            Assert.AreEqual(8, inputStream.Index());
            Assert.AreEqual(3, inputStream.CharPositionInLine);
            Assert.AreEqual(2, inputStream.Line);
        }
		public void TestConsumeAndIndexOnANTLRInputStream()
		{
			Encoding encoding = Encoding.Unicode;
			byte[] grammarStrBuffer = encoding.GetBytes(grammarStr);
			MemoryStream grammarStream = new MemoryStream(grammarStrBuffer);

			ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode);
			Assert.AreEqual(0, inputStream.Index());

			inputStream.Consume();
			Assert.AreEqual(1, inputStream.Index());

			inputStream.Consume();
			Assert.AreEqual(2, inputStream.Index());

			while (inputStream.Index() < inputStream.Size())
			{
				inputStream.Consume();
			}
			Assert.AreEqual(inputStream.Index(), inputStream.Size());
		}
		public void TestSeekOnANTLRInputStream()
		{
			Encoding encoding = Encoding.Unicode;
			byte[] buffer = encoding.GetBytes("One\r\nTwo\r\nThree");
			MemoryStream grammarStream = new MemoryStream(buffer);

			ANTLRInputStream stream = new ANTLRInputStream(grammarStream, encoding);
			Assert.AreEqual('O', stream.LA(1));
			Assert.AreEqual(0, stream.Index());
			Assert.AreEqual(0, stream.CharPositionInLine);
			Assert.AreEqual(1, stream.Line);

			stream.Seek(6);
			Assert.AreEqual('w', stream.LA(1));
			Assert.AreEqual(6, stream.Index());
			Assert.AreEqual(1, stream.CharPositionInLine);
			Assert.AreEqual(2, stream.Line);

			stream.Seek(11);
			Assert.AreEqual('h', stream.LA(1));
			Assert.AreEqual(11, stream.Index());
			Assert.AreEqual(1, stream.CharPositionInLine);
			Assert.AreEqual(3, stream.Line);

			// seeking backwards leaves state info (other than index in stream) unchanged
			stream.Seek(1);
			Assert.AreEqual('n', stream.LA(1));
			Assert.AreEqual(1, stream.Index());
			Assert.AreEqual(1, stream.CharPositionInLine);
			Assert.AreEqual(3, stream.Line);
		}
		public void TestResetOnANTLRInputStream()
		{
			Encoding encoding = Encoding.Unicode;
			byte[] buffer = encoding.GetBytes("One\r\nTwo");
			MemoryStream grammarStream = new MemoryStream(buffer);

			ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, encoding);
			Assert.AreEqual(0, inputStream.Index());
			Assert.AreEqual(0, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);

			inputStream.Consume();		// O
			inputStream.Consume();		// n

			Assert.AreEqual('e', inputStream.LA(1));
			Assert.AreEqual(2, inputStream.Index());

			inputStream.Reset();
			Assert.AreEqual('O', inputStream.LA(1));
			Assert.AreEqual(0, inputStream.Index());
			Assert.AreEqual(0, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);
			inputStream.Consume();		// O

			Assert.AreEqual('n', inputStream.LA(1));
			Assert.AreEqual(1, inputStream.Index());
			Assert.AreEqual(1, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);
			inputStream.Consume();		// n

			Assert.AreEqual('e', inputStream.LA(1));
			Assert.AreEqual(2, inputStream.Index());
			Assert.AreEqual(2, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);
			inputStream.Consume();		// e
		}
		public void TestConsumeOnANTLRInputStream()
		{
			Encoding encoding = Encoding.Unicode;
			byte[] buffer = encoding.GetBytes("One\r\nTwo");
			MemoryStream grammarStream = new MemoryStream(buffer);

			ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode);
			Assert.AreEqual(0, inputStream.Index());
			Assert.AreEqual(0, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);

			inputStream.Consume();		// O
			Assert.AreEqual(1, inputStream.Index());
			Assert.AreEqual(1, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);

			inputStream.Consume();		// n
			Assert.AreEqual(2, inputStream.Index());
			Assert.AreEqual(2, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);

			inputStream.Consume();		// e
			Assert.AreEqual(3, inputStream.Index());
			Assert.AreEqual(3, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);

			inputStream.Consume();		// \r
			Assert.AreEqual(4, inputStream.Index());
			Assert.AreEqual(4, inputStream.CharPositionInLine);
			Assert.AreEqual(1, inputStream.Line);

			inputStream.Consume();		// \n
			Assert.AreEqual(5, inputStream.Index());
			Assert.AreEqual(0, inputStream.CharPositionInLine);
			Assert.AreEqual(2, inputStream.Line);

			inputStream.Consume();		// T
			Assert.AreEqual(6, inputStream.Index());
			Assert.AreEqual(1, inputStream.CharPositionInLine);
			Assert.AreEqual(2, inputStream.Line);

			inputStream.Consume();		// w
			Assert.AreEqual(7, inputStream.Index());
			Assert.AreEqual(2, inputStream.CharPositionInLine);
			Assert.AreEqual(2, inputStream.Line);

			inputStream.Consume();		// o
			Assert.AreEqual(8, inputStream.Index());
			Assert.AreEqual(3, inputStream.CharPositionInLine);
			Assert.AreEqual(2, inputStream.Line);

			inputStream.Consume();		// EOF
			Assert.AreEqual(8, inputStream.Index());
			Assert.AreEqual(3, inputStream.CharPositionInLine);
			Assert.AreEqual(2, inputStream.Line);

			inputStream.Consume();		// EOF
			Assert.AreEqual(8, inputStream.Index());
			Assert.AreEqual(3, inputStream.CharPositionInLine);
			Assert.AreEqual(2, inputStream.Line);
		}
		public void TestConsumeAllCharactersInAnANTLRInputStream()
		{
			Encoding encoding = Encoding.Unicode;
			byte[] grammarStrBuffer = encoding.GetBytes(grammarStr);
			MemoryStream grammarStream = new MemoryStream(grammarStrBuffer);

			ANTLRInputStream inputStream = new ANTLRInputStream(grammarStream, Encoding.Unicode);
			while (inputStream.Index() < inputStream.Size())
			{
				Console.Out.Write((char)inputStream.LA(1));
				inputStream.Consume();
			}
			Assert.AreEqual(inputStream.Index(), inputStream.Size());
		}