Changeset 8087 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
- Timestamp:
- 2015-02-19T15:22:49+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r8086 r8087 38 38 * (a) the preprocessor and (b) the main mapcss parser. 39 39 * 40 * The preprocessor handles @ media syntax. Basically this allows41 * to write one style for different versions of JOSM (or different editors).42 * When the @ mediacondition is not fulfilled, it should simply skip over40 * The preprocessor handles @supports and @media syntax (@media is deprecated). 41 * Basically this allows to write one style for different versions of JOSM (or different editors). 42 * When the @supports condition is not fulfilled, it should simply skip over 43 43 * the whole section and not attempt to parse the possibly unknown 44 44 * grammar. It preserves whitespace and comments, in order to keep the … … 100 100 { 101 101 < PP_AND: "and" > 102 | < PP_OR: "or" > 102 103 | < PP_NOT: "not" > 104 | < PP_SUPPORTS: "@supports" > 103 105 | < PP_MEDIA: "@media" > 104 106 | < PP_NEWLINECHAR: "\n" | "\r" | "\f" > … … 244 246 { 245 247 ( 246 (t=<PP_AND> | t=<PP_ NOT> | t=<UINT> | t=<STRING> | t=<REGEX> | t=<LPAR> | t=<RPAR> | t=<COMMA> | t=<COLON> | t=<IDENT> | t=<PP_SOMETHING_ELSE>) { if (write) sb.append(t.image); }248 (t=<PP_AND> | t=<PP_OR> | t=<PP_NOT> | t=<UINT> | t=<STRING> | t=<REGEX> | t=<LPAR> | t=<RPAR> | t=<COMMA> | t=<COLON> | t=<IDENT> | t=<PP_SOMETHING_ELSE>) { if (write) sb.append(t.image); } 247 249 | 248 250 pp_w1() 251 | 252 pp_supports(!write) 249 253 | 250 254 pp_media(!write) … … 254 258 } 255 259 260 /** 261 * Parses an @supports rule. 262 * 263 * @param ignore if the content of this rule should be ignored 264 * (because we are already inside a @supports block that didn't pass) 265 */ 266 void pp_supports(boolean ignore): 267 { 268 boolean pass; 269 } 270 { 271 <PP_SUPPORTS> pp_w() 272 pass=pp_supports_condition() 273 <LBRACE> 274 pp_black_box(pass && !ignore) 275 <RBRACE> 276 } 277 278 /** 279 * Parses the condition of the @supports rule. 280 * 281 * Unlike other parsing rules, grabs trailing whitespace. 282 * @return true, if the condition is fulfilled 283 */ 284 boolean pp_supports_condition(): 285 { 286 boolean pass; 287 boolean q; 288 } 289 { 290 ( 291 <PP_NOT> pp_w() q=pp_supports_condition_in_parens() { pass = !q; } pp_w() 292 | 293 LOOKAHEAD(pp_supports_condition_in_parens() pp_w() <PP_AND>) 294 pass=pp_supports_condition_in_parens() pp_w() 295 ( <PP_AND> pp_w() q=pp_supports_condition_in_parens() { pass = pass && q; } pp_w() )+ 296 | 297 LOOKAHEAD(pp_supports_condition_in_parens() pp_w() <PP_OR>) 298 pass=pp_supports_condition_in_parens() pp_w() 299 ( <PP_OR> pp_w() q=pp_supports_condition_in_parens() { pass = pass || q; } pp_w() )+ 300 | 301 pass=pp_supports_condition_in_parens() pp_w() 302 ) 303 { return pass; } 304 } 305 306 /** 307 * Parses something in parenthesis inside the condition of the @supports rule. 308 * 309 * @return true, if the condition is fulfilled 310 */ 311 boolean pp_supports_condition_in_parens(): 312 { 313 boolean pass; 314 } 315 { 316 ( 317 LOOKAHEAD(pp_supports_declaration_condition()) 318 pass=pp_supports_declaration_condition() 319 | 320 <LPAR> pp_w() pass=pp_supports_condition() <RPAR> 321 ) 322 { return pass; } 323 } 324 325 /** 326 * Parse an @supports declaration condition, e. g. a single (key:value) or (key) statement. 327 * 328 * The parsing rule {@link #literal()} from the main mapcss parser is reused here. 329 * 330 * @return true if the condition is fulfilled 331 */ 332 boolean pp_supports_declaration_condition(): 333 { 334 Token t; 335 String feature; 336 Object val = null; 337 } 338 { 339 <LPAR> pp_w() t=<IDENT> { feature = t.image; } pp_w() ( <COLON> pp_w() val=literal() )? <RPAR> 340 { return this.sheet.evalSupportsDeclCondition(feature, val); } 341 } 342 343 // deprecated 256 344 void pp_media(boolean ignore): 257 345 { … … 270 358 } 271 359 360 // deprecated 272 361 boolean pp_media_query(): 273 362 { … … 302 391 * @return true if the condition is fulfilled 303 392 */ 393 // deprecated 304 394 boolean pp_media_expression(): 305 395 { … … 310 400 { 311 401 <LPAR> pp_w() t=<IDENT> { feature = t.image; } pp_w() ( <COLON> pp_w() val=literal() )? <RPAR> 312 { return this.sheet.eval MediaExpression(feature, val); }402 { return this.sheet.evalSupportsDeclCondition(feature, val); } 313 403 } 314 404
Note: See TracChangeset
for help on using the changeset viewer.