Commit 28eac700 by Aaron Leung

Putting code in place for reporting file names in post-parsing errors, and also…

Putting code in place for reporting file names in post-parsing errors, and also string concatenation.
parent 5a0eae49
#include "eval_apply.hpp" #include "eval_apply.hpp"
#include "error.hpp"
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
namespace Sass { namespace Sass {
using std::cerr; using std::endl; using std::cerr; using std::endl;
void eval_error(string message, size_t line_number, const char* file_name)
{
string fn;
if (file_name) {
const char* end = Prelexer::string_constant(file_name);
if (end) fn = string(file_name, end - file_name);
else fn = string(file_name);
}
throw Error(Error::evaluation, line_number, fn, message);
}
Node eval(Node& expr, Environment& env, map<pair<string, size_t>, Function>& f_env) Node eval(Node& expr, Environment& env, map<pair<string, size_t>, Function>& f_env)
{ {
...@@ -17,6 +29,7 @@ namespace Sass { ...@@ -17,6 +29,7 @@ namespace Sass {
case Node::expansion: { case Node::expansion: {
Token name(expr[0].content.token); Token name(expr[0].content.token);
Node args(expr[1]); Node args(expr[1]);
if (!env.query(name)) eval_error("mixin " + name.to_string() + " is undefined", expr.line_number, expr.file_name);
Node mixin(env[name]); Node mixin(env[name]);
Node expansion(apply_mixin(mixin, args, env, f_env)); Node expansion(apply_mixin(mixin, args, env, f_env));
expr.content.children->pop_back(); expr.content.children->pop_back();
...@@ -277,6 +290,15 @@ namespace Sass { ...@@ -277,6 +290,15 @@ namespace Sass {
acc.content.children->pop_back(); acc.content.children->pop_back();
acc << Node(acc.line_number, r, g, b); acc << Node(acc.line_number, r, g, b);
} }
// else if (lhs.type == Node::concatenation) {
// lhs << rhs;
// }
// else if (lhs.type == Node::string_constant || rhs.type == Node::string_constant) {
// acc.content.children->pop_back();
// Node cat(Node::concatenation, lhs.line_number, 2);
// cat << lhs << rhs;
// acc << cat;
// }
else { else {
// TO DO: disallow division and multiplication on lists // TO DO: disallow division and multiplication on lists
acc.content.children->push_back(rhs); acc.content.children->push_back(rhs);
......
...@@ -8,6 +8,7 @@ bobo + mogo { ...@@ -8,6 +8,7 @@ bobo + mogo {
hey: ho; hey: ho;
div { div {
blah: blah; blah: blah;
bloo: (1/0) + 5;
} }
} }
...@@ -19,8 +20,8 @@ bobo + mogo { ...@@ -19,8 +20,8 @@ bobo + mogo {
div[hux ~= "hello"] { div[hux ~= "hello"] {
hux: blux; hux: blux;
foo: boo; foo: boo;
@include moogoo; dux: "hello" + "goodbye";
dux: mux; shux: "hello" + 12;
@import bugaboo "foogoo" frux: 12 + "hello";
blah: blah; blah: blah;
} }
...@@ -110,14 +110,16 @@ namespace Sass { ...@@ -110,14 +110,16 @@ namespace Sass {
bool boolean_value; bool boolean_value;
} content; } content;
const char* file_name;
static size_t allocations; static size_t allocations;
void clear() void clear()
{ {
type = none; line_number = 0; has_children = false; type = none; line_number = 0; file_name = 0;
has_statements = false; has_blocks = false; has_expansions = false; has_children = false; has_statements = false; has_blocks = false;
has_backref = false; from_variable = false; eval_me = false; has_expansions = false; has_backref = false; from_variable = false;
unquoted = false; eval_me = false; unquoted = false;
} }
size_t size() const size_t size() const
......
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