Commit df9b4e6a by Aaron Leung

Selector interpolation works robustly (sans a few special cases).

parent bf146431
...@@ -60,17 +60,18 @@ namespace Sass { ...@@ -60,17 +60,18 @@ namespace Sass {
return doc; return doc;
} }
Document Document::make_from_source_chars(Context& ctx, char* src, string path) Document Document::make_from_source_chars(Context& ctx, char* src, string path, bool own_source)
{ {
Document doc(ctx); Document doc(ctx);
doc.path = path; doc.path = path;
doc.line = 1; doc.line = 1;
doc.root = ctx.new_Node(Node::root, path, 1, 0); doc.root = ctx.new_Node(Node::root, path, 1, 0);
doc.lexed = Token::make(); doc.lexed = Token::make();
doc.own_source = false; doc.own_source = own_source;
doc.source = src; doc.source = src;
doc.end = src + std::strlen(src); doc.end = src + std::strlen(src);
doc.position = doc.end; doc.position = src;
if (own_source) doc.context.source_refs.push_back(src);
return doc; return doc;
} }
......
#include <map> #include <map>
#ifndef SASS_PRELEXER_INCLUDED
#include "prelexer.hpp"
#endif
#ifndef SASS_NODE_INCLUDED #ifndef SASS_NODE_INCLUDED
#include "node.hpp" #include "node.hpp"
#endif #endif
#include "prelexer.hpp" #ifndef SASS_CONTEXT_INCLUDED
#include "context.hpp" #include "context.hpp"
#endif
struct Selector_Lookahead { struct Selector_Lookahead {
const char* found; const char* found;
...@@ -41,7 +46,7 @@ namespace Sass { ...@@ -41,7 +46,7 @@ namespace Sass {
~Document(); ~Document();
static Document make_from_file(Context& ctx, string path); static Document make_from_file(Context& ctx, string path);
static Document make_from_source_chars(Context& ctx, char* src, string path = ""); static Document make_from_source_chars(Context& ctx, char* src, string path = "", bool own_source = false);
static Document make_from_token(Context& ctx, Token t, string path = "", size_t line_number = 1); static Document make_from_token(Context& ctx, Token t, string path = "", size_t line_number = 1);
template <prelexer mx> template <prelexer mx>
......
...@@ -898,6 +898,10 @@ namespace Sass { ...@@ -898,6 +898,10 @@ namespace Sass {
prefix_match, prefix_match,
suffix_match, suffix_match,
substring_match> >(p)) || substring_match> >(p)) ||
(q = peek< sequence< exactly<'.'>, interpolant > >(p)) ||
(q = peek< sequence< exactly<'#'>, interpolant > >(p)) ||
(q = peek< sequence< exactly<'-'>, interpolant > >(p)) ||
(q = peek< sequence< pseudo_prefix, interpolant > >(p)) ||
(q = peek< interpolant >(p))) { (q = peek< interpolant >(p))) {
p = q; p = q;
if (*(p - 1) == '}') saw_interpolant = true; if (*(p - 1) == '}') saw_interpolant = true;
......
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
namespace Sass { namespace Sass {
using std::map; using std::map;
Node eval(Node& expr, Environment& env, map<pair<string, size_t>, Function>& f_env, Node_Factory& new_Node); Node eval(Node& expr, Environment& env, map<pair<string, size_t>, Function>& f_env, Node_Factory& new_Node, Context& src_refs);
Node accumulate(Node::Type op, Node& acc, Node& rhs, Node_Factory& new_Node); Node accumulate(Node::Type op, Node& acc, Node& rhs, Node_Factory& new_Node);
double operate(Node::Type op, double lhs, double rhs); double operate(Node::Type op, double lhs, double rhs);
Node apply_mixin(Node& mixin, const Node& args, Environment& env, map<pair<string, size_t>, Function>& f_env, Node_Factory& new_Node); Node apply_mixin(Node& mixin, const Node& args, Environment& env, map<pair<string, size_t>, Function>& f_env, Node_Factory& new_Node, Context& src_refs);
Node apply_function(const Function& f, const Node& args, Environment& env, map<pair<string, size_t>, Function>& f_env, Node_Factory& new_Node); Node apply_function(const Function& f, const Node& args, Environment& env, map<pair<string, size_t>, Function>& f_env, Node_Factory& new_Node, Context& src_refs);
} }
\ No newline at end of file
...@@ -39,21 +39,8 @@ extern "C" { ...@@ -39,21 +39,8 @@ extern "C" {
{ {
using namespace Sass; using namespace Sass;
doc.parse_scss(); doc.parse_scss();
// cerr << "PARSED" << endl; eval(doc.root, doc.context.global_env, doc.context.function_env, doc.context.new_Node, doc.context);
eval(doc.root, doc.context.global_env, doc.context.function_env, doc.context.new_Node);
// cerr << "EVALUATED" << endl;
string output(doc.emit_css(static_cast<Document::CSS_Style>(style))); string output(doc.emit_css(static_cast<Document::CSS_Style>(style)));
// cerr << "EMITTED" << endl;
// cerr << "Allocations:\t" << Node::allocations << endl;
// cerr << "Destructions:\t" << Node::destructed << endl;
// cerr << "Registry size:\t" << doc.context.registry.size() << endl;
// for (size_t i = 0; i < doc.context.registry.size(); ++i) {
// delete doc.context.registry[i];
// }
// cerr << "Deallocations:\t" << i << endl;
char* c_output = (char*) malloc(output.size() + 1); char* c_output = (char*) malloc(output.size() + 1);
strcpy(c_output, output.c_str()); strcpy(c_output, output.c_str());
return c_output; return c_output;
......
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