Changeset 4069 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.jj
- Timestamp:
- 2011-05-02T23:47:19+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.jj
r4011 r4069 13 13 import org.openstreetmap.josm.gui.mappaint.Keyword; 14 14 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition; 15 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context; 15 16 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression; 16 17 import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction; … … 20 21 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.FunctionExpression; 21 22 import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.LiteralExpression; 23 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException; 22 24 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector; 23 25 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector; 26 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector; 24 27 import org.openstreetmap.josm.tools.Pair; 25 28 … … 224 227 ( 225 228 try { 226 r=rule() { if (r != null) { sheet.rules.add(r); } } w() 229 r=rule() { if (r != null) { sheet.rules.add(r); } } w() 230 } catch (MapCSSException mex) { 231 error_skipto(RBRACE, mex); 232 w(); 227 233 } catch (ParseException ex) { 228 error_skipto(RBRACE); 234 error_skipto(RBRACE, null); 229 235 w(); 230 236 } … … 252 258 { 253 259 boolean parentSelector = false; 254 Selector sel1, sel2 = null; 255 } 256 { 257 sel1=selector() w() 258 ( 259 ( <GREATER> { parentSelector = false; } | <LESS> { parentSelector = true; } ) w() 260 sel2=selector() w() 260 Condition c; 261 List<Condition> conditions = new ArrayList<Condition>(); 262 Selector selLeft; 263 LinkSelector selLink = null; 264 Selector selRight = null; 265 } 266 { 267 selLeft=selector() w() 268 ( 269 ( <GREATER> { parentSelector = false; } | <LESS> { parentSelector = true; } ) 270 ( ( c=condition(Context.LINK) | c=pseudoclass(Context.LINK) ) { conditions.add(c); } )* 271 { selLink = new LinkSelector(conditions); } 272 w() 273 selRight=selector() w() 261 274 )? 262 { return sel 2!= null ? new ChildOrParentSelector(sel1, sel2, parentSelector) : sel1; }275 { return selRight != null ? new ChildOrParentSelector(selLeft, selLink, selRight, parentSelector) : selLeft; } 263 276 } 264 277 … … 274 287 ( base=<IDENT> | base=<STAR> ) 275 288 ( r=zoom() )? 276 ( ( c=condition() | c=pseudoclass() ) { conditions.add(c); } )* 289 ( ( c=condition(Context.PRIMITIVE) | c=pseudoclass(Context.PRIMITIVE) ) { conditions.add(c); } )* 277 290 ( sub=subpart() )? 278 291 { return new GeneralSelector(base.image, r, conditions, sub); } … … 294 307 } 295 308 296 Condition condition() : 309 Condition condition(Context context) : 297 310 { 298 311 Condition c; … … 302 315 <LSQUARE> s() 303 316 ( 304 LOOKAHEAD( simple_key_condition() s() <RSQUARE> ) 305 c=simple_key_condition() s() <RSQUARE> { return c; } 317 LOOKAHEAD( simple_key_condition(context) s() <RSQUARE> ) 318 c=simple_key_condition(context) s() <RSQUARE> { return c; } 306 319 | 307 LOOKAHEAD( simple_key_value_condition() s() <RSQUARE> ) 308 c=simple_key_value_condition() s() <RSQUARE> { return c; } 320 LOOKAHEAD( simple_key_value_condition(context) s() <RSQUARE> ) 321 c=simple_key_value_condition(context) s() <RSQUARE> { return c; } 309 322 | 310 e=expression() <RSQUARE> { return newCondition.ExpressionCondition(e); }323 e=expression() <RSQUARE> { return Condition.create(e, context); } 311 324 ) 312 325 } … … 323 336 } 324 337 325 Condition simple_key_condition() : 338 Condition simple_key_condition(Context context) : 326 339 { 327 340 boolean not = false; … … 333 346 key=tag_key() 334 347 ( <QUESTION> { yes = true; } )? 335 { return newCondition.KeyCondition(key, not, yes); }336 } 337 338 Condition simple_key_value_condition() : 348 { return Condition.create(key, not, yes, context); } 349 } 350 351 Condition simple_key_value_condition(Context context) : 339 352 { 340 353 String key; … … 385 398 f=float_() { val=Float.toString(f); } 386 399 ) 387 { return newCondition.KeyValueCondition(key, val, op); }388 } 389 390 Condition pseudoclass() : 400 { return Condition.create(key, val, op, context); } 401 } 402 403 Condition pseudoclass(Context context) : 391 404 { 392 405 Token t; … … 397 410 <COLON> 398 411 t=<IDENT> 399 { return newCondition.PseudoClassCondition(t.image, not); }412 { return Condition.create(t.image, not, context); } 400 413 } 401 414 … … 550 563 551 564 JAVACODE 552 void error_skipto(int kind) { 565 void error_skipto(int kind, MapCSSException me) { 553 566 if (token.kind == EOF) 554 567 throw new ParseException("Reached end of file while parsing"); 555 ParseException e = generateParseException(); 568 569 Exception e = null; 570 ParseException pe = generateParseException(); 571 572 if (me != null) { 573 me.setLine(pe.currentToken.next.beginLine); 574 me.setColumn(pe.currentToken.next.beginColumn); 575 e = me; 576 } else { 577 e = new ParseException(pe.getMessage()); // prevent memory leak 578 } 579 556 580 System.err.println("Skipping to the next rule, because of an error:"); 557 581 System.err.println(e); 558 582 if (sheet != null) { 559 sheet.logError( new ParseException(e.getMessage()));583 sheet.logError(e); 560 584 } 561 585 Token t;
Note:
See TracChangeset
for help on using the changeset viewer.
