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:
|
| 154 | 154 | < UFLOAT: ( ["0"-"9"] )+ ( "." ( ["0"-"9"] )+ )? > |
| 155 | 155 | | < #H: ["0"-"9","a"-"f","A"-"F"] > |
| 156 | 156 | | < HEXCOLOR: "#" ( <H><H><H><H><H><H><H><H> | <H><H><H><H><H><H> | <H><H><H> ) > |
| 157 | | | < S: ( " " | "\t" | "\n" | "\r" | "\f" )+ > |
| 158 | 157 | | < STAR: "*" > |
| 159 | 158 | | < SLASH: "/" > |
| 160 | 159 | | < LSQUARE: "[" > |
| … |
… |
TOKEN:
|
| 180 | 179 | | < FULLSTOP: "." > |
| 181 | 180 | | < ELEMENT_OF: "∈" > |
| 182 | 181 | | < CROSSING: "⧉" > |
| | 182 | } |
| | 183 | |
| | 184 | <DEFAULT> |
| | 185 | SKIP: |
| | 186 | { |
| | 187 | < S: ( " " | "\t" | "\n" | "\r" | "\f" )+ > |
| 183 | 188 | | < COMMENT_START: "/*" > : COMMENT |
| 184 | | | < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from |
| 185 | 189 | } |
| 186 | 190 | |
| 187 | 191 | <COMMENT> |
| 188 | | TOKEN: |
| | 192 | SKIP: |
| 189 | 193 | { |
| 190 | 194 | < COMMENT_END: "*/" > : DEFAULT |
| | 195 | | < ~[] > |
| 191 | 196 | } |
| 192 | 197 | |
| 193 | | <COMMENT> |
| 194 | | SKIP: |
| 195 | | { |
| 196 | | < ~[] > |
| 197 | | } |
| 198 | | |
| 199 | | |
| 200 | 198 | /************* |
| 201 | 199 | * |
| 202 | 200 | * Preprocessor parser definitions: |
| … |
… |
String regex() :
|
| 428 | 426 | } |
| 429 | 427 | |
| 430 | 428 | /** |
| 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 | | /** |
| 451 | 429 | * comma delimited list of floats (at least 2, all >= 0) |
| 452 | 430 | */ |
| 453 | 431 | List<Float> float_array() : |
| … |
… |
List<Float> float_array() :
|
| 458 | 436 | { |
| 459 | 437 | f=ufloat() { fs.add(f); } |
| 460 | 438 | ( |
| 461 | | <COMMA> s() |
| | 439 | <COMMA> |
| 462 | 440 | f=ufloat() { fs.add(f); } |
| 463 | 441 | )+ |
| 464 | 442 | { |
| … |
… |
void sheet(MapCSSStyleSource sheet):
|
| 474 | 452 | } |
| 475 | 453 | { |
| 476 | 454 | { this.sheet = sheet; } |
| 477 | | w() |
| 478 | 455 | ( |
| 479 | 456 | try { |
| 480 | | rule() w() |
| | 457 | rule() |
| 481 | 458 | } catch (MapCSSException mex) { |
| 482 | 459 | error_skipto(RBRACE, mex); |
| 483 | | w(); |
| | 460 | ; |
| 484 | 461 | } catch (ParseException ex) { |
| 485 | 462 | error_skipto(RBRACE, null); |
| 486 | | w(); |
| | 463 | ; |
| 487 | 464 | } |
| 488 | 465 | )* |
| 489 | 466 | <EOF> |
| … |
… |
void rule():
|
| 498 | 475 | { |
| 499 | 476 | sel=child_selector() { selectors.add(sel); } |
| 500 | 477 | ( |
| 501 | | <COMMA> w() |
| | 478 | <COMMA> |
| 502 | 479 | sel=child_selector() { selectors.add(sel); } |
| 503 | 480 | )* |
| 504 | 481 | decl=declaration() |
| … |
… |
Selector child_selector() :
|
| 519 | 496 | Selector selRight = null; |
| 520 | 497 | } |
| 521 | 498 | { |
| 522 | | selLeft=selector() w() |
| | 499 | selLeft=selector() |
| 523 | 500 | ( |
| 524 | 501 | ( |
| 525 | 502 | ( |
| … |
… |
Selector child_selector() :
|
| 536 | 513 | | |
| 537 | 514 | <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; } |
| 538 | 515 | ) |
| 539 | | w() |
| 540 | 516 | | |
| 541 | 517 | { /* <GREATER> is optional for child selector */ type = Selector.ChildOrParentSelectorType.CHILD; } |
| 542 | 518 | ) |
| 543 | 519 | { selLink = new LinkSelector(conditions); } |
| 544 | | selRight=selector() w() |
| | 520 | selRight=selector() |
| 545 | 521 | )? |
| 546 | 522 | { return selRight != null ? new ChildOrParentSelector(selLeft, selLink, selRight, type) : selLeft; } |
| 547 | 523 | } |
| … |
… |
Condition condition(Context context) :
|
| 586 | 562 | Expression e; |
| 587 | 563 | } |
| 588 | 564 | { |
| 589 | | <LSQUARE> s() |
| | 565 | <LSQUARE> |
| 590 | 566 | ( |
| 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; } |
| 593 | 569 | | |
| 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; } |
| 596 | 572 | | |
| 597 | 573 | e=expression() <RSQUARE> { return Condition.createExpressionCondition(e, context); } |
| 598 | 574 | ) |
| … |
… |
Condition simple_key_value_condition(Context context) :
|
| 637 | 613 | boolean considerValAsKey = false; |
| 638 | 614 | } |
| 639 | 615 | { |
| 640 | | key=tag_key() s() |
| | 616 | key=tag_key() |
| 641 | 617 | ( |
| 642 | 618 | LOOKAHEAD(3) |
| 643 | 619 | ( |
| … |
… |
Condition simple_key_value_condition(Context context) :
|
| 645 | 621 | | |
| 646 | 622 | <EXCLAMATION> <TILDE> { op=Condition.Op.NREGEX; } |
| 647 | 623 | ) |
| 648 | | s() |
| 649 | 624 | ( <STAR> { considerValAsKey=true; } )? |
| 650 | 625 | val=regex() |
| 651 | 626 | | |
| … |
… |
Condition simple_key_value_condition(Context context) :
|
| 662 | 637 | | |
| 663 | 638 | <STAR> <EQUAL> { op=Condition.Op.CONTAINS; } |
| 664 | 639 | ) |
| 665 | | s() |
| 666 | 640 | ( <STAR> { considerValAsKey=true; } )? |
| 667 | 641 | ( |
| 668 | 642 | LOOKAHEAD(2) |
| … |
… |
Condition simple_key_value_condition(Context context) :
|
| 682 | 656 | | |
| 683 | 657 | <LESS> { op=Condition.Op.LESS; } |
| 684 | 658 | ) |
| 685 | | s() |
| 686 | 659 | f=float_() { val=Float.toString(f); } |
| 687 | 660 | ) |
| 688 | 661 | { return Condition.createKeyValueCondition(key, val, op, context, considerValAsKey); } |
| … |
… |
Declaration declaration() :
|
| 724 | 697 | Object val = null; |
| 725 | 698 | } |
| 726 | 699 | { |
| 727 | | <LBRACE> w() |
| | 700 | <LBRACE> |
| 728 | 701 | ( |
| 729 | 702 | ( |
| 730 | | <SET> w() |
| | 703 | <SET> |
| 731 | 704 | (<FULLSTOP>)? // specification allows "set .class" to set "class". we also support "set class" |
| 732 | | key=<IDENT> w() |
| | 705 | key=<IDENT> |
| 733 | 706 | ( <EQUAL> val=expression() )? |
| 734 | 707 | { 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> ) |
| 736 | 709 | ) |
| 737 | 710 | | |
| 738 | | key=<IDENT> w() <COLON> w() |
| | 711 | key=<IDENT> <COLON> |
| 739 | 712 | ( |
| 740 | | LOOKAHEAD( float_array() w() ( <SEMICOLON> | <RBRACE> ) ) |
| | 713 | LOOKAHEAD( float_array() ( <SEMICOLON> | <RBRACE> ) ) |
| 741 | 714 | val=float_array() |
| 742 | 715 | { 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> ) |
| 745 | 718 | | |
| 746 | 719 | LOOKAHEAD( expression() ( <SEMICOLON> | <RBRACE> ) ) |
| 747 | 720 | val=expression() |
| 748 | 721 | { 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> ) |
| 750 | 723 | | |
| 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)); } |
| 752 | 725 | ) |
| 753 | 726 | )* |
| 754 | 727 | <RBRACE> |
| … |
… |
Expression expression():
|
| 763 | 736 | } |
| 764 | 737 | { |
| 765 | 738 | ( |
| 766 | | <EXCLAMATION> { op = "not"; } w() e=primary() { args.add(e); } w() |
| | 739 | <EXCLAMATION> { op = "not"; } e=primary() { args.add(e); } |
| 767 | 740 | | |
| 768 | | <MINUS> { op = "minus"; } w() e=primary() { args.add(e); } w() |
| | 741 | <MINUS> { op = "minus"; } e=primary() { args.add(e); } |
| 769 | 742 | | |
| 770 | 743 | |
| 771 | 744 | ( |
| 772 | | e=primary() { args.add(e); } w() |
| | 745 | e=primary() { args.add(e); } |
| 773 | 746 | ( |
| 774 | | ( <PLUS> { op = "plus"; } w() e=primary() { args.add(e); } w() )+ |
| | 747 | ( <PLUS> { op = "plus"; } e=primary() { args.add(e); } )+ |
| 775 | 748 | | |
| 776 | | ( <STAR> { op = "times"; } w() e=primary() { args.add(e); } w() )+ |
| | 749 | ( <STAR> { op = "times"; } e=primary() { args.add(e); } )+ |
| 777 | 750 | | |
| 778 | | ( <MINUS> { op = "minus"; } w() e=primary() { args.add(e); } w() )+ |
| | 751 | ( <MINUS> { op = "minus"; } e=primary() { args.add(e); } )+ |
| 779 | 752 | | |
| 780 | | ( <SLASH> { op = "divided_by"; } w() e=primary() { args.add(e); } w() )+ |
| | 753 | ( <SLASH> { op = "divided_by"; } e=primary() { args.add(e); } )+ |
| 781 | 754 | | |
| 782 | | <GREATER_EQUAL> { op = "greater_equal"; } w() e=primary() { args.add(e); } w() |
| | 755 | <GREATER_EQUAL> { op = "greater_equal"; } e=primary() { args.add(e); } |
| 783 | 756 | | |
| 784 | | <LESS_EQUAL> { op = "less_equal"; } w() e=primary() { args.add(e); } w() |
| | 757 | <LESS_EQUAL> { op = "less_equal"; } e=primary() { args.add(e); } |
| 785 | 758 | | |
| 786 | | <GREATER> { op = "greater"; } w() e=primary() { args.add(e); } w() |
| | 759 | <GREATER> { op = "greater"; } e=primary() { args.add(e); } |
| 787 | 760 | | |
| 788 | | <EQUAL> ( <EQUAL> )? { op = "equal"; } w() e=primary() { args.add(e); } w() |
| | 761 | <EQUAL> ( <EQUAL> )? { op = "equal"; } e=primary() { args.add(e); } |
| 789 | 762 | | |
| 790 | | <LESS> { op = "less"; } w() e=primary() { args.add(e); } w() |
| | 763 | <LESS> { op = "less"; } e=primary() { args.add(e); } |
| 791 | 764 | | |
| 792 | | <AMPERSAND> <AMPERSAND> { op = "and"; } w() e=primary() { args.add(e); } w() |
| | 765 | <AMPERSAND> <AMPERSAND> { op = "and"; } e=primary() { args.add(e); } |
| 793 | 766 | | |
| 794 | | <PIPE> <PIPE> { op = "or"; } w() e=primary() { args.add(e); } w() |
| | 767 | <PIPE> <PIPE> { op = "or"; } e=primary() { args.add(e); } |
| 795 | 768 | | |
| 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); } |
| 797 | 770 | )? |
| 798 | 771 | ) |
| 799 | 772 | ) |
| … |
… |
Expression primary() :
|
| 816 | 789 | | |
| 817 | 790 | lit=literal() { return new LiteralExpression(lit); } |
| 818 | 791 | | |
| 819 | | <LPAR> w() nested=expression() <RPAR> { return nested; } |
| | 792 | <LPAR> nested=expression() <RPAR> { return nested; } |
| 820 | 793 | } |
| 821 | 794 | |
| 822 | 795 | Expression function() : |
| … |
… |
Expression function() :
|
| 826 | 799 | List<Expression> args = new ArrayList<Expression>(); |
| 827 | 800 | } |
| 828 | 801 | { |
| 829 | | name=ident() w() |
| 830 | | <LPAR> w() |
| | 802 | name=ident() |
| | 803 | <LPAR> |
| 831 | 804 | ( |
| 832 | 805 | arg=expression() { args.add(arg); } |
| 833 | | ( <COMMA> w() arg=expression() { args.add(arg); } )* |
| | 806 | ( <COMMA> arg=expression() { args.add(arg); } )* |
| 834 | 807 | )? |
| 835 | 808 | <RPAR> |
| 836 | 809 | { return ExpressionFactory.createFunctionExpression(name, args); } |
| … |
… |
String readRaw() {
|
| 896 | 869 | StringBuilder s = new StringBuilder(); |
| 897 | 870 | while (true) { |
| 898 | 871 | t = getNextToken(); |
| 899 | | if ((t.kind == S || t.kind == STRING || t.kind == UNEXPECTED_CHAR) && |
| | 872 | if ((t.kind == S || t.kind == STRING) && |
| 900 | 873 | t.image.contains("\n")) { |
| 901 | 874 | ParseException e = new ParseException(String.format("Warning: end of line while reading an unquoted string at line %s column %s.", t.beginLine, t.beginColumn)); |
| 902 | 875 | Main.error(e); |