Skip to content

Commit 7bdcd6a

Browse files
committed
Fix parsing of another missed block comment
Fixes #1021
1 parent d215db5 commit 7bdcd6a

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

constants.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ namespace Sass {
127127
extern const char map_name[] = "map";
128128
extern const char arglist_name[] = "arglist";
129129

130+
// some specific constant character classes
131+
// they must be static to be useable by lexer
132+
extern const char static_ops[] = "*/%";
133+
130134
// byte order marks
131135
// (taken from http://en.wikipedia.org/wiki/Byte_order_mark)
132136
extern const unsigned char utf_8_bom[] = { 0xEF, 0xBB, 0xBF };

constants.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ namespace Sass {
130130
extern const char map_name[];
131131
extern const char arglist_name[];
132132

133+
// some specific constant character classes
134+
// they must be static to be useable by lexer
135+
extern const char static_ops[];
136+
133137
// byte order marks
134138
// (taken from http://en.wikipedia.org/wiki/Byte_order_mark)
135139
extern const unsigned char utf_8_bom[];

parser.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,31 +1190,28 @@ namespace Sass {
11901190

11911191
Expression* Parser::parse_term()
11921192
{
1193-
Expression* fact1 = parse_factor();
1194-
1193+
Expression* factor = parse_factor();
11951194
// Special case: Ruby sass never tries to modulo if the lhs contains an interpolant
1196-
if (peek< exactly<'%'> >(position) && fact1->concrete_type() == Expression::STRING) {
1197-
String_Schema* ss = dynamic_cast<String_Schema*>(fact1);
1198-
if (ss && ss->has_interpolants()) return fact1;
1195+
if (peek_css< exactly<'%'> >(position) && factor->concrete_type() == Expression::STRING) {
1196+
String_Schema* ss = dynamic_cast<String_Schema*>(factor);
1197+
if (ss && ss->has_interpolants()) return factor;
11991198
}
1200-
12011199
// if it's a singleton, return it directly; don't wrap it
1202-
if (!(peek< exactly<'*'> >(position) ||
1203-
peek< exactly<'/'> >(position) ||
1204-
peek< exactly<'%'> >(position)))
1205-
{ return fact1; }
1206-
1207-
while (lex< block_comment >());
1208-
vector<Expression*> operands;
1209-
vector<Binary_Expression::Type> operators;
1210-
while (lex< exactly<'*'> >() || lex< exactly<'/'> >() || lex< exactly<'%'> >()) {
1211-
if (lexed.to_string() == "*") operators.push_back(Binary_Expression::MUL);
1212-
else if (lexed.to_string() == "/") operators.push_back(Binary_Expression::DIV);
1213-
else operators.push_back(Binary_Expression::MOD);
1200+
if (!peek< class_char< static_ops > >(position)) return factor;
1201+
// parse more factors and operators
1202+
vector<Expression*> operands; // factors
1203+
vector<Binary_Expression::Type> operators; // ops
1204+
while (lex_css< class_char< static_ops > >()) {
1205+
switch(*lexed.begin) {
1206+
case '*': operators.push_back(Binary_Expression::MUL); break;
1207+
case '/': operators.push_back(Binary_Expression::DIV); break;
1208+
case '%': operators.push_back(Binary_Expression::MOD); break;
1209+
default: throw runtime_error("unknown static op parsed"); break;
1210+
}
12141211
operands.push_back(parse_factor());
12151212
}
1216-
1217-
return fold_operands(fact1, operands, operators);
1213+
// operands and operators to binary expression
1214+
return fold_operands(factor, operands, operators);
12181215
}
12191216

12201217
Expression* Parser::parse_factor()

0 commit comments

Comments
 (0)