source: trunk/src/script/parser/qscriptsyntaxchecker_p.h@ 561

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

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 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 QSCRIPTSYNTAXCHECKER_H
25#define QSCRIPTSYNTAXCHECKER_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.h>
39
40#include "qscriptgrammar_p.h"
41
42QT_BEGIN_NAMESPACE
43
44namespace QScript {
45
46class Lexer;
47
48class SyntaxChecker: protected QScriptGrammar
49{
50public:
51 enum State {
52 Error,
53 Intermediate,
54 Valid,
55 };
56
57 struct Result {
58 Result(State s, int ln, int col, const QString &msg)
59 : state(s), errorLineNumber(ln), errorColumnNumber(col),
60 errorMessage(msg) {}
61 State state;
62 int errorLineNumber;
63 int errorColumnNumber;
64 QString errorMessage;
65 };
66
67 SyntaxChecker();
68 ~SyntaxChecker();
69
70 Result checkSyntax(const QString &code);
71
72protected:
73 bool automatic(QScript::Lexer *lexer, int token) const;
74 inline void reallocateStack();
75
76protected:
77 int tos;
78 int stack_size;
79 int *state_stack;
80};
81
82inline void SyntaxChecker::reallocateStack()
83{
84 if (! stack_size)
85 stack_size = 128;
86 else
87 stack_size <<= 1;
88
89 state_stack = reinterpret_cast<int*> (qRealloc(state_stack, stack_size * sizeof(int)));
90}
91
92} // namespace QScript
93
94QT_END_NAMESPACE
95
96#endif
Note: See TracBrowser for help on using the repository browser.