Skip to content

Commit 4d5d61d

Browse files
authored
Merge pull request #2388 from mgreter/bugfix/issue-2384
Implement unary slash expressions (#2349 and #2384)
2 parents 3c37c99 + d1e7c32 commit 4d5d61d

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/ast.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ namespace Sass {
12851285
////////////////////////////////////////////////////////////////////////////
12861286
class Unary_Expression : public Expression {
12871287
public:
1288-
enum Type { PLUS, MINUS, NOT };
1288+
enum Type { PLUS, MINUS, NOT, SLASH };
12891289
private:
12901290
HASH_PROPERTY(Type, optype)
12911291
HASH_PROPERTY(Expression_Obj, operand)
@@ -1304,6 +1304,7 @@ namespace Sass {
13041304
switch (optype_) {
13051305
case PLUS: return "plus";
13061306
case MINUS: return "minus";
1307+
case SLASH: return "slash";
13071308
case NOT: return "not";
13081309
default: return "invalid";
13091310
}

src/eval.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,10 @@ namespace Sass {
893893
cpy->value( - cpy->value() ); // negate value
894894
return cpy.detach(); // return the copy
895895
}
896+
else if (u->optype() == Unary_Expression::SLASH) {
897+
std::string str = '/' + nr->to_string(ctx.c_options);
898+
return SASS_MEMORY_NEW(String_Constant, u->pstate(), str);
899+
}
896900
// nothing for positive
897901
return nr.detach();
898902
}

src/inspect.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ namespace Sass {
497497

498498
void Inspect::operator()(Unary_Expression_Ptr expr)
499499
{
500-
if (expr->optype() == Unary_Expression::PLUS) append_string("+");
501-
else append_string("-");
500+
if (expr->optype() == Unary_Expression::PLUS) append_string("+");
501+
else if (expr->optype() == Unary_Expression::SLASH) append_string("/");
502+
else append_string("-");
502503
expr->operand()->perform(this);
503504
}
504505

src/parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,11 @@ namespace Sass {
14411441
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
14421442
return ex;
14431443
}
1444+
else if (lex< exactly<'/'> >()) {
1445+
Unary_Expression_Ptr ex = SASS_MEMORY_NEW(Unary_Expression, pstate, Unary_Expression::SLASH, parse_factor());
1446+
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
1447+
return ex;
1448+
}
14441449
else if (lex< sequence< kwd_not > >()) {
14451450
Unary_Expression_Ptr ex = SASS_MEMORY_NEW(Unary_Expression, pstate, Unary_Expression::NOT, parse_factor());
14461451
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());

0 commit comments

Comments
 (0)