Ignore:
Timestamp:
2011-05-02T23:47:19+02:00 (15 years ago)
Author:
bastiK
Message:

mapcss: add role based selection (collaborative work by Gubaer and me)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.jj

    r4011 r4069  
    1313import org.openstreetmap.josm.gui.mappaint.Keyword;
    1414import org.openstreetmap.josm.gui.mappaint.mapcss.Condition;
     15import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context;
    1516import org.openstreetmap.josm.gui.mappaint.mapcss.Expression;
    1617import org.openstreetmap.josm.gui.mappaint.mapcss.Instruction;
     
    2021import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.FunctionExpression;
    2122import org.openstreetmap.josm.gui.mappaint.mapcss.Expression.LiteralExpression;
     23import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSException;
    2224import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
    2325import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.GeneralSelector;
     26import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.LinkSelector;
    2427import org.openstreetmap.josm.tools.Pair;
    2528
     
    224227    (
    225228        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();
    227233        } catch (ParseException ex) {
    228             error_skipto(RBRACE);
     234            error_skipto(RBRACE, null);
    229235            w();
    230236        }
     
    252258{
    253259    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()
    261274    )?
    262     { return sel2 != null ? new ChildOrParentSelector(sel1, sel2, parentSelector) : sel1; }
     275    { return selRight != null ? new ChildOrParentSelector(selLeft, selLink, selRight, parentSelector) : selLeft; }
    263276}
    264277
     
    274287    ( base=<IDENT> | base=<STAR> )
    275288    ( r=zoom() )?
    276     ( ( c=condition() | c=pseudoclass() ) { conditions.add(c); } )*
     289    ( ( c=condition(Context.PRIMITIVE) | c=pseudoclass(Context.PRIMITIVE) ) { conditions.add(c); } )*
    277290    ( sub=subpart() )?
    278291    { return new GeneralSelector(base.image, r, conditions, sub); }
     
    294307}
    295308
    296 Condition condition() :
     309Condition condition(Context context) :
    297310{
    298311    Condition c;
     
    302315    <LSQUARE> s()
    303316    (
    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; }
    306319        |
    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; }
    309322        |
    310             e=expression() <RSQUARE> { return new Condition.ExpressionCondition(e); }
     323            e=expression() <RSQUARE> { return Condition.create(e, context); }
    311324    )
    312325}
     
    323336}
    324337
    325 Condition simple_key_condition() :
     338Condition simple_key_condition(Context context) :
    326339{
    327340    boolean not = false;
     
    333346    key=tag_key()
    334347    ( <QUESTION> { yes = true; } )?
    335     { return new Condition.KeyCondition(key, not, yes); }
    336 }
    337 
    338 Condition simple_key_value_condition() :
     348    { return Condition.create(key, not, yes, context); }
     349}
     350
     351Condition simple_key_value_condition(Context context) :
    339352{
    340353    String key;
     
    385398            f=float_() { val=Float.toString(f); }
    386399    )
    387     { return new Condition.KeyValueCondition(key, val, op); }
    388 }
    389 
    390 Condition pseudoclass() :
     400    { return Condition.create(key, val, op, context); }
     401}
     402
     403Condition pseudoclass(Context context) :
    391404{
    392405    Token t;
     
    397410    <COLON>
    398411    t=<IDENT>
    399     { return new Condition.PseudoClassCondition(t.image, not); }
     412    { return Condition.create(t.image, not, context); }
    400413}
    401414
     
    550563
    551564JAVACODE
    552 void error_skipto(int kind) {
     565void error_skipto(int kind, MapCSSException me) {
    553566    if (token.kind == EOF)
    554567        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   
    556580    System.err.println("Skipping to the next rule, because of an error:");
    557581    System.err.println(e);
    558582    if (sheet != null) {
    559         sheet.logError(new ParseException(e.getMessage()));
     583        sheet.logError(e);
    560584    }
    561585    Token t;
Note: See TracChangeset for help on using the changeset viewer.