1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | //
|
---|
43 | // W A R N I N G
|
---|
44 | // -------------
|
---|
45 | //
|
---|
46 | // This file is not part of the Qt API. It exists purely as an
|
---|
47 | // implementation detail. This header file may change from version to
|
---|
48 | // version without notice, or even be removed.
|
---|
49 | //
|
---|
50 | // We mean it.
|
---|
51 |
|
---|
52 | #ifndef Patternist_XSLTTokenizer_H
|
---|
53 | #define Patternist_XSLTTokenizer_H
|
---|
54 |
|
---|
55 | #include <QQueue>
|
---|
56 | #include <QStack>
|
---|
57 | #include <QUrl>
|
---|
58 |
|
---|
59 | #include "qmaintainingreader_p.h"
|
---|
60 | #include "qreportcontext_p.h"
|
---|
61 | #include "qtokenizer_p.h"
|
---|
62 | #include "qxslttokenlookup_p.h"
|
---|
63 |
|
---|
64 | QT_BEGIN_HEADER
|
---|
65 |
|
---|
66 | QT_BEGIN_NAMESPACE
|
---|
67 |
|
---|
68 | namespace QPatternist
|
---|
69 | {
|
---|
70 | /**
|
---|
71 | * @short A TokenSource which contains one Tokenizer::Token.
|
---|
72 | *
|
---|
73 | * One possible way to optimize this is to let SingleTokenContainer
|
---|
74 | * actually contain a list of tokens, such that XSLTTokenizer::queueToken()
|
---|
75 | * could append to that, instead of instansiating a SingleTokenContainer
|
---|
76 | * all the time.
|
---|
77 | *
|
---|
78 | * @author Frans Englich <[email protected]>
|
---|
79 | */
|
---|
80 | class SingleTokenContainer : public TokenSource
|
---|
81 | {
|
---|
82 | public:
|
---|
83 | inline SingleTokenContainer(const Tokenizer::Token &token,
|
---|
84 | const YYLTYPE &location);
|
---|
85 |
|
---|
86 | virtual Tokenizer::Token nextToken(YYLTYPE *const sourceLocator);
|
---|
87 | private:
|
---|
88 | const Tokenizer::Token m_token;
|
---|
89 | const YYLTYPE m_location;
|
---|
90 | bool m_hasDelivered;
|
---|
91 | };
|
---|
92 |
|
---|
93 | SingleTokenContainer::SingleTokenContainer(const Tokenizer::Token &token,
|
---|
94 | const YYLTYPE &location) : m_token(token)
|
---|
95 | , m_location(location)
|
---|
96 | , m_hasDelivered(false)
|
---|
97 | {
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * @short Tokenizes XSL-T 2.0 documents.
|
---|
102 | *
|
---|
103 | * XSLTTokenizer takes in its constructor a pointer to a QIODevice which is
|
---|
104 | * supposed to contain an XSL-T document. XSLTTokenizer then rewrites that
|
---|
105 | * document into XQuery tokens delivered via nextToken(), which the regular
|
---|
106 | * XQuery parser then reads. Hence, the XSL-T language is rewritten into
|
---|
107 | * XQuery code, slightly extended to handle the featuress specific to
|
---|
108 | * XSL-T.
|
---|
109 | *
|
---|
110 | * @author Frans Englich <[email protected]>
|
---|
111 | */
|
---|
112 | class XSLTTokenizer : public Tokenizer
|
---|
113 | , private MaintainingReader<XSLTTokenLookup>
|
---|
114 | {
|
---|
115 | public:
|
---|
116 | /**
|
---|
117 | * XSLTTokenizer do not own @p queryDevice.
|
---|
118 | */
|
---|
119 | XSLTTokenizer(QIODevice *const queryDevice,
|
---|
120 | const QUrl &location,
|
---|
121 | const ReportContext::Ptr &context,
|
---|
122 | const NamePool::Ptr &np);
|
---|
123 |
|
---|
124 | virtual Token nextToken(YYLTYPE *const sourceLocator);
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * For XSLT we don't need this mechanism, so we do nothing.
|
---|
128 | */
|
---|
129 | virtual int commenceScanOnly();
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * For XSLT we don't need this mechanism, so we do nothing.
|
---|
133 | */
|
---|
134 | virtual void resumeTokenizationFrom(const int position);
|
---|
135 |
|
---|
136 | virtual void setParserContext(const ParserContext::Ptr &parseInfo);
|
---|
137 |
|
---|
138 | virtual QUrl documentURI() const
|
---|
139 | {
|
---|
140 | return queryURI();
|
---|
141 | }
|
---|
142 |
|
---|
143 | protected:
|
---|
144 | virtual bool isAnyAttributeAllowed() const;
|
---|
145 |
|
---|
146 | private:
|
---|
147 | inline void validateElement() const;
|
---|
148 |
|
---|
149 | YYLTYPE currentSourceLocator() const;
|
---|
150 |
|
---|
151 | enum State
|
---|
152 | {
|
---|
153 | OutsideDocumentElement,
|
---|
154 | InsideStylesheetModule,
|
---|
155 | InsideSequenceConstructor
|
---|
156 | };
|
---|
157 |
|
---|
158 | enum VariableType
|
---|
159 | {
|
---|
160 | FunctionParameter,
|
---|
161 | GlobalParameter,
|
---|
162 | TemplateParameter,
|
---|
163 | VariableDeclaration,
|
---|
164 | VariableInstruction,
|
---|
165 | WithParamVariable
|
---|
166 | };
|
---|
167 |
|
---|
168 | void queueNamespaceDeclarations(TokenSource::Queue *const ts,
|
---|
169 | QStack<Token> *const target,
|
---|
170 | const bool isDeclaration = false);
|
---|
171 |
|
---|
172 | inline void queueToken(const Token &token,
|
---|
173 | TokenSource::Queue *const ts);
|
---|
174 | void queueEmptySequence(TokenSource::Queue *const to);
|
---|
175 | void queueSequenceType(const QString &expr);
|
---|
176 | /**
|
---|
177 | * If @p emptynessAllowed is @c true, the @c select attribute may
|
---|
178 | * be empty while there also is no sequence constructor.
|
---|
179 | */
|
---|
180 | void queueSimpleContentConstructor(const ReportContext::ErrorCode code,
|
---|
181 | const bool emptynessAllowed,
|
---|
182 | TokenSource::Queue *const to,
|
---|
183 | const bool selectOnlyFirst = false);
|
---|
184 | /**
|
---|
185 | * Tokenizes and queues @p expr as if it was an attribute value
|
---|
186 | * template.
|
---|
187 | */
|
---|
188 | void queueAVT(const QString &expr,
|
---|
189 | TokenSource::Queue *const to);
|
---|
190 |
|
---|
191 | void hasWrittenExpression(bool &beacon);
|
---|
192 | void commencingExpression(bool &hasWrittenExpression,
|
---|
193 | TokenSource::Queue *const to);
|
---|
194 |
|
---|
195 | void outsideDocumentElement();
|
---|
196 | void insideChoose(TokenSource::Queue *const to);
|
---|
197 | void insideFunction();
|
---|
198 |
|
---|
199 | bool attributeYesNo(const QString &localName) const;
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Scans/skips @c xsl:fallback elements only. This is the case of the
|
---|
203 | * children of @c xsl:sequence, for instance.
|
---|
204 | */
|
---|
205 | void parseFallbacksOnly();
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Returns true if the current element is either @c stylesheet
|
---|
209 | * or the synonym @c transform.
|
---|
210 | *
|
---|
211 | * This function assumes that m_reader is positioned at an element
|
---|
212 | * and that the namespace is XSL-T.
|
---|
213 | */
|
---|
214 | bool isStylesheetElement() const;
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Returns true if the current element name is @p name.
|
---|
218 | *
|
---|
219 | * It is assumed that the namespace is XSL-T and that the current
|
---|
220 | * state in m_reader is either QXmlStreamReader::StartElement or
|
---|
221 | * QXmlStreamReader::EndElement.
|
---|
|
---|