Advance() public method

public Advance ( int count = 1 ) : void
count int
return void
Example #1
0
        private void ScanMultiLineString(LineProgress p)
        {
            p.StartNaturalText();

            while (!p.EndOfLine)
            {
                if (p.Char() == '"' && p.NextChar() == '"') // "" is allowed within multiline string.
                {
                    p.Advance(2);
                }
                else if (p.Char() == '"') // end of multi-line string
                {
                    p.EndNaturalText();

                    p.Advance();
                    p.State = State.Default;
                    return;
                }
                else
                {
                    p.Advance();
                }
            }

            // End of line.  Emit as human readable, but remain in MultiLineString state.
            p.EndNaturalText();
            Debug.Assert(p.State == State.MultiLineString);
        }
Example #2
0
        private void ScanString(LineProgress p)
        {
            p.StartNaturalText();

            while (!p.EndOfLine)
            {
                if (p.Char() == '\\') // escaped character.  Skip over it.
                {
                    p.Advance(2);
                }
                else if (p.Char() == '"') // end of string.
                {
                    p.EndNaturalText();
                    p.Advance();
                    p.State = State.Default;

                    return;
                }
                else
                {
                    p.Advance();
                }
            }

            // End of line.  String wasn't closed.  Oh well.  Revert to Default state.
            p.EndNaturalText();
            p.State = State.Default;
        }
Example #3
0
        private void ScanDocCommentXml(LineProgress p)
        {
            while (!p.EndOfLine)
            {
                if (p.Char() == '"')
                {
                    p.Advance(1);
                    p.State = State.DocCommentXmlString;
                    ScanDocCommentXmlString(p);
                }
                else if (p.Char() == '>')
                {
                    p.Advance();
                    p.State = State.DocComment;

                    return; // Done with xml tag in doc comment.
                }
                else
                {
                    p.Advance();
                }
            }

            // End of line.  Never found the '>' for the tag, but whatever.  We revert to default state.
            p.State = State.Default;
        }
Example #4
0
        private void ScanDocComment(LineProgress p)
        {
            p.StartNaturalText();
            while (!p.EndOfLine)
            {
                if (p.Char() == '<')
                {
                    p.EndNaturalText();

                    p.Advance();
                    p.State = State.DocCommentXml;
                    ScanDocCommentXml(p);

                    p.StartNaturalText();
                }
                else
                {
                    p.Advance();
                }
            }

            // End of line.  Record what we have and revert to default state.
            p.EndNaturalText();
            p.State = State.Default;
        }
Example #5
0
        private void ScanDocCommentXmlString(LineProgress p)
        {
            while (!p.EndOfLine)
            {
                if (p.Char() == '"')
                {
                    p.Advance(1);
                    p.State = State.DocCommentXml;

                    return; // Done with string in doc comment xml.
                }
                else
                {
                    p.Advance();
                }
            }

            // End of line.  Never found the '"' to close the string, but whatever.  We revert to default state.
            p.State = State.Default;
        }
Example #6
0
        private void ScanCharacter(LineProgress p)
        {
            if (!p.EndOfLine && p.Char() == '\\') // escaped character.  Eat it.
            {
                p.Advance(2);
            }
            else if (!p.EndOfLine && p.Char() != '\'') // non-escaped character.  Eat it.
            {
                p.Advance(1);
            }

            if (!p.EndOfLine && p.Char() == '\'') // closing ' for character, as expected.
            {
                p.Advance(1);
                p.State = State.Default;
                return;
            }

            // Didn't find closing ' for character.  Oh well.
            p.State = State.Default;
        }
Example #7
0
        private void ScanMultiLineComment(LineProgress p)
        {
            p.StartNaturalText();

            while (!p.EndOfLine)
            {
                if (p.Char() == '*' && p.NextChar() == '/') // close comment
                {
                    p.EndNaturalText();
                    p.Advance(2);
                    p.State = State.Default;

                    return; // done with multi-line comment.
                }
                else
                {
                    p.Advance();
                }
            }

            // End of line.  Emit as human readable, but remain in MultiLineComment state.
            p.EndNaturalText();
            Debug.Assert(p.State == State.MultiLineComment);
        }
Example #8
0
        private void ScanDefault(LineProgress p)
        {
            while (!p.EndOfLine)
            {
                if (p.Char() == '/' && p.NextChar() == '/' && p.NextNextChar() == '/') // doc comment.
                {
                    p.Advance(3);
                    p.State = State.DocComment;
                    ScanDocComment(p);
                }
                else if (p.Char() == '/' && p.NextChar() == '/') // single line comment
                {
                    p.Advance(2);
                    p.StartNaturalText();
                    p.AdvanceToEndOfLine();
                    p.EndNaturalText();

                    p.State = State.Default;
                    return;
                }
                else if (p.Char() == '/' && p.NextChar() == '*') // multi-line comment
                {
                    p.Advance(2);
                    p.State = State.MultiLineComment;
                    ScanMultiLineComment(p);
                }
                else if (p.Char() == '@' && p.NextChar() == '"') // multi-line string
                {
                    p.Advance(2);
                    p.State = State.MultiLineString;
                    ScanMultiLineString(p);
                }
                else if (p.Char() == '"') // single-line string
                {
                    p.Advance(1);
                    p.State = State.String;
                    ScanString(p);
                }
                else if (p.Char() == '\'') // character literal
                {
                    p.Advance(1);
                    p.State = State.Character;
                    ScanCharacter(p);
                }
                else
                {
                    p.Advance();
                }
            }
        }