Esempio n. 1
0
        public override Lexem ReadNextLexem(SourceCodeIterator iterator)
        {
            if (iterator.CurrentSymbol == '<')
            {
                char next = iterator.PeekNext();

                if (next == '>' || next == '=')
                {
                    iterator.MoveNext();
                    iterator.MoveNext();
                    return(ExtractOperatorContent(iterator));
                }
            }
            else if (iterator.CurrentSymbol == '>')
            {
                char next = iterator.PeekNext();

                if (next == '=')
                {
                    iterator.MoveNext();
                    iterator.MoveNext();
                    return(ExtractOperatorContent(iterator));
                }
            }

            var lex = ExtractOperatorContent(iterator);

            iterator.MoveNext();

            return(lex);
        }
Esempio n. 2
0
        public void SourceCode_Iterator_Basics()
        {
            string code     = "Б = 1;";
            var    iterator = new SourceCodeIterator(code);

            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == '\0');
            Assert.True(iterator.PeekNext() == 'Б');

            Assert.True(iterator.MoveNext());
            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == 'Б');
            Assert.True(iterator.PeekNext() == ' ');
            Assert.True(iterator.Position == 0);

            Assert.True(iterator.MoveNext());
            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == ' ');
            Assert.True(iterator.PeekNext() == '=');
            Assert.True(iterator.Position == 1);

            Assert.True(iterator.MoveNext());
            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == '=');
            Assert.True(iterator.PeekNext() == ' ');
            Assert.True(iterator.Position == 2);

            Assert.True(iterator.MoveNext());
            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == ' ');
            Assert.True(iterator.PeekNext() == '1');
            Assert.True(iterator.Position == 3);

            Assert.True(iterator.MoveNext());
            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == '1');
            Assert.True(iterator.PeekNext() == ';');
            Assert.True(iterator.Position == 4);

            Assert.True(iterator.MoveNext());
            Assert.True(iterator.CurrentLine == 1);
            Assert.True(iterator.CurrentSymbol == ';');
            Assert.True(iterator.PeekNext() == '\0');
            Assert.True(iterator.Position == 5);

            Assert.False(iterator.MoveNext());
            Assert.True(iterator.CurrentSymbol == '\0');
            Assert.True(iterator.PeekNext() == '\0');
        }