Beispiel #1
0
        public IToken Scan()
        {
            if (CharPosition == 1 && CurrentCharacter == '\'')
            {
                return(Add(EToken.StringLiteral, 1, Formula));
            }
            while (Advancable())
            {
                if (!CurrentCharacter.IsWhiteSpace())
                {
                    var start = CharPosition;
                    switch (CurrentCharacter)
                    {
                    case '!': return(Add(EToken.Bang, start, GetText(start)));

                    case '=': return(Add(EToken.EqualsOperator, start, GetText(start)));

                    case ',': return(Add(EToken.Comma, start, GetText(start)));

                    case ';': return(Add(EToken.Semicolon, start, GetText(start)));

                    case '+':
                    case '-':
                    case '%': return(Add(EToken.UnaryOperator, start, GetText(start)));

                    case '*':
                    case '/':
                    case '&':
                    case '^': return(Add(EToken.BinaryOperator, start, GetText(start)));

                    case '<':
                    case '>': if (IsEOT)
                        {
                            break;
                        }
                        if (NextCharacterIs('='))
                        {
                            CharPosition++;
                        }
                        return(Add(EToken.BinaryOperator, start, GetText(start)));

                    case '(': ParenDepth++; return(Add(EToken.OpenParen, start, GetText(start)));

                    case ')': ParenDepth--; return(Add(EToken.CloseParen, start, GetText(start)));

                    case '{': BraceDepth++; return(Add(EToken.OpenBrace, start, GetText(start)));

                    case '}': BraceDepth--; return(Add(EToken.CloseBrace, start, GetText(start)));

                    case '#': return(ScanErrorIdent(start));

                    case '"': return(ScanStringLiteral(start));

                    case '\'': return(ScanClosedExternalRef(start));

                    case '[': return(ScanOpenExternalRef(start));

                    default:
                        if (CurrentCharacter.IsNumeric())
                        {
                            return(ScanNumber(start));
                        }
                        if (CurrentCharacter.IsAlpha())
                        {
                            return(ScanIdentifier(start));
                        }
                        return(Add(EToken.ScanError, start, this));
                    }
                }
            }
            return(IsEOT ? Add(EToken.EOT, CharPosition, this)
                         : Add(EToken.ScanError, CharPosition, this));
        }