- Timestamp:
- 2013-12-29T12:03:21+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r6554 r6560 22 22 abstract public boolean applies(Environment e); 23 23 24 public static Condition create (String k, String v, Op op, Context context, boolean considerValAsKey) {24 public static Condition createKeyValueCondition(String k, String v, Op op, Context context, boolean considerValAsKey) { 25 25 switch (context) { 26 26 case PRIMITIVE: … … 41 41 } 42 42 43 public static Condition create (String k, boolean not, KeyMatchType matchType, Context context) {43 public static Condition createKeyCondition(String k, boolean not, KeyMatchType matchType, Context context) { 44 44 switch (context) { 45 45 case PRIMITIVE: … … 57 57 } 58 58 59 public static Condition create (String id, boolean not, Context context) {59 public static Condition createPseudoClassCondition(String id, boolean not, Context context) { 60 60 return new PseudoClassCondition(id, not); 61 61 } 62 62 63 public static Condition create(Expression e, Context context) { 63 public static Condition createClassCondition(String id, boolean not, Context context) { 64 return new ClassCondition(id, not); 65 } 66 67 public static Condition createExpressionCondition(Expression e, Context context) { 64 68 return new ExpressionCondition(e); 65 69 } … … 275 279 } 276 280 281 public static class ClassCondition extends Condition { 282 283 public final String id; 284 public final boolean not; 285 286 public ClassCondition(String id, boolean not) { 287 this.id = id; 288 this.not = not; 289 } 290 291 @Override 292 public boolean applies(Environment env) { 293 return not ^ env.mc.getCascade(env.layer).containsKey(id); 294 } 295 296 @Override 297 public String toString() { 298 return (not ? "!" : "") + "." + id; 299 } 300 } 301 277 302 public static class PseudoClassCondition extends Condition { 278 303 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r6538 r6560 84 84 Environment env; 85 85 86 /** 87 * Identity function for compatibility with MapCSS specification. 88 * @param o any object 89 * @return {@code o} unchanged 90 */ 86 91 public static Object eval(Object o) { 87 92 return o; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6554 r6560 42 42 TOKEN: 43 43 { 44 < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* > 44 < SET: ("set" | "SET") > 45 | < IDENT: ["a"-"z","A"-"Z","_"] ( ["a"-"z","A"-"Z","_","-","0"-"9"] )* > 45 46 | < UINT: ["1"-"9"] ( ["0"-"9"] )* > 46 47 | < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? > … … 78 79 | < DOLLAR: "$" > 79 80 | < CARET: "^" > 81 | < FULLSTOP: "." > 80 82 | < COMMENT_START: "/*" > : COMMENT 81 83 | < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from … … 271 273 ( 272 274 ( <GREATER> { parentSelector = false; } | <LESS> { parentSelector = true; } ) 273 ( ( c=condition(Context.LINK) | c= pseudoclass(Context.LINK) ) { conditions.add(c); } )*275 ( ( c=condition(Context.LINK) | c=class_or_pseudoclass(Context.LINK) ) { conditions.add(c); } )* 274 276 { selLink = new LinkSelector(conditions); } 275 277 w() … … 290 292 ( base=<IDENT> | base=<STAR> ) 291 293 ( r=zoom() )? 292 ( ( c=condition(Context.PRIMITIVE) | c= pseudoclass(Context.PRIMITIVE) ) { conditions.add(c); } )*294 ( ( c=condition(Context.PRIMITIVE) | c=class_or_pseudoclass(Context.PRIMITIVE) ) { conditions.add(c); } )* 293 295 ( sub=subpart() )? 294 296 { return new GeneralSelector(base.image, r, conditions, sub); } … … 327 329 c=simple_key_value_condition(context) s() <RSQUARE> { return c; } 328 330 | 329 e=expression() <RSQUARE> { return Condition.create (e, context); }331 e=expression() <RSQUARE> { return Condition.createExpressionCondition(e, context); } 330 332 ) 331 333 } … … 357 359 ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { matchType = Condition.KeyMatchType.FALSE; } )? 358 360 ( <QUESTION> { matchType = Condition.KeyMatchType.TRUE; } )? 359 { return Condition.create (key, not, matchType, context); }361 { return Condition.createKeyCondition(key, not, matchType, context); } 360 362 } 361 363 … … 418 420 f=float_() { val=Float.toString(f); } 419 421 ) 420 { return Condition.create (key, val, op, context, considerValAsKey); }421 } 422 423 Condition pseudoclass(Context context) :422 { return Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); } 423 } 424 425 Condition class_or_pseudoclass(Context context) : 424 426 { 425 427 Token t; 426 428 boolean not = false; 429 boolean pseudo; 427 430 } 428 431 { 429 432 ( <EXCLAMATION> { not = true; } )? 430 <COLON> 433 ( 434 <FULLSTOP> { pseudo = false; } 435 | 436 <COLON> { pseudo = true; } 437 ) 431 438 t=<IDENT> 432 { return Condition.create(t.image, not, context); } 439 { return pseudo 440 ? Condition.createPseudoClassCondition(t.image, not, context) 441 : Condition.createClassCondition(t.image, not, context); } 433 442 } 434 443 … … 448 457 Instruction i; 449 458 Token key; 450 Object val ;459 Object val = null; 451 460 } 452 461 { 453 462 <LBRACE> w() 454 463 ( 464 ( 465 <SET> w() key=<IDENT> w() 466 ( <EQUAL> val=expression() )? 467 { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val)); } 468 ( <RBRACE> { return ins; } | <SEMICOLON> w() ) 469 ) 470 | 455 471 key=<IDENT> w() <COLON> w() 456 472 (
Note:
See TracChangeset
for help on using the changeset viewer.