author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 29 Apr 2010 15:15:16 +0300 | |
branch | RCL_3 |
changeset 16 | 4b6ee5efea19 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the utils of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef RE2NFA_H |
|
43 |
#define RE2NFA_H |
|
44 |
||
45 |
#include "nfa.h" |
|
46 |
#include <QSet> |
|
47 |
||
48 |
class RE2NFA |
|
49 |
{ |
|
50 |
public: |
|
51 |
RE2NFA(const QMap<QString, NFA> ¯os, const QSet<InputType> &maxInputSet, Qt::CaseSensitivity cs); |
|
52 |
||
53 |
NFA parse(const QString &expression, int *errorColumn = 0); |
|
54 |
||
55 |
private: |
|
56 |
NFA parseExpr(); |
|
57 |
NFA parseBranch(); |
|
58 |
NFA parsePiece(); |
|
59 |
NFA parseAtom(); |
|
60 |
NFA parseMaybeQuantifier(const NFA &nfa); |
|
61 |
NFA parseSet(); |
|
62 |
NFA parseSet2(); |
|
63 |
||
64 |
NFA createCharNFA(); |
|
65 |
||
66 |
private: |
|
67 |
friend class RegExpTokenizer; |
|
68 |
||
69 |
enum Token { |
|
70 |
TOK_INVALID, |
|
71 |
TOK_STRING, |
|
72 |
TOK_LBRACE, // { |
|
73 |
TOK_RBRACE, // } |
|
74 |
TOK_LBRACKET, // [ |
|
75 |
TOK_RBRACKET, // ] |
|
76 |
TOK_LPAREN, // ( |
|
77 |
TOK_RPAREN, // ) |
|
78 |
TOK_COMMA, |
|
79 |
TOK_STAR, |
|
80 |
TOK_OR, |
|
81 |
TOK_QUESTION, |
|
82 |
TOK_DOT, |
|
83 |
TOK_PLUS, |
|
84 |
TOK_SEQUENCE, |
|
85 |
TOK_QUOTED_STRING |
|
86 |
}; |
|
87 |
||
88 |
struct Symbol |
|
89 |
{ |
|
90 |
inline Symbol() : token(TOK_INVALID), column(-1) {} |
|
91 |
inline Symbol(Token t, const QString &l = QString()) : token(t), lexem(l), column(-1) {} |
|
92 |
Token token; |
|
93 |
QString lexem; |
|
94 |
int column; |
|
95 |
}; |
|
96 |
||
97 |
inline bool hasNext() const { return index < symbols.count(); } |
|
98 |
inline Token next() { return symbols.at(index++).token; } |
|
99 |
bool next(Token t); |
|
100 |
bool test(Token t); |
|
101 |
inline void prev() { index--; } |
|
102 |
inline const Symbol &symbol() const { return symbols.at(index - 1); } |
|
103 |
QString lexemUntil(Token t); |
|
104 |
||
105 |
void tokenize(const QString &input); |
|
106 |
||
107 |
QMap<QString, NFA> macros; |
|
108 |
QVector<Symbol> symbols; |
|
109 |
int index; |
|
110 |
int errorColumn; |
|
111 |
const QSet<InputType> maxInputSet; |
|
112 |
Qt::CaseSensitivity caseSensitivity; |
|
113 |
}; |
|
114 |
||
115 |
#endif // RE2NFA_H |
|
116 |