示例#1
0
        public bool ReadNextToken(out LexerResult lexerResult)
        {
            int character = ReadNextChar();

            if (character == -1)
            {
                lexerResult = new LexerResult(null, TokenType.EndOfStream);
                return false;
            }

            if (IsSpaceChar(character))
            {
                while (IsSpaceChar(PeekNextChar()))
                {
                    character = ReadNextChar();
                }

                lexerResult = new LexerResult(" ", TokenType.Space);
                return true;
            }

            return AnalyzeChar(character, out lexerResult);
        }
示例#2
0
        private bool AnalyzeChar(int character, out LexerResult lexerResult)
        {
            if (character == '{')
            {
                _inTemplate = true;

                lexerResult = new LexerResult("{", TokenType.LeftBrace);
                return true;
            }
            else if (character == '}')
            {
                _inTemplate = false;

                lexerResult = new LexerResult("}", TokenType.RightBrace);
                return true;
            }
            else if (character == '.')
            {
                lexerResult = new LexerResult(".", TokenType.Point);
                return true;
            }
            else if (character == ':')
            {
                lexerResult = new LexerResult(":", TokenType.Colon);
                return true;
            }
            else if (character == '\"')
            {
                lexerResult = new LexerResult("\"", TokenType.Quotes);
                return true;
            }
            else if (_inTemplate && IsSpecialChar(character))
            {
                lexerResult = new LexerResult(((char)character).ToString(), TokenType.SpecialSymbol);
                return true;
            }
            else if (IsPunctuationChar(character))
            {
                lexerResult = new LexerResult(((char)character).ToString(), TokenType.Punctuation);
                return true;
            }
            else if (char.IsLetter((char)character))
            {
                lexerResult = new LexerResult(((char)character).ToString(), TokenType.Letter);
                return true;
            }
            else if (char.IsDigit((char)character))
            {
                lexerResult = new LexerResult(((char)character).ToString(), TokenType.Digit);
                return true;
            }

            lexerResult = null;
            RaiseLexerException(character);
            return false;
        }