Commit ca5286a7 by Aaron Leung

Adding/refactoring some helper methods.

parent b19c9594
#include "context.hpp"
#include <iostream>
#include <unistd.h>
#include "prelexer.hpp"
using std::cerr; using std::endl;
namespace Sass {
......
......@@ -644,7 +644,6 @@ namespace Sass {
return new_Node(Node::boolean, val.path(), val.line(), false);
}
}
}
}
......@@ -9,6 +9,23 @@ namespace Sass {
// Node method implementations
// ------------------------------------------------------------------------
void Node::flatten()
{
if (type() != block && type() != expansion && type() != root) return;
for (size_t i = 0, S = size(); i < S; ++i) {
if (at(i).type() == expansion) {
Node expn(at(i));
if (expn.has_expansions()) expn.flatten();
ip_->has_statements |= expn.has_statements();
ip_->has_blocks |= expn.has_blocks();
ip_->has_expansions |= expn.has_expansions();
// leave the expansion node here and skip it during emission
insert(begin() + i, expn.begin(), expn.end());
}
}
}
bool Node::operator==(Node rhs) const
{
Type t = type();
......
......@@ -177,10 +177,18 @@ namespace Sass {
Node& operator<<(Node n);
Node& operator+=(Node n);
vector<Node>::iterator begin();
vector<Node>::iterator end();
void insert(vector<Node>::iterator position,
vector<Node>::iterator first,
vector<Node>::iterator last);
bool& boolean_value() const;
double numeric_value() const;
Token token() const;
Token unit() const;
void flatten();
bool operator==(Node rhs) const;
bool operator!=(Node rhs) const;
......@@ -322,6 +330,16 @@ namespace Sass {
for (size_t i = 0, L = n.size(); i < L; ++i) push_back(n[i]);
return *this;
}
inline vector<Node>::iterator Node::begin()
{ return ip_->children.begin(); }
inline vector<Node>::iterator Node::end()
{ return ip_->children.end(); }
inline void Node::insert(vector<Node>::iterator position,
vector<Node>::iterator first,
vector<Node>::iterator last)
{ ip_->children.insert(position, first, last); }
inline bool& Node::boolean_value() const { return ip_->boolean_value(); }
inline double Node::numeric_value() const { return ip_->numeric_value(); }
inline Token Node::token() const { return ip_->value.token; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment