Changeset 6896 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
- Timestamp:
- 2014-03-02T16:23:58+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6830 r6896 41 41 42 42 <DEFAULT> 43 TOKEN [IGNORE_CASE]: 44 { 45 /* Special keywords in some contexts, ordinary identifiers in other contexts. 46 Don't use the javacc token contexts (except DEFAULT and COMMENT) because 47 they complicate error handling. Instead simply add a parsing rule <code>ident()</code> 48 that parses the IDENT token and in addition all the keyword tokens. */ 49 < AND: "and" > 50 | < SET: "set" > 51 | < NOT: "not" > 52 | < MEDIA: "@media" > 53 } 54 55 <DEFAULT> 43 56 TOKEN: 44 57 { 45 < SET: ("set" | "SET") > 46 | < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* > 58 < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* > 47 59 | < UINT: ["1"-"9"] ( ["0"-"9"] )* > 48 60 | < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? > … … 122 134 * 'val' can be a literal, or an expression like "prop(width, default) + 0.8". 123 135 * 136 * @media { ... } queries are supported, following http://www.w3.org/TR/css3-mediaqueries/#syntax 137 * 138 * media_query 139 * ___________________________|_______________________________ 140 * | | 141 * @media all and (min-josm-version: 7789) and (max-josm-version: 7790), all and (user-agent: xyz) { ... } 142 * |______________________| 143 * | 144 * media_expression 124 145 */ 125 146 … … 166 187 } 167 188 189 String ident(): 190 { 191 Token t; 192 String s; 193 } 194 { 195 ( t=<IDENT> | t=<SET> | t=<NOT> | t=<AND> ) { return t.image; } 196 } 197 168 198 String string_or_ident() : 169 199 { … … 172 202 } 173 203 { 174 t=<IDENT> { return t.image; } | s=string() { return s; }204 ( s=ident() | s=string() ) { return s; } 175 205 } 176 206 … … 229 259 { 230 260 MapCSSRule r; 231 Token com = null;232 261 } 233 262 { 234 263 { this.sheet = sheet; } 235 264 w() 265 rules(true) ( media() w() rules(true) )* 266 <EOF> 267 } 268 269 void media(): 270 { 271 boolean pass = false; 272 boolean q; 273 boolean empty = true; 274 } 275 { 276 <MEDIA> w() 277 ( q=media_query() { pass = pass || q; empty = false; } 278 ( <COMMA> w() q=media_query() { pass = pass || q; } )* 279 )? 280 <LBRACE> w() 281 rules(empty || pass) 282 <RBRACE> 283 } 284 285 boolean media_query(): 286 { 287 Token t; 288 String mediatype = "all"; 289 boolean pass = true; 290 boolean invert = false; 291 boolean e; 292 } 293 { 294 ( <NOT> { invert = true; } w() )? 295 ( 296 t=<IDENT> { mediatype = t.image.toLowerCase(); } w() 297 ( <AND> w() e=media_expression() { pass = pass && e; } w() )* 298 | 299 e=media_expression() { pass = pass && e; } w() 300 ( <AND> w() e=media_expression() { pass = pass && e; } w() )* 301 ) 302 { 303 if (!"all".equals(mediatype)) { 304 pass = false; 305 } 306 return invert ? (!pass) : pass; 307 } 308 } 309 310 boolean media_expression(): 311 { 312 Token t; 313 String feature; 314 Object val = null; 315 } 316 { 317 <LPAR> w() t=<IDENT> { feature = t.image; } w() ( <COLON> w() val=literal() )? <RPAR> 318 { return this.sheet.evalMediaExpression(feature, val); } 319 } 320 321 void rules(boolean add): 322 { 323 MapCSSRule r; 324 } 325 { 236 326 ( 237 327 try { 238 r=rule() { if (r != null) { sheet.rules.add(r); } } w()328 r=rule() { if (add && r != null) { sheet.rules.add(r); } } w() 239 329 } catch (MapCSSException mex) { 240 330 error_skipto(RBRACE, mex); … … 245 335 } 246 336 )* 247 <EOF>248 337 } 249 338 … … 345 434 String tag_key() : 346 435 { 347 String s ;436 String s, s2; 348 437 Token t; 349 438 } … … 351 440 s=string() { return s; } 352 441 | 353 t=<IDENT> { s = t.image; } ( <COLON> t=<IDENT> { s += ':' + t.image; } )* { return s; }442 s=ident() ( <COLON> s2=ident() { s += ':' + s2; } )* { return s; } 354 443 } 355 444 … … 435 524 Condition class_or_pseudoclass(Context context) : 436 525 { 437 Token t;526 String s; 438 527 boolean not = false; 439 528 boolean pseudo; … … 446 535 <COLON> { pseudo = true; } 447 536 ) 448 t=<IDENT>537 s=ident() 449 538 { return pseudo 450 ? Condition.createPseudoClassCondition( t.image, not, context)451 : Condition.createClassCondition( t.image, not, context); }539 ? Condition.createPseudoClassCondition(s, not, context) 540 : Condition.createClassCondition(s, not, context); } 452 541 } 453 542 454 543 String subpart() : 455 544 { 456 Token t;545 String s; 457 546 } 458 547 { 459 548 <DCOLON> 460 ( t=<IDENT> | t=<STAR> ) 461 { return t.image; } 549 ( s=ident() { return s; } | <STAR> { return "*"; } ) 462 550 } 463 551 … … 573 661 } 574 662 { 575 tmp=<IDENT> { name = tmp.image; }w()663 name=ident() w() 576 664 <LPAR> w() 577 665 (
Note:
See TracChangeset
for help on using the changeset viewer.