Skip to content

Commit e2efacd

Browse files
committed
DRY up list parsing
1 parent 09f5d07 commit e2efacd

File tree

3 files changed

+36
-69
lines changed

3 files changed

+36
-69
lines changed

src/parser.cpp

Lines changed: 10 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,7 @@ namespace Sass {
10361036
{
10371037
// check if we have an empty list
10381038
// return the empty list as such
1039-
if (peek_css<
1040-
exactly<']'>
1041-
>(position))
1039+
if (peek_css< list_terminator >(position))
10421040
{
10431041
// return an empty list (nothing to delay)
10441042
return SASS_MEMORY_NEW(List, pstate, 0, SASS_SPACE, false, true);
@@ -1068,18 +1066,7 @@ namespace Sass {
10681066
while (lex_css< exactly<','> >())
10691067
{
10701068
// check for abort condition
1071-
if (peek_css< alternatives <
1072-
exactly<';'>,
1073-
exactly<'}'>,
1074-
exactly<'{'>,
1075-
exactly<')'>,
1076-
exactly<']'>,
1077-
exactly<':'>,
1078-
end_of_file,
1079-
exactly<ellipsis>,
1080-
default_flag,
1081-
global_flag
1082-
> >(position)
1069+
if (peek_css< list_terminator >(position)
10831070
) { break; }
10841071
// otherwise add another expression
10851072
bracketed_list->append(parse_space_list());
@@ -1101,19 +1088,7 @@ namespace Sass {
11011088
{
11021089
// check if we have an empty list
11031090
// return the empty list as such
1104-
if (peek_css< alternatives <
1105-
// exactly<'!'>,
1106-
exactly<';'>,
1107-
exactly<'}'>,
1108-
exactly<'{'>,
1109-
exactly<')'>,
1110-
exactly<']'>,
1111-
exactly<':'>,
1112-
end_of_file,
1113-
exactly<ellipsis>,
1114-
default_flag,
1115-
global_flag
1116-
> >(position))
1091+
if (peek_css< list_terminator >(position))
11171092
{
11181093
// return an empty list (nothing to delay)
11191094
return SASS_MEMORY_NEW(List, pstate, 0);
@@ -1137,18 +1112,7 @@ namespace Sass {
11371112
while (lex_css< exactly<','> >())
11381113
{
11391114
// check for abort condition
1140-
if (peek_css< alternatives <
1141-
exactly<';'>,
1142-
exactly<'}'>,
1143-
exactly<'{'>,
1144-
exactly<')'>,
1145-
exactly<']'>,
1146-
exactly<':'>,
1147-
end_of_file,
1148-
exactly<ellipsis>,
1149-
default_flag,
1150-
global_flag
1151-
> >(position)
1115+
if (peek_css< list_terminator >(position)
11521116
) { break; }
11531117
// otherwise add another expression
11541118
comma_list->append(parse_space_list());
@@ -1163,39 +1127,16 @@ namespace Sass {
11631127
{
11641128
Expression_Obj disj1 = parse_disjunction();
11651129
// if it's a singleton, return it (don't wrap it)
1166-
if (peek_css< alternatives <
1167-
// exactly<'!'>,
1168-
exactly<';'>,
1169-
exactly<'}'>,
1170-
exactly<'{'>,
1171-
exactly<')'>,
1172-
exactly<']'>,
1173-
exactly<','>,
1174-
exactly<':'>,
1175-
end_of_file,
1176-
exactly<ellipsis>,
1177-
default_flag,
1178-
global_flag
1179-
> >(position)
1180-
) { return disj1; }
1130+
if (peek_css< space_list_terminator >(position)
1131+
) {
1132+
return disj1; }
11811133

11821134
List_Obj space_list = SASS_MEMORY_NEW(List, pstate, 2, SASS_SPACE);
11831135
space_list->append(disj1);
11841136

1185-
while (!(peek_css< alternatives <
1186-
// exactly<'!'>,
1187-
exactly<';'>,
1188-
exactly<'}'>,
1189-
exactly<'{'>,
1190-
exactly<')'>,
1191-
exactly<']'>,
1192-
exactly<','>,
1193-
exactly<':'>,
1194-
end_of_file,
1195-
exactly<ellipsis>,
1196-
default_flag,
1197-
global_flag
1198-
> >(position)) && peek_css< optional_css_whitespace >() != end
1137+
while (
1138+
!(peek_css< space_list_terminator >(position)) &&
1139+
peek_css< optional_css_whitespace >() != end
11991140
) {
12001141
// the space is parsed implicitly?
12011142
space_list->append(parse_disjunction());

src/prelexer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,28 @@ namespace Sass {
14201420
>(src);
14211421
}
14221422

1423+
const char* list_terminator(const char* src) {
1424+
return alternatives <
1425+
exactly<';'>,
1426+
exactly<'}'>,
1427+
exactly<'{'>,
1428+
exactly<')'>,
1429+
exactly<']'>,
1430+
exactly<':'>,
1431+
end_of_file,
1432+
exactly<ellipsis>,
1433+
default_flag,
1434+
global_flag
1435+
>(src);
1436+
};
1437+
1438+
const char* space_list_terminator(const char* src) {
1439+
return alternatives <
1440+
exactly<','>,
1441+
list_terminator
1442+
>(src);
1443+
};
1444+
14231445

14241446
// const char* real_uri_prefix(const char* src) {
14251447
// return alternatives<

src/prelexer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ namespace Sass {
355355
const char* ie_keyword_arg_value(const char* src);
356356
const char* ie_keyword_arg_property(const char* src);
357357

358+
// characters that terminate parsing of a list
359+
const char* list_terminator(const char* src);
360+
const char* space_list_terminator(const char* src);
361+
358362
// match url()
359363
const char* H(const char* src);
360364
const char* W(const char* src);

0 commit comments

Comments
 (0)