f1decd8b57f810b313694a2ce87f3874d85d9c06
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / parser / qtokensource_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
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_TokenSource_H
53 #define Patternist_TokenSource_H
54
55 #include <private/qatomiccomparator_p.h>
56 #include <private/qatomicmathematician_p.h>
57 #include <private/qcombinenodes_p.h>
58 #include <private/qfunctionargument_p.h>
59 #include <private/qitem_p.h>
60 #include <private/qitemtype_p.h>
61 #include <private/qorderby_p.h>
62 #include <private/qpath_p.h>
63 #include <private/qquerytransformparser_p.h>
64 #include <private/qvalidate_p.h>
65
66 QT_BEGIN_HEADER
67
68 QT_BEGIN_NAMESPACE
69
70 template<typename T> class QQueue;
71
72 namespace QPatternist
73 {
74     /**
75      * @short A union of all the enums the parser uses.
76      */
77     union EnumUnion
78     {
79         AtomicComparator::Operator              valueOperator;
80         AtomicMathematician::Operator           mathOperator;
81         CombineNodes::Operator                  combinedNodeOp;
82         QXmlNodeModelIndex::Axis                axis;
83         QXmlNodeModelIndex::DocumentOrder       nodeOperator;
84         StaticContext::BoundarySpacePolicy      boundarySpacePolicy;
85         StaticContext::ConstructionMode         constructionMode;
86         StaticContext::OrderingEmptySequence    orderingEmptySequence;
87         StaticContext::OrderingMode             orderingMode;
88         OrderBy::OrderSpec::Direction           sortDirection;
89         Validate::Mode                          validationMode;
90         VariableSlotID                          slot;
91         int                                     tokenizerPosition;
92         qint16                                  zeroer;
93         bool                                    Bool;
94         xsDouble                                Double;
95         Path::Kind                              pathKind;
96     };
97
98     /**
99      * @short Base class for components that needs to return tokens.
100      *
101      * TokenSource represents a stream of Token instances. The end
102      * is reached when readNext() returns a Token constructed with
103      * END_OF_FILE.
104      *
105      * @see <a href="http://www.w3.org/TR/xquery-xpath-parsing/">Building a
106      * Tokenizer for XPath or XQuery</a>
107      * @author Frans Englich <frans.englich@nokia.com>
108      */
109     class TokenSource : public QSharedData
110     {
111     public:
112         /**
113          * typedef for the enum Bison generates that contains
114          * the token symbols.
115          */
116         typedef yytokentype TokenType;
117
118         /**
119          * Represents a token by carrying its name and value.
120          */
121         class Token
122         {
123         public:
124             /**
125              * Constructs an invalid Token. This default constructor
126              * is need in Qt's container classes.
127              */
128             inline Token() {}
129             inline Token(const TokenType t) : type(t) {}
130             inline Token(const TokenType t, const QString &val) : type(t), value(val) {}
131
132             bool hasError() const
133             {
134                 return type == ERROR;
135             }
136
137             TokenType type;
138             QString value;
139         };
140
141         typedef QExplicitlySharedDataPointer<TokenSource> Ptr;
142         typedef QQueue<Ptr> Queue;
143
144         /**
145          * The C++ compiler cannot synthesize it when we use the
146          * Q_DISABLE_COPY() macro.
147          */
148         inline TokenSource()
149         {
150         }
151
152         virtual ~TokenSource();
153
154         /**
155          * @returns the next token.
156          */
157
158             virtual Token nextToken(YYLTYPE *const sourceLocator) = 0;
159
160     private:
161         Q_DISABLE_COPY(TokenSource)
162     };
163 }
164
165 QT_END_NAMESPACE
166
167 QT_END_HEADER
168
169 #endif