1 #ifndef __CSSREADER_H__
2 #define __CSSREADER_H__
3 /**
4 * Phoebe DOM Implementation.
5 *
6 * This is a C++ approximation of the W3C DOM model, which follows
7 * fairly closely the specifications in the various .idl files, copies of
8 * which are provided for reference. Most important is this one:
9 *
10 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11 *
12 * Authors:
13 * Bob Jamison
14 *
15 * Copyright (C) 2005-2008 Bob Jamison
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
33 #include "dom.h"
35 #include "css.h"
37 namespace org
38 {
39 namespace w3c
40 {
41 namespace dom
42 {
43 namespace css
44 {
46 class CssReader
47 {
49 public:
51 /**
52 *
53 */
54 CssReader()
55 {}
57 /**
58 *
59 */
60 virtual ~CssReader()
61 {}
63 /**
64 *
65 */
66 virtual bool parse(const DOMString &str);
68 /**
69 *
70 */
71 virtual bool parseFile(const DOMString &str);
74 private:
76 DOMString parsebuf;
77 long parselen;
78 CSSStyleSheet stylesheet;
81 /**
82 *
83 */
84 void error(char const *fmt, ...)
85 #ifdef G_GNUC_PRINTF
86 G_GNUC_PRINTF(2, 3)
87 #endif
88 ;
90 /**
91 * Get the character at the given location in the buffer.
92 * Return 0 if out-of-bounds
93 */
94 XMLCh get(int index);
97 /**
98 * Test if the given substring exists at the given position
99 * in parsebuf. Use get() in case of out-of-bounds
100 */
101 bool match(int pos, const char *str);
103 /**
104 * Skip over whitespace
105 * Return new position
106 */
107 int skipwhite(int index);
109 /**
110 * Get the word at the current position. Return the new
111 * position if successful, the current position if no word,
112 * -1 if error.
113 */
114 int getWord(int index, DOMString &str);
117 /**
118 * Get a number at the current position
119 * Return the new position if a proper number, else the original pos
120 */
121 int getNumber(int index, double &result);
123 /**
124 * Assume that we are starting on a quote. Ends on the char
125 * after the final '"'
126 */
127 int getQuoted(int p0, DOMString &result);
129 /**
130 * Not in api. replaces URI return by lexer
131 */
132 int getUri(int p0, DOMString &str);
135 /**
136 * Skip to the next rule
137 */
138 int skipBlock(int p0);
140 //#########################################################################
141 //# P R O D U C T I O N S
142 //#########################################################################
144 /**
145 * stylesheet
146 * : [ CHARSET_SYM S* STRING S* ';' ]?
147 * [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
148 * [ [ ruleset | media | page ] [S|CDO|CDC]* ]*
149 * ;
150 */
151 int getStyleSheet(int p0);
153 /**
154 * import
155 * : IMPORT_SYM S*
156 * [STRING|URI] S* [ medium [ COMMA S* medium]* ]? ';' S*
157 * ;
158 */
159 int getImport(int p0);
161 /**
162 * media
163 * : MEDIA_SYM S* medium [ COMMA S* medium ]* LBRACE S* ruleset* '}' S*
164 * ;
165 */
166 int getMedia(int p0);
168 /**
169 * medium
170 * : IDENT S*
171 * ;
172 */
173 int getMedium(int p0);
175 /**
176 * page
177 * : PAGE_SYM S* pseudo_page? S*
178 * LBRACE S* declaration [ ';' S* declaration ]* '}' S*
179 * ;
180 */
181 int getPage(int p0);
183 /**
184 * pseudo_page
185 * : ':' IDENT
186 * ;
187 */
188 int getPseudoPage(int p0);
190 /**
191 * ruleset
192 * : selector [ COMMA S* selector ]*
193 * LBRACE S* declaration [ ';' S* declaration ]* '}' S*
194 * ;
195 */
196 int getRuleSet(int p0);
198 /**
199 * selector
200 * : simple_selector [ combinator simple_selector ]*
201 * ;
202 */
203 int getSelector(int p0);
205 /**
206 * simple_selector
207 * : element_name [ HASH | class | attrib | pseudo ]*
208 * | [ HASH | class | attrib | pseudo ]+
209 * ;
210 */
211 int getSimpleSelector(int p0);
213 /**
214 * declaration
215 * : property ':' S* expr prio?
216 * | {empty}
217 * ;
218 */
219 int getDeclaration(int p0, CSSStyleDeclaration &declarationList);
221 /**
222 * prio
223 * : IMPORTANT_SYM S*
224 * ;
225 */
226 int getPrio(int p0, DOMString &val);
228 /**
229 * expr
230 * : term [ operator term ]*
231 * ;
232 */
233 int getExpr(int p0);
235 /**
236 * term
237 * : unary_operator?
238 * [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
239 * TIME S* | FREQ S* | function ]
240 * | STRING S* | IDENT S* | URI S* | hexcolor
241 * ;
242 */
243 int getTerm(int p0);
245 /**
246 * function
247 * : FUNCTION S* expr ')' S*
248 * ;
249 */
250 int getFunction(int p0);
252 /**
253 * There is a constraint on the color that it must
254 * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
255 * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
256 *
257 * hexcolor
258 * : HASH S*
259 * ;
260 */
261 int getHexColor(int p0);
264 int lastPosition;
266 /**
267 * Get the column and row number of the given character position.
268 * Also gets the last-occuring newline before the position
269 */
270 void getColumnAndRow(int p, int &col, int &row, int &lastNL);
272 };
275 } // namespace css
276 } // namespace dom
277 } // namespace w3c
278 } // namespace org
286 #endif /* __CSSREADER_H__ */
287 //#########################################################################
288 //# E N D O F F I L E
289 //#########################################################################