source: trunk/src/corelib/xml/qxmlstream.g@ 135

Last change on this file since 135 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 55.5 KB
Line 
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 QtCore 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-- This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41-- WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42--
43----------------------------------------------------------------------------
44
45%parser QXmlStreamReader_Table
46
47%merged_output qxmlstream_p.h
48
49%token NOTOKEN
50%token SPACE " "
51%token LANGLE "<"
52%token RANGLE ">"
53%token AMPERSAND "&"
54%token HASH "#"
55%token QUOTE "\'"
56%token DBLQUOTE "\""
57%token LBRACK "["
58%token RBRACK "]"
59%token LPAREN "("
60%token RPAREN ")"
61%token PIPE "|"
62%token EQ "="
63%token PERCENT "%"
64%token SLASH "/"
65%token COLON ":"
66%token SEMICOLON ";"
67%token COMMA ","
68%token DASH "-"
69%token PLUS "+"
70%token STAR "*"
71%token DOT "."
72%token QUESTIONMARK "?"
73%token BANG "!"
74%token LETTER "[a-zA-Z]"
75%token DIGIT "[0-9]"
76
77-- after langle_bang
78%token CDATA_START "[CDATA["
79%token DOCTYPE "DOCTYPE"
80%token ELEMENT "ELEMENT"
81%token ATTLIST "ATTLIST"
82%token ENTITY "ENTITY"
83%token NOTATION "NOTATION"
84
85-- entity decl
86%token SYSTEM "SYSTEM"
87%token PUBLIC "PUBLIC"
88%token NDATA "NDATA"
89
90-- default decl
91%token REQUIRED "REQUIRED"
92%token IMPLIED "IMPLIED"
93%token FIXED "FIXED"
94
95-- conent spec
96%token EMPTY "EMPTY"
97%token ANY "ANY"
98%token PCDATA "PCDATA"
99
100-- error
101%token ERROR
102
103-- entities
104%token PARSE_ENTITY
105%token ENTITY_DONE
106%token UNRESOLVED_ENTITY
107
108-- att type
109%token CDATA "CDATA"
110%token ID "ID"
111%token IDREF "IDREF"
112%token IDREFS "IDREFS"
113%token ENTITY "ENTITY"
114%token ENTITIES "ENTITIES"
115%token NMTOKEN "NMTOKEN"
116%token NMTOKENS "NMTOKENS"
117
118-- xml declaration
119%token XML "<?xml"
120%token VERSION "version"
121
122%nonassoc SHIFT_THERE
123%nonassoc AMPERSAND
124 BANG
125 COLON
126 COMMA
127 DASH
128 DBLQUOTE
129 DIGIT
130 DOT
131 ENTITY_DONE
132 EQ
133 HASH
134 LBRACK
135 LETTER
136 LPAREN
137 PERCENT
138 PIPE
139 PLUS
140 QUESTIONMARK
141 QUOTE
142 RANGLE
143 RBRACK
144 RPAREN
145 SEMICOLON
146 SLASH
147 SPACE
148 STAR
149
150%start document
151
152/.
153template <typename T> class QXmlStreamSimpleStack {
154 T *data;
155 int tos, cap;
156public:
157 inline QXmlStreamSimpleStack():data(0), tos(-1), cap(0){}
158 inline ~QXmlStreamSimpleStack(){ if (data) qFree(data); }
159
160 inline void reserve(int extraCapacity) {
161 if (tos + extraCapacity + 1 > cap) {
162 cap = qMax(tos + extraCapacity + 1, cap << 1 );
163 data = reinterpret_cast<T *>(qRealloc(data, cap * sizeof(T)));
164 }
165 }
166
167 inline T &push() { reserve(1); return data[++tos]; }
168 inline T &rawPush() { return data[++tos]; }
169 inline const T &top() const { return data[tos]; }
170 inline T &top() { return data[tos]; }
171 inline T &pop() { return data[tos--]; }
172 inline T &operator[](int index) { return data[index]; }
173 inline const T &at(int index) const { return data[index]; }
174 inline int size() const { return tos + 1; }
175 inline void resize(int s) { tos = s - 1; }
176 inline bool isEmpty() const { return tos < 0; }
177 inline void clear() { tos = -1; }
178};
179
180
181class QXmlStream
182{
183 Q_DECLARE_TR_FUNCTIONS(QXmlStream)
184};
185
186class QXmlStreamPrivateTagStack {