Skip to content

Commit

Permalink
Implement unary slash expressions (sass#2349 and sass#2384)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed May 20, 2017
1 parent 3c37c99 commit d1e7c32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ namespace Sass {
////////////////////////////////////////////////////////////////////////////
class Unary_Expression : public Expression {
public:
enum Type { PLUS, MINUS, NOT };
enum Type { PLUS, MINUS, NOT, SLASH };
private:
HASH_PROPERTY(Type, optype)
HASH_PROPERTY(Expression_Obj, operand)
Expand All @@ -1304,6 +1304,7 @@ namespace Sass {
switch (optype_) {
case PLUS: return "plus";
case MINUS: return "minus";
case SLASH: return "slash";
case NOT: return "not";
default: return "invalid";
}
Expand Down
4 changes: 4 additions & 0 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,10 @@ namespace Sass {
cpy->value( - cpy->value() ); // negate value
return cpy.detach(); // return the copy
}
else if (u->optype() == Unary_Expression::SLASH) {
std::string str = '/' + nr->to_string(ctx.c_options);
return SASS_MEMORY_NEW(String_Constant, u->pstate(), str);
}
// nothing for positive
return nr.detach();
}
Expand Down
5 changes: 3 additions & 2 deletions src/inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ namespace Sass {

void Inspect::operator()(Unary_Expression_Ptr expr)
{
if (expr->optype() == Unary_Expression::PLUS) append_string("+");
else append_string("-");
if (expr->optype() == Unary_Expression::PLUS) append_string("+");
else if (expr->optype() == Unary_Expression::SLASH) append_string("/");
else append_string("-");
expr->operand()->perform(this);
}

Expand Down
5 changes: 5 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,11 @@ namespace Sass {
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
return ex;
}
else if (lex< exactly<'/'> >()) {
Unary_Expression_Ptr ex = SASS_MEMORY_NEW(Unary_Expression, pstate, Unary_Expression::SLASH, parse_factor());
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
return ex;
}
else if (lex< sequence< kwd_not > >()) {
Unary_Expression_Ptr ex = SASS_MEMORY_NEW(Unary_Expression, pstate, Unary_Expression::NOT, parse_factor());
if (ex && ex->operand()) ex->is_delayed(ex->operand()->is_delayed());
Expand Down

0 comments on commit d1e7c32

Please sign in to comment.