1 #ifndef __CSSPARSER_H__
2 #define __CSSPARSER_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 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 CssParser
47 {
49 public:
51 /**
52 *
53 */
54 CssParser()
55 {}
57 /**
58 *
59 */
60 virtual ~CssParser()
61 {}
63 /**
64 *
65 */
66 virtual bool parse(const DOMString &str);
68 /**
69 *
70 */
71 virtual bool parseFile(const DOMString &str);
74 protected:
76 DOMString parsebuf;
77 long parselen;
78 CSSStyleSheet stylesheet;
81 /**
82 *
83 */
84 void error(char *fmt, ...);
86 /**
87 * Get the character at the given location in the buffer.
88 * Return 0 if out-of-bounds
89 */
90 XMLCh get(int index);
93 /**
94 * Test if the given substring exists at the given position
95 * in parsebuf. Use get() in case of out-of-bounds
96 */
97 bool match(int pos, char *str);
99 /**
100 * Skip over whitespace
101 * Return new position
102 */
103 int skipwhite(int index);
105 /**
106 * Get the word at the current position. Return the new
107 * position if successful, the current position if no word,
108 * -1 if error.
109 */
110 int getWord(int index, DOMString &str);
113 /**
114 * Get a number at the current position
115 * Return the new position if a proper number, else the original pos
116 */
117 int getNumber(int index, double &result);
119 /**
120 * Assume that we are starting on a quote. Ends on the char
121 * after the final '"'
122 */
123 int getQuoted(int p0, DOMString &result);
125 /**
126 * Not in api. replaces URI return by lexer
127 */
128 int getUri(int p0, DOMString &str);
131 /**
132 * Skip to the next rule
133 */
134 int skipBlock(int p0);
136 //#########################################################################
137 //# P R O D U C T I O N S
138 //#########################################################################
140 /**
141 * stylesheet
142 * : [ CHARSET_SYM S* STRING S* ';' ]?
143 * [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
144 * [ [ ruleset | media | page ] [S|CDO|CDC]* ]*
145 * ;
146 */
147 int getStyleSheet(int p0);
149 /**
150 * import
151 * : IMPORT_SYM S*
152 * [STRING|URI] S* [ medium [ COMMA S* medium]* ]? ';' S*
153 * ;
154 */
155 int getImport(int p0);
157 /**
158 * media
159 * : MEDIA_SYM S* medium [ COMMA S* medium ]* LBRACE S* ruleset* '}' S*
160 * ;
161 */
162 int getMedia(int p0);
164 /**
165 * medium
166 * : IDENT S*
167 * ;
168 */
169 int getMedium(int p0);
171 /**
172 * page
173 * : PAGE_SYM S* pseudo_page? S*
174 * LBRACE S* declaration [ ';' S* declaration ]* '}' S*
175 * ;
176 */
177 int getPage(int p0);
179 /**
180 * pseudo_page
181 * : ':' IDENT
182 * ;
183 */
184 int getPseudoPage(int p0);
186 /**
187 * ruleset
188 * : selector [ COMMA S* selector ]*
189 * LBRACE S* declaration [ ';' S* declaration ]* '}' S*
190 * ;
191 */
192 int getRuleSet(int p0);
194 /**
195 * selector
196 * : simple_selector [ combinator simple_selector ]*
197 * ;
198 */
199 int getSelector(int p0);
201 /**
202 * simple_selector
203 * : element_name [ HASH | class | attrib | pseudo ]*
204 * | [ HASH | class | attrib | pseudo ]+
205 * ;
206 */
207 int getSimpleSelector(int p0);
209 /**
210 * declaration
211 * : property ':' S* expr prio?
212 * | {empty}
213 * ;
214 */
215 int getDeclaration(int p0, CSSStyleDeclaration &declarationList);
217 /**
218 * prio
219 * : IMPORTANT_SYM S*
220 * ;
221 */
222 int getPrio(int p0, DOMString &val);
224 /**
225 * expr
226 * : term [ operator term ]*
227 * ;
228 */
229 int getExpr(int p0);
231 /**
232 * term
233 * : unary_operator?
234 * [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
235 * TIME S* | FREQ S* | function ]
236 * | STRING S* | IDENT S* | URI S* | hexcolor
237 * ;
238 */
239 int getTerm(int p0);
241 /**
242 * function
243 * : FUNCTION S* expr ')' S*
244 * ;
245 */
246 int getFunction(int p0);
248 /**
249 * There is a constraint on the color that it must
250 * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
251 * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
252 *
253 * hexcolor
254 * : HASH S*
255 * ;
256 */
257 int getHexColor(int p0);
260 int lastPosition;
262 /**
263 * Get the column and row number of the given character position.
264 * Also gets the last-occuring newline before the position
265 */
266 void getColumnAndRow(int p, int &col, int &row, int &lastNL);
268 };
271 } // namespace css
272 } // namespace dom
273 } // namespace w3c
274 } // namespace org
282 #endif /* __CSSPARSER_H__ */
283 //#########################################################################
284 //# E N D O F F I L E
285 //#########################################################################