1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
55 // This file is automatically generated from qmljs.g.
56 // Changes will be lost.
59 #ifndef QDECLARATIVEJSPARSER_P_H
60 #define QDECLARATIVEJSPARSER_P_H
62 #include "qdeclarativejsglobal_p.h"
63 #include "qdeclarativejsgrammar_p.h"
64 #include "qdeclarativejsast_p.h"
65 #include "qdeclarativejsengine_p.h"
67 #include <QtCore/QList>
68 #include <QtCore/QString>
70 QT_QML_BEGIN_NAMESPACE
72 namespace QDeclarativeJS {
76 class QML_PARSER_EXPORT Parser: protected QDeclarativeJSGrammar
82 AST::ArgumentList *ArgumentList;
83 AST::CaseBlock *CaseBlock;
84 AST::CaseClause *CaseClause;
85 AST::CaseClauses *CaseClauses;
87 AST::DefaultClause *DefaultClause;
88 AST::ElementList *ElementList;
89 AST::Elision *Elision;
90 AST::ExpressionNode *Expression;
91 AST::Finally *Finally;
92 AST::FormalParameterList *FormalParameterList;
93 AST::FunctionBody *FunctionBody;
94 AST::FunctionDeclaration *FunctionDeclaration;
96 AST::PropertyName *PropertyName;
97 AST::PropertyNameAndValueList *PropertyNameAndValueList;
98 AST::SourceElement *SourceElement;
99 AST::SourceElements *SourceElements;
100 AST::Statement *Statement;
101 AST::StatementList *StatementList;
103 AST::VariableDeclaration *VariableDeclaration;
104 AST::VariableDeclarationList *VariableDeclarationList;
106 AST::UiProgram *UiProgram;
107 AST::UiImportList *UiImportList;
108 AST::UiImport *UiImport;
109 AST::UiParameterList *UiParameterList;
110 AST::UiPublicMember *UiPublicMember;
111 AST::UiObjectDefinition *UiObjectDefinition;
112 AST::UiObjectInitializer *UiObjectInitializer;
113 AST::UiObjectBinding *UiObjectBinding;
114 AST::UiScriptBinding *UiScriptBinding;
115 AST::UiArrayBinding *UiArrayBinding;
116 AST::UiObjectMember *UiObjectMember;
117 AST::UiObjectMemberList *UiObjectMemberList;
118 AST::UiArrayMemberList *UiArrayMemberList;
119 AST::UiQualifiedId *UiQualifiedId;
123 Parser(Engine *engine);
126 // parse a UI program
127 bool parse() { return parse(T_FEED_UI_PROGRAM); }
128 bool parseStatement() { return parse(T_FEED_JS_STATEMENT); }
129 bool parseExpression() { return parse(T_FEED_JS_EXPRESSION); }
130 bool parseSourceElement() { return parse(T_FEED_JS_SOURCE_ELEMENT); }
131 bool parseUiObjectMember() { return parse(T_FEED_UI_OBJECT_MEMBER); }
132 bool parseProgram() { return parse(T_FEED_JS_PROGRAM); }
134 AST::UiProgram *ast() const
135 { return AST::cast<AST::UiProgram *>(program); }
137 AST::Statement *statement() const
142 return program->statementCast();
145 AST::ExpressionNode *expression() const
150 return program->expressionCast();
153 AST::UiObjectMember *uiObjectMember() const
158 return program->uiObjectMemberCast();
161 AST::Node *rootNode() const
164 QList<DiagnosticMessage> diagnosticMessages() const
165 { return diagnostic_messages; }
167 inline DiagnosticMessage diagnosticMessage() const
169 foreach (const DiagnosticMessage &d, diagnostic_messages) {
170 if (! d.kind == DiagnosticMessage::Warning)
174 return DiagnosticMessage();
177 inline QString errorMessage() const
178 { return diagnosticMessage().message; }
180 inline int errorLineNumber() const
181 { return diagnosticMessage().loc.startLine; }
183 inline int errorColumnNumber() const
184 { return diagnosticMessage().loc.startColumn; }
187 bool parse(int startToken);
189 void reallocateStack();
191 inline Value &sym(int index)
192 { return sym_stack [tos + index - 1]; }
194 inline QStringRef &stringRef(int index)
195 { return string_stack [tos + index - 1]; }
197 inline AST::SourceLocation &loc(int index)
198 { return location_stack [tos + index - 1]; }
200 AST::UiQualifiedId *reparseAsQualifiedId(AST::ExpressionNode *expr);
209 AST::SourceLocation *location_stack;
210 QStringRef *string_stack;
215 enum { TOKEN_BUFFER_SIZE = 3 };
220 AST::SourceLocation loc;
225 QStringRef yytokenspell;
226 AST::SourceLocation yylloc;
227 AST::SourceLocation yyprevlloc;
229 SavedToken token_buffer[TOKEN_BUFFER_SIZE];
230 SavedToken *first_token;
231 SavedToken *last_token;
233 QList<DiagnosticMessage> diagnostic_messages;
236 } // end of namespace QDeclarativeJS
240 #define J_SCRIPT_REGEXPLITERAL_RULE1 79
242 #define J_SCRIPT_REGEXPLITERAL_RULE2 80
248 #endif // QDECLARATIVEJSPARSER_P_H