Пример #1
0
        private Token NextToken()
        {
            clutter = current;

            nl = Skip();

            while (true)
            {
                payload = current;

                Debug.Assert(current <= limit);
                if (current == limit)
                {
                    return(Token(TK.Eof));
                }

                switch (Current)
                {
                case '"':
                    return(String());

                case '\'':
                    return(Char());

                case '(':
                    current += 1;
                    return(Token(TK.LParen));

                case ')':
                    current += 1;
                    return(Token(TK.RParen));

                case '[':
                    current += 1;
                    return(Token(TK.LSquare));

                case ']':
                    current += 1;
                    return(Token(TK.RSquare));

                case '{':
                    current += 1;
                    return(Token(TK.LBrace));

                case '}':
                    current += 1;
                    return(Token(TK.RBrace));

                case ',':
                    current += 1;
                    return(Token(TK.Comma));

                case '~':
                    current += 1;
                    return(Token(TK.Tilde));

                case ':':
                    current += 1;
                    return(Token(TK.Colon));

                case ';':
                    current += 1;
                    return(Token(TK.Semi));

                case '?':
                    current += 1;
                    return(Token(TK.Question));

                case '|':
                    current += 1;
                    return(Token(TK.Pipe));

                case '^':
                    current += 1;
                    return(Token(TK.Hat));

                case '&':
                    current += 1;
                    return(Token(TK.Amper));

                case '.':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == '>')
                        {
                            current += 1;
                            return(Token(TK.Chain));
                        }
                        if (Current == '.' && current + 1 < limit && Next == '.')
                        {
                            current += 2;
                            return(Token(TK.Ellipsis));
                        }
                    }
                    return(Token(TK.Dot));

                case '@':
                    current += 1;
                    if (current < limit && Current == '{')
                    {
                        current += 1;
                        return(Token(TK.AtLBrace));
                    }
                    return(Token(TK.At));

                case '+':
                    current += 1;
                    return(Token(TK.Plus));

                case '-':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == '>')
                        {
                            current += 1;
                            return(Token(TK.Arrow));
                        }
                    }
                    return(Token(TK.Minus));

                case '/':
                    current += 1;
                    return(Token(TK.Divide));

                case '*':
                    current += 1;
                    return(Token(TK.Multiply));

                case '%':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == '%')
                        {
                            current += 1;
                            return(Token(TK.Mod));
                        }
                    }
                    return(Token(TK.Rem));

                case '=':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == '>')
                        {
                            current += 1;
                            return(Token(TK.DblArrow));
                        }
                        else if (Current == '=')
                        {
                            current += 1;
                            return(Token(TK.Eq));
                        }
                    }
                    return(Token(TK.Assign));

                case '!':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == '=')
                        {
                            current += 1;
                            return(Token(TK.Ne));
                        }
                    }
                    return(Token(TK.Exclamation));

                case '<':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == ':')
                        {
                            current += 1;
                            return(Token(TK.Subtype));
                        }
                        if (Current == '=')
                        {
                            current += 1;
                            return(Token(TK.Le));
                        }
                        if (Current == '<')
                        {
                            current += 1;
                            return(Token(TK.LShift));
                        }
                    }
                    return(Token(TK.Lt));

                case '>':
                    current += 1;
                    if (current < limit)
                    {
                        if (Current == '=')
                        {
                            current += 1;
                            return(Token(TK.Ge));
                        }
                    }
                    return(Token(TK.Gt));

                default:
                    if (Current.IsLetterOrUnderscore())
                    {
                        return(IdentifierOrKeyword());
                    }
                    if (Current.IsDigit())
                    {
                        return(Number());
                    }
                    break;
                }

                Errors.AtOffset(ErrNo.Lex001, Source, current, $"unknown character ``{CharRep.InText(Current)}´´ in source stream");
                current += 1;

                nl = Skip() || nl;
            }
        }