source: trunk/src/script/parser/qscriptlexer_p.h@ 792

Last change on this file since 792 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtScript module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL-ONLY$
10** GNU Lesser General Public License Usage
11** This file may be used under the terms of the GNU Lesser
12** General Public License version 2.1 as published by the Free Software
13** Foundation and appearing in the file LICENSE.LGPL included in the
14** packaging of this file. Please review the following information to
15** ensure the GNU Lesser General Public License version 2.1 requirements
16** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17**
18** If you have questions regarding the use of this file, please contact
19** Nokia at [email protected].
20** $QT_END_LICENSE$
21**
22****************************************************************************/
23
24#ifndef QSCRIPTLEXER_P_H
25#define QSCRIPTLEXER_P_H
26
27//
28// W A R N I N G
29// -------------
30//
31// This file is not part of the Qt API. It exists purely as an
32// implementation detail. This header file may change from version to
33// version without notice, or even be removed.
34//
35// We mean it.
36//
37
38#include <QtCore/QString>
39
40QT_BEGIN_NAMESPACE
41
42class QScriptEnginePrivate;
43class QScriptNameIdImpl;
44
45namespace QScript {
46
47class Lexer
48{
49public:
50 Lexer(QScriptEnginePrivate *eng);
51 ~Lexer();
52
53 void setCode(const QString &c, int lineno);
54 int lex();
55
56 int currentLineNo() const { return yylineno; }
57 int currentColumnNo() const { return yycolumn; }
58
59 int startLineNo() const { return startlineno; }
60 int startColumnNo() const { return startcolumn; }
61
62 int endLineNo() const { return currentLineNo(); }
63 int endColumnNo() const
64 { int col = currentColumnNo(); return (col > 0) ? col - 1 : col; }
65
66 bool prevTerminator() const { return terminator; }
67
68 enum State { Start,
69 Identifier,
70 InIdentifier,
71 InSingleLineComment,
72 InMultiLineComment,
73 InNum,
74 InNum0,
75 InHex,
76 InOctal,
77 InDecimal,
78 InExponentIndicator,
79 InExponent,
80 Hex,
81 Octal,
82 Number,
83 String,
84 Eof,
85 InString,
86 InEscapeSequence,
87 InHexEscape,
88 InUnicodeEscape,
89 Other,
90 Bad };
91
92 enum Error {
93 NoError,
94 IllegalCharacter,
95 UnclosedStringLiteral,
96 IllegalEscapeSequence,
97 IllegalUnicodeEscapeSequence,
98 UnclosedComment,
99 IllegalExponentIndicator,
100 IllegalIdentifier
101 };
102
103 enum ParenthesesState {
104 IgnoreParentheses,
105 CountParentheses,
106 BalancedParentheses
107 };
108
109 enum RegExpBodyPrefix {
110 NoPrefix,
111 EqualPrefix
112 };
113
114 bool scanRegExp(RegExpBodyPrefix prefix = NoPrefix);
115
116 QScriptNameIdImpl *pattern;
117 int flags;
118
119 State lexerState() const
120 { return state; }
121
122 QString errorMessage() const
123 { return errmsg; }
124 void setErrorMessage(const QString &err)
125 { errmsg = err; }
126 void setErrorMessage(const char *err)
127 { setErrorMessage(QString::fromLatin1(err)); }
128
129 Error error() const
130 { return err; }
131 void clearError()