@@ -66,13 +66,8 @@ namespace Sass {
66
66
lex< optional_spaces >();
67
67
Selector_Lookahead lookahead_result;
68
68
while (position < end) {
69
- if (lex< block_comment >()) {
70
- bool is_important = lexed.begin [2 ] == ' !' ;
71
- String* contents = parse_interpolated_chunk (lexed);
72
- Comment* comment = new (ctx.mem ) Comment (pstate, contents, is_important);
73
- (*root) << comment;
74
- }
75
- else if (peek< import >()) {
69
+ parse_block_comments (root);
70
+ if (peek< import >()) {
76
71
Import* imp = parse_import ();
77
72
if (!imp->urls ().empty ()) (*root) << imp;
78
73
if (!imp->files ().empty ()) {
@@ -483,10 +478,12 @@ namespace Sass {
483
478
group->last_block (block_stack.back ());
484
479
do {
485
480
reloop = false ;
486
- if (peek< exactly<' {' > >() ||
487
- peek< exactly<' }' > >() ||
488
- peek< exactly<' )' > >() ||
489
- peek< exactly<' ;' > >())
481
+ if (peek< alternatives <
482
+ exactly<' {' >,
483
+ exactly<' }' >,
484
+ exactly<' )' >,
485
+ exactly<' ;' >
486
+ > >())
490
487
break ; // in case there are superfluous commas at the end
491
488
Complex_Selector* comb = parse_selector_combination ();
492
489
if (!comb->has_reference () && !in_at_root) {
@@ -531,12 +528,13 @@ namespace Sass {
531
528
{
532
529
Position sel_source_position (-1 );
533
530
Compound_Selector* lhs;
534
- if (peek< exactly<' +' > >() ||
535
- peek< exactly<' ~' > >() ||
536
- peek< exactly<' >' > >()) {
537
- // no selector before the combinator
538
- lhs = 0 ;
539
- }
531
+ if (peek< alternatives <
532
+ exactly<' +' >,
533
+ exactly<' ~' >,
534
+ exactly<' >' >
535
+ > >())
536
+ // no selector before the combinator
537
+ { lhs = 0 ; }
540
538
else {
541
539
lhs = parse_simple_selector_sequence ();
542
540
sel_source_position = before_token;
@@ -551,15 +549,16 @@ namespace Sass {
551
549
bool cpx_lf = peek_newline ();
552
550
553
551
Complex_Selector* rhs;
554
- if (peek< exactly<' ,' > >() ||
555
- peek< exactly<' )' > >() ||
556
- peek< exactly<' {' > >() ||
557
- peek< exactly<' }' > >() ||
558
- peek< exactly<' ;' > >() ||
559
- peek< optional >()) {
560
- // no selector after the combinator
561
- rhs = 0 ;
562
- }
552
+ if (peek< alternatives <
553
+ exactly<' ,' >,
554
+ exactly<' )' >,
555
+ exactly<' {' >,
556
+ exactly<' }' >,
557
+ exactly<' ;' >,
558
+ optional
559
+ > >())
560
+ // no selector after the combinator
561
+ { rhs = 0 ; }
563
562
else {
564
563
rhs = parse_selector_combination ();
565
564
sel_source_position = before_token;
@@ -604,14 +603,15 @@ namespace Sass {
604
603
}
605
604
606
605
while (!peek< spaces >(position) &&
607
- !(peek < exactly<' +' > >(position) ||
608
- peek < exactly<' ~' > >(position) ||
609
- peek < exactly<' >' > >(position) ||
610
- peek < exactly<' ,' > >(position) ||
611
- peek < exactly<' )' > >(position) ||
612
- peek < exactly<' {' > >(position) ||
613
- peek < exactly<' }' > >(position) ||
614
- peek < exactly<' ;' > >(position))) {
606
+ !(peek < alternatives < exactly<' +' >,
607
+ exactly<' ~' >,
608
+ exactly<' >' >,
609
+ exactly<' ,' >,
610
+ exactly<' )' >,
611
+ exactly<' {' >,
612
+ exactly<' }' >,
613
+ exactly<' ;' >
614
+ > >(position))) {
615
615
(*seq) << parse_simple_selector ();
616
616
}
617
617
return seq;
@@ -751,6 +751,16 @@ namespace Sass {
751
751
return new (ctx.mem ) Attribute_Selector (p, name, matcher, value);
752
752
}
753
753
754
+ /* parse block comment and add to block */
755
+ void Parser::parse_block_comments (Block* block)
756
+ {
757
+ while (lex< block_comment >()) {
758
+ bool is_important = lexed.begin [2 ] == ' !' ;
759
+ String* contents = parse_interpolated_chunk (lexed);
760
+ (*block) << new (ctx.mem ) Comment (pstate, contents, is_important);
761
+ }
762
+ }
763
+
754
764
Block* Parser::parse_block ()
755
765
{
756
766
lex< exactly<' {' > >();
@@ -760,33 +770,18 @@ namespace Sass {
760
770
block_stack.push_back (block);
761
771
lex< zero_plus < alternatives < space, line_comment > > >();
762
772
// JMA - ensure that a block containing only block_comments is parsed
763
- while (lex< block_comment >()) {
764
- bool is_important = lexed.begin [2 ] == ' !' ;
765
- String* contents = parse_interpolated_chunk (lexed);
766
- Comment* comment = new (ctx.mem ) Comment (pstate, contents, is_important);
767
- (*block) << comment;
768
- }
773
+ parse_block_comments (block);
769
774
770
775
while (!lex< exactly<' }' > >()) {
776
+ parse_block_comments (block);
771
777
if (semicolon) {
772
778
if (!lex< one_plus< exactly<' ;' > > >()) {
773
779
error (" non-terminal statement or declaration must end with ';'" , pstate);
774
780
}
775
781
semicolon = false ;
776
- while (lex< block_comment >()) {
777
- bool is_important = lexed.begin [2 ] == ' !' ;
778
- String* contents = parse_interpolated_chunk (lexed);
779
- Comment* comment = new (ctx.mem ) Comment (pstate, contents, is_important);
780
- (*block) << comment;
781
- }
782
+ parse_block_comments (block);
782
783
if (lex< sequence< exactly<' }' >, zero_plus< exactly<' ;' > > > >()) break ;
783
784
}
784
- if (lex< block_comment >()) {
785
- bool is_important = lexed.begin [2 ] == ' !' ;
786
- String* contents = parse_interpolated_chunk (lexed);
787
- Comment* comment = new (ctx.mem ) Comment (pstate, contents, is_important);
788
- (*block) << comment;
789
- }
790
785
else if (peek< import >(position)) {
791
786
if (stack.back () == mixin_def || stack.back () == function_def) {
792
787
lex< import >(); // to adjust the before_token number
@@ -922,12 +917,7 @@ namespace Sass {
922
917
}
923
918
}
924
919
else lex< one_plus< exactly<' ;' > > >();
925
- while (lex< block_comment >()) {
926
- bool is_important = lexed.begin [2 ] == ' !' ;
927
- String* contents = parse_interpolated_chunk (lexed);
928
- Comment* comment = new (ctx.mem ) Comment (pstate, contents, is_important);
929
- (*block) << comment;
930
- }
920
+ parse_block_comments (block);
931
921
}
932
922
block_stack.pop_back ();
933
923
return block;
@@ -1018,13 +1008,15 @@ namespace Sass {
1018
1008
1019
1009
Expression* Parser::parse_comma_list ()
1020
1010
{
1021
- if (// peek< exactly<'!'> >(position) ||
1022
- peek< exactly<' ;' > >(position) ||
1023
- peek< exactly<' }' > >(position) ||
1024
- peek< exactly<' {' > >(position) ||
1025
- peek< exactly<' )' > >(position) ||
1026
- // peek< exactly<':'> >(position) ||
1027
- peek< exactly<ellipsis> >(position))
1011
+ if (peek< alternatives <
1012
+ // exactly<'!'>,
1013
+ // exactly<':'>,
1014
+ exactly<' ;' >,
1015
+ exactly<' }' >,
1016
+ exactly<' {' >,
1017
+ exactly<' )' >,
1018
+ exactly<ellipsis>
1019
+ > >(position))
1028
1020
{ return new (ctx.mem ) List (pstate, 0 ); }
1029
1021
Expression* list1 = parse_space_list ();
1030
1022
// if it's a singleton, return it directly; don't wrap it
@@ -1035,15 +1027,16 @@ namespace Sass {
1035
1027
1036
1028
while (lex< exactly<' ,' > >())
1037
1029
{
1038
- if (// peek< exactly<'!'> >(position) ||
1039
- peek< exactly<' ;' > >(position) ||
1040
- peek< exactly<' }' > >(position) ||
1041
- peek< exactly<' {' > >(position) ||
1042
- peek< exactly<' )' > >(position) ||
1043
- peek< exactly<' :' > >(position) ||
1044
- peek< exactly<ellipsis> >(position)) {
1045
- break ;
1046
- }
1030
+ if (peek< alternatives <
1031
+ // exactly<'!'>,
1032
+ exactly<' ;' >,
1033
+ exactly<' }' >,
1034
+ exactly<' {' >,
1035
+ exactly<' )' >,
1036
+ exactly<' :' >,
1037
+ exactly<ellipsis>
1038
+ > >(position)
1039
+ ) { break ; }
1047
1040
Expression* list = parse_space_list ();
1048
1041
(*comma_list) << list;
1049
1042
}
@@ -1055,32 +1048,36 @@ namespace Sass {
1055
1048
{
1056
1049
Expression* disj1 = parse_disjunction ();
1057
1050
// if it's a singleton, return it directly; don't wrap it
1058
- if (// peek< exactly<'!'> >(position) ||
1059
- peek< exactly<' ;' > >(position) ||
1060
- peek< exactly<' }' > >(position) ||
1061
- peek< exactly<' {' > >(position) ||
1062
- peek< exactly<' )' > >(position) ||
1063
- peek< exactly<' ,' > >(position) ||
1064
- peek< exactly<' :' > >(position) ||
1065
- peek< exactly<ellipsis> >(position) ||
1066
- peek< default_flag >(position) ||
1067
- peek< global_flag >(position))
1068
- { return disj1; }
1051
+ if (peek< alternatives <
1052
+ // exactly<'!'>,
1053
+ exactly<' ;' >,
1054
+ exactly<' }' >,
1055
+ exactly<' {' >,
1056
+ exactly<' )' >,
1057
+ exactly<' ,' >,
1058
+ exactly<' :' >,
1059
+ exactly<ellipsis>,
1060
+ default_flag,
1061
+ global_flag
1062
+ > >(position)
1063
+ ) { return disj1; }
1069
1064
1070
1065
List* space_list = new (ctx.mem ) List (pstate, 2 , List::SPACE);
1071
1066
(*space_list) << disj1;
1072
1067
1073
- while (!(// peek< exactly<'!'> >(position) ||
1074
- peek< exactly<' ;' > >(position) ||
1075
- peek< exactly<' }' > >(position) ||
1076
- peek< exactly<' {' > >(position) ||
1077
- peek< exactly<' )' > >(position) ||
1078
- peek< exactly<' ,' > >(position) ||
1079
- peek< exactly<' :' > >(position) ||
1080
- peek< exactly<ellipsis> >(position) ||
1081
- peek< default_flag >(position) ||
1082
- peek< global_flag >(position)))
1083
- {
1068
+ while (!(peek< alternatives <
1069
+ // exactly<'!'>,
1070
+ exactly<' ;' >,
1071
+ exactly<' }' >,
1072
+ exactly<' {' >,
1073
+ exactly<' )' >,
1074
+ exactly<' ,' >,
1075
+ exactly<' :' >,
1076
+ exactly<ellipsis>,
1077
+ default_flag,
1078
+ global_flag
1079
+ > >(position))
1080
+ ) {
1084
1081
(*space_list) << parse_disjunction ();
1085
1082
}
1086
1083
@@ -1117,12 +1114,13 @@ namespace Sass {
1117
1114
{
1118
1115
Expression* expr1 = parse_expression ();
1119
1116
// if it's a singleton, return it directly; don't wrap it
1120
- if (!(peek< eq_op >(position) ||
1121
- peek< neq_op >(position) ||
1122
- peek< gte_op >(position) ||
1123
- peek< gt_op >(position) ||
1124
- peek< lte_op >(position) ||
1125
- peek< lt_op >(position)))
1117
+ if (!(peek< alternatives < eq_op,
1118
+ neq_op,
1119
+ gte_op,
1120
+ gt_op,
1121
+ lte_op,
1122
+ lt_op
1123
+ > >(position)))
1126
1124
{ return expr1; }
1127
1125
1128
1126
Binary_Expression::Type op
0 commit comments