Ticket #10066: parser.jj.patch

File parser.jj.patch, 10.8 KB (added by simon04, 12 years ago)
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj b/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
    index bf50fd0..6049f80 100644
    a b TOKEN:  
    154154    < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? >
    155155|   < #H: ["0"-"9","a"-"f","A"-"F"] >
    156156|   < HEXCOLOR: "#" ( <H><H><H><H><H><H><H><H> | <H><H><H><H><H><H> | <H><H><H> ) >
    157 |   < S: ( " " | "\t" | "\n" | "\r" | "\f" )+ >
    158157|   < STAR: "*" >
    159158|   < SLASH: "/" >
    160159|   < LSQUARE: "[" >
    TOKEN:  
    180179|   < FULLSTOP: "." >
    181180|   < ELEMENT_OF: "∈" >
    182181|   < CROSSING: "⧉" >
     182}
     183
     184<DEFAULT>
     185SKIP:
     186{
     187    < S: ( " " | "\t" | "\n" | "\r" | "\f" )+ >
    183188|   < COMMENT_START: "/*" > : COMMENT
    184 |   < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from
    185189}
    186190
    187191<COMMENT>
    188 TOKEN:
     192SKIP:
    189193{
    190194    < COMMENT_END: "*/" > : DEFAULT
     195|   < ~[] >
    191196}
    192197
    193 <COMMENT>
    194 SKIP:
    195 {
    196     < ~[] >
    197 }
    198 
    199 
    200198/*************
    201199 *
    202200 * Preprocessor parser definitions:
    String regex() :  
    428426}
    429427
    430428/**
    431  * white-space
    432  */
    433 void s() :
    434 {
    435 }
    436 {
    437     ( <S> )?
    438 }
    439 
    440 /**
    441  * mix of white-space and comments
    442  */
    443 void w() :
    444 {
    445 }
    446 {
    447     ( <S> | <COMMENT_START> <COMMENT_END> )*
    448 }
    449 
    450 /**
    451429 * comma delimited list of floats (at least 2, all &gt;= 0)
    452430 */
    453431List<Float> float_array() :
    List<Float> float_array() :  
    458436{
    459437    f=ufloat() { fs.add(f); }
    460438    (
    461         <COMMA> s()
     439        <COMMA>
    462440        f=ufloat() { fs.add(f); }
    463441    )+
    464442    {
    void sheet(MapCSSStyleSource sheet):  
    474452}
    475453{
    476454    { this.sheet = sheet; }
    477     w()
    478455    (
    479456        try {
    480             rule() w()
     457            rule()
    481458        } catch (MapCSSException mex) {
    482459            error_skipto(RBRACE, mex);
    483             w();
     460            ;
    484461        } catch (ParseException ex) {
    485462            error_skipto(RBRACE, null);
    486             w();
     463            ;
    487464        }
    488465    )*
    489466    <EOF>
    void rule():  
    498475{
    499476    sel=child_selector() { selectors.add(sel); }
    500477    (
    501         <COMMA> w()
     478        <COMMA>
    502479        sel=child_selector() { selectors.add(sel); }
    503480    )*
    504481    decl=declaration()
    Selector child_selector() :  
    519496    Selector selRight = null;
    520497}
    521498{
    522     selLeft=selector() w()
     499    selLeft=selector()
    523500    (
    524501        (
    525502            (
    Selector child_selector() :  
    536513            |
    537514                <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; }
    538515            )
    539             w()
    540516        |
    541517            { /* <GREATER> is optional for child selector */ type = Selector.ChildOrParentSelectorType.CHILD; }
    542518        )
    543519        { selLink = new LinkSelector(conditions); }
    544         selRight=selector() w()
     520        selRight=selector()
    545521    )?
    546522    { return selRight != null ? new ChildOrParentSelector(selLeft, selLink, selRight, type) : selLeft; }
    547523}
    Condition condition(Context context) :  
    586562    Expression e;
    587563}
    588564{
    589     <LSQUARE> s()
     565    <LSQUARE>
    590566    (
    591         LOOKAHEAD( simple_key_condition(context) s() <RSQUARE> )
    592             c=simple_key_condition(context) s() <RSQUARE> { return c; }
     567        LOOKAHEAD( simple_key_condition(context) <RSQUARE> )
     568            c=simple_key_condition(context) <RSQUARE> { return c; }
    593569        |
    594         LOOKAHEAD( simple_key_value_condition(context) s() <RSQUARE> )
    595             c=simple_key_value_condition(context) s() <RSQUARE> { return c; }
     570        LOOKAHEAD( simple_key_value_condition(context) <RSQUARE> )
     571            c=simple_key_value_condition(context) <RSQUARE> { return c; }
    596572        |
    597573            e=expression() <RSQUARE> { return Condition.createExpressionCondition(e, context); }
    598574    )
    Condition simple_key_value_condition(Context context) :  
    637613    boolean considerValAsKey = false;
    638614}
    639615{
    640     key=tag_key() s()
     616    key=tag_key()
    641617    (
    642618        LOOKAHEAD(3)
    643619            (
    Condition simple_key_value_condition(Context context) :  
    645621                |
    646622                    <EXCLAMATION> <TILDE> { op=Condition.Op.NREGEX; }
    647623            )
    648             s()
    649624            ( <STAR> { considerValAsKey=true; } )?
    650625            val=regex()
    651626        |
    Condition simple_key_value_condition(Context context) :  
    662637                |
    663638                    <STAR> <EQUAL> { op=Condition.Op.CONTAINS; }
    664639            )
    665             s()
    666640            ( <STAR> { considerValAsKey=true; } )?
    667641            (
    668642                LOOKAHEAD(2)
    Condition simple_key_value_condition(Context context) :  
    682656                |
    683657                    <LESS> { op=Condition.Op.LESS; }
    684658            )
    685             s()
    686659            f=float_() { val=Float.toString(f); }
    687660    )
    688661    { return Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); }
    Declaration declaration() :  
    724697    Object val = null;
    725698}
    726699{
    727     <LBRACE> w()
     700    <LBRACE>
    728701    (
    729702        (
    730             <SET> w()
     703            <SET>
    731704            (<FULLSTOP>)? // specification allows "set .class" to set "class". we also support "set class"
    732             key=<IDENT> w()
     705            key=<IDENT>
    733706            ( <EQUAL> val=expression() )?
    734707            { ins.add(new Instruction.AssignmentInstruction(key.image, val == null ? true : val, true)); }
    735             ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() )
     708            ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> )
    736709        )
    737710    |
    738         key=<IDENT> w() <COLON> w()
     711        key=<IDENT> <COLON>
    739712        (
    740             LOOKAHEAD( float_array() w() ( <SEMICOLON> | <RBRACE> ) )
     713            LOOKAHEAD( float_array() ( <SEMICOLON> | <RBRACE> ) )
    741714                val=float_array()
    742715                { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
    743                 w()
    744                 ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() )
     716               
     717                ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> )
    745718            |
    746719            LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) )
    747720                val=expression()
    748721                { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
    749                 ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> w() )
     722                ( <RBRACE> { return new Declaration(ins, declarationCounter++); } | <SEMICOLON> )
    750723            |
    751                 val=readRaw() w() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
     724                val=readRaw() { ins.add(new Instruction.AssignmentInstruction(key.image, val, false)); }
    752725        )
    753726    )*
    754727    <RBRACE>
    Expression expression():  
    763736}
    764737{
    765738    (
    766         <EXCLAMATION> { op = "not"; } w() e=primary() { args.add(e); } w()
     739        <EXCLAMATION> { op = "not"; } e=primary() { args.add(e); }
    767740    |
    768         <MINUS> { op = "minus"; } w() e=primary() { args.add(e); } w()
     741        <MINUS> { op = "minus"; } e=primary() { args.add(e); }
    769742    |
    770743
    771744        (
    772             e=primary() { args.add(e); } w()
     745            e=primary() { args.add(e); }
    773746            (
    774                     ( <PLUS> { op = "plus"; } w() e=primary() { args.add(e); } w() )+
     747                    ( <PLUS> { op = "plus"; } e=primary() { args.add(e); } )+
    775748                |
    776                     ( <STAR> { op = "times"; } w() e=primary() { args.add(e); } w() )+
     749                    ( <STAR> { op = "times"; } e=primary() { args.add(e); } )+
    777750                |
    778                     ( <MINUS> { op = "minus"; } w() e=primary() { args.add(e); } w() )+
     751                    ( <MINUS> { op = "minus"; } e=primary() { args.add(e); } )+
    779752                |
    780                     ( <SLASH> { op = "divided_by"; } w() e=primary() { args.add(e); } w() )+
     753                    ( <SLASH> { op = "divided_by"; } e=primary() { args.add(e); } )+
    781754                |
    782                     <GREATER_EQUAL> { op = "greater_equal"; } w() e=primary() { args.add(e); } w()
     755                    <GREATER_EQUAL> { op = "greater_equal"; } e=primary() { args.add(e); }
    783756                |
    784                     <LESS_EQUAL> { op = "less_equal"; } w() e=primary() { args.add(e); } w()
     757                    <LESS_EQUAL> { op = "less_equal"; } e=primary() { args.add(e); }
    785758                |
    786                     <GREATER> { op = "greater"; } w() e=primary() { args.add(e); } w()
     759                    <GREATER> { op = "greater"; } e=primary() { args.add(e); }
    787760                |
    788                     <EQUAL> ( <EQUAL> )? { op = "equal"; } w() e=primary() { args.add(e); } w()
     761                    <EQUAL> ( <EQUAL> )? { op = "equal"; } e=primary() { args.add(e); }
    789762                |
    790                     <LESS> { op = "less"; } w() e=primary() { args.add(e); } w()
     763                    <LESS> { op = "less"; } e=primary() { args.add(e); }
    791764                |
    792                     <AMPERSAND> <AMPERSAND> { op = "and"; } w() e=primary() { args.add(e); } w()
     765                    <AMPERSAND> <AMPERSAND> { op = "and"; } e=primary() { args.add(e); }
    793766                |
    794                     <PIPE> <PIPE> { op = "or"; } w() e=primary() { args.add(e); } w()
     767                    <PIPE> <PIPE> { op = "or"; } e=primary() { args.add(e); }
    795768                |
    796                     <QUESTION> { op = "cond"; } w() e=primary() { args.add(e); } w() <COLON> w() e=primary() { args.add(e); } w()
     769                    <QUESTION> { op = "cond"; } e=primary() { args.add(e); } <COLON> e=primary() { args.add(e); }
    797770            )?
    798771        )
    799772    )
    Expression primary() :  
    816789    |
    817790        lit=literal() { return new LiteralExpression(lit); }
    818791    |
    819         <LPAR> w() nested=expression() <RPAR> { return nested; }
     792        <LPAR> nested=expression() <RPAR> { return nested; }
    820793}
    821794
    822795Expression function() :
    Expression function() :  
    826799    List<Expression> args = new ArrayList<Expression>();
    827800}
    828801{
    829     name=ident() w()
    830     <LPAR> w()
     802    name=ident()
     803    <LPAR>
    831804    (
    832805        arg=expression() { args.add(arg); }
    833         ( <COMMA> w() arg=expression() { args.add(arg); } )*
     806        ( <COMMA> arg=expression() { args.add(arg); } )*
    834807    )?
    835808    <RPAR>
    836809    { return ExpressionFactory.createFunctionExpression(name, args); }
    String readRaw() {  
    896869    StringBuilder s = new StringBuilder();
    897870    while (true) {
    898871        t = getNextToken();
    899         if ((t.kind == S || t.kind == STRING || t.kind == UNEXPECTED_CHAR) &&
     872        if ((t.kind == S || t.kind == STRING) &&
    900873                t.image.contains("\n")) {
    901874            ParseException e = new ParseException(String.format("Warning: end of line while reading an unquoted string at line %s column %s.", t.beginLine, t.beginColumn));
    902875            Main.error(e);