Ignore:
Timestamp:
2013-12-29T12:03:21+01:00 (11 years ago)
Author:
simon04
Message:

see #9485 - MapCSS: add support for set class_name instruction and .class_name condition (which is specified in the MapCSS specification)

File:
1 edited

Legend:

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

    r6554 r6560  
    4242TOKEN:
    4343{
    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"] )* >
    4546|   < UINT: ["1"-"9"] ( ["0"-"9"] )* >
    4647|   < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? >
     
    7879|   < DOLLAR: "$" >
    7980|   < CARET: "^" >
     81|   < FULLSTOP: "." >
    8082|   < COMMENT_START: "/*" > : COMMENT
    8183|   < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from
     
    271273    (
    272274        ( <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); } )*
    274276        { selLink = new LinkSelector(conditions); }
    275277        w()
     
    290292    ( base=<IDENT> | base=<STAR> )
    291293    ( 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); } )*
    293295    ( sub=subpart() )?
    294296    { return new GeneralSelector(base.image, r, conditions, sub); }
     
    327329            c=simple_key_value_condition(context) s() <RSQUARE> { return c; }
    328330        |
    329             e=expression() <RSQUARE> { return Condition.create(e, context); }
     331            e=expression() <RSQUARE> { return Condition.createExpressionCondition(e, context); }
    330332    )
    331333}
     
    357359    ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { matchType = Condition.KeyMatchType.FALSE; } )?
    358360    (              <QUESTION>               { matchType = Condition.KeyMatchType.TRUE;  } )?
    359     { return Condition.create(key, not, matchType, context); }
     361    { return Condition.createKeyCondition(key, not, matchType, context); }
    360362}
    361363
     
    418420            f=float_() { val=Float.toString(f); }
    419421    )
    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
     425Condition class_or_pseudoclass(Context context) :
    424426{
    425427    Token t;
    426428    boolean not = false;
     429    boolean pseudo;
    427430}
    428431{
    429432    ( <EXCLAMATION> { not = true; } )?
    430     <COLON>
     433    (
     434        <FULLSTOP> { pseudo = false; }
     435    |
     436        <COLON> { pseudo = true; }
     437    )
    431438    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); }
    433442}
    434443
     
    448457    Instruction i;
    449458    Token key;
    450     Object val;
     459    Object val = null;
    451460}
    452461{
    453462    <LBRACE> w()
    454463    (
     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        |
    455471        key=<IDENT> w() <COLON> w()
    456472        (
Note: See TracChangeset for help on using the changeset viewer.