Skip to content

Commit 527fb9b

Browse files
committed
Implement unary slash expressions (#2349 and #2384)
1 parent 017be61 commit 527fb9b

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
@@ -1281,7 +1281,7 @@ namespace Sass {
12811281
////////////////////////////////////////////////////////////////////////////
12821282
class Unary_Expression : public Expression {
12831283
public:
1284-
enum Type { PLUS, MINUS, NOT };
1284+
enum Type { PLUS, MINUS, NOT, SLASH };
12851285
private:
12861286
HASH_PROPERTY(Type, optype)
12871287
HASH_PROPERTY(Expression_Obj, operand)
@@ -1300,6 +1300,7 @@ namespace Sass {
13001300
switch (optype_) {
13011301
case PLUS: return "plus";
13021302
case MINUS: return "minus";
1303+
case SLASH: return "slash";
13031304
case NOT: return "not";
13041305
default: return "invalid";
13051306
}

src/eval.cpp

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

src/inspect.cpp

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

476476
void Inspect::operator()(Unary_Expression_Ptr expr)
477477
{
478-
if (expr->optype() == Unary_Expression::PLUS) append_string("+");
479-
else append_string("-");
478+
if (expr->optype() == Unary_Expression::PLUS) append_string("+");
479+
else if (expr->optype() == Unary_Expression::SLASH) append_string("/");
480+
else append_string("-");
480481
expr->operand()->perform(this);
481482
}
482483

src/parser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,11 @@ namespace Sass {
14331433
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
14341434
return ex;
14351435
}
1436+
else if (lex< exactly<'/'> >()) {
1437+
Unary_Expression_Ptr ex = SASS_MEMORY_NEW(Unary_Expression, pstate, Unary_Expression::SLASH, parse_factor());
1438+
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
1439+
return ex;
1440+
}
14361441
else if (lex< sequence< kwd_not > >()) {
14371442
Unary_Expression_Ptr ex = SASS_MEMORY_NEW(Unary_Expression, pstate, Unary_Expression::NOT, parse_factor());
14381443
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());

0 commit comments

Comments
 (0)