1
/***************************************************************************
2
* Copyright (C) 2004 by Roberto Raggi *
3
* roberto@kdevelop.org *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU Library General Public License as *
7
* published by the Free Software Foundation; either version 2 of the *
8
* License, or (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public *
16
* License along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
30
typedef void (MILexer::*scan_fun_ptr)(int *kind);
42
TokenStream *tokenStream;
52
inline int lookAhead(int n = 0) const
53
{ return (m_currentToken + n)->kind; }
55
inline int currentToken() const
56
{ return m_currentToken->kind; }
58
inline QByteArray currentTokenText() const
59
{ return tokenText(-1); }
61
QByteArray tokenText(int index = 0) const;
63
inline int lineOffset(int line) const
64
{ return m_lines.at(line); }
66
void positionAt(int position, int *line, int *column) const;
68
inline void getTokenStartPosition(int index, int *line, int *column) const
69
{ positionAt((m_firstToken + index)->position, line, column); }
71
inline void getTokenEndPosition(int index, int *line, int *column) const
73
Token *tk = m_firstToken + index;
74
positionAt(tk->position + tk->length, line, column);
77
inline void rewind(int index)
78
{ m_currentToken = m_firstToken + index; }
80
inline int cursor() const
81
{ return m_currentToken - m_firstToken; }
83
inline void nextToken()
84
{ m_currentToken++; m_cursor++; }
87
QByteArray m_contents;
92
QVector<Token> m_tokens;
96
Token *m_currentToken;
107
TokenStream *tokenize(const FileSymbol *fileSymbol);
110
int nextToken(int &position, int &len);
112
void scanChar(int *kind);
113
void scanUnicodeChar(int *kind);
114
void scanNewline(int *kind);
115
void scanWhiteSpaces(int *kind);
116
void scanStringLiteral(int *kind);
117
void scanNumberLiteral(int *kind);
118
void scanIdentifier(int *kind);
120
void setupScanTable();
123
static bool s_initialized;
124
static scan_fun_ptr s_scan_table[128 + 1];
126
QByteArray m_contents;
128
// Cached 'm_contents.length()'
131
QVector<int> m_lines;
134
QVector<Token> m_tokens;
140
inline FileSymbol::~FileSymbol()