Commit 2d15ad0c by Aaron Leung

Type checking for the numeric functions.

parent 445fe21d
...@@ -43,4 +43,6 @@ div { ...@@ -43,4 +43,6 @@ div {
flah: unquote("hello"); flah: unquote("hello");
grah: quote(hello); grah: quote(hello);
hrah: quote(mukluk); hrah: quote(mukluk);
mwah: percentage(.3);
a: floor(10.8%);
} }
\ No newline at end of file
...@@ -274,6 +274,7 @@ namespace Sass { ...@@ -274,6 +274,7 @@ namespace Sass {
Node percentage(const vector<Token>& parameters, map<Token, Node>& bindings) { Node percentage(const vector<Token>& parameters, map<Token, Node>& bindings) {
Node cpy(bindings[parameters[0]].clone()); Node cpy(bindings[parameters[0]].clone());
// TO DO: make sure it's not already a percentage // TO DO: make sure it's not already a percentage
if (cpy.type != Node::number) eval_error("argument to percentage must be a unitless number", cpy.line_number, cpy.file_name);
cpy.content.numeric_value = cpy.content.numeric_value * 100; cpy.content.numeric_value = cpy.content.numeric_value * 100;
cpy.type = Node::numeric_percentage; cpy.type = Node::numeric_percentage;
return cpy; return cpy;
...@@ -286,9 +287,12 @@ namespace Sass { ...@@ -286,9 +287,12 @@ namespace Sass {
if (cpy.type == Node::numeric_dimension) { if (cpy.type == Node::numeric_dimension) {
cpy.content.dimension.numeric_value = std::floor(cpy.content.dimension.numeric_value + 0.5); cpy.content.dimension.numeric_value = std::floor(cpy.content.dimension.numeric_value + 0.5);
} }
else { else if (cpy.type == Node::number || cpy.type == Node::numeric_percentage) {
cpy.content.numeric_value = std::floor(cpy.content.numeric_value + 0.5); cpy.content.numeric_value = std::floor(cpy.content.numeric_value + 0.5);
} }
else {
eval_error("argument to round must be numeric", cpy.line_number, cpy.file_name);
}
return cpy; return cpy;
} }
...@@ -299,9 +303,12 @@ namespace Sass { ...@@ -299,9 +303,12 @@ namespace Sass {
if (cpy.type == Node::numeric_dimension) { if (cpy.type == Node::numeric_dimension) {
cpy.content.dimension.numeric_value = std::ceil(cpy.content.dimension.numeric_value); cpy.content.dimension.numeric_value = std::ceil(cpy.content.dimension.numeric_value);
} }
else { else if (cpy.type == Node::number || cpy.type == Node::numeric_percentage){
cpy.content.numeric_value = std::ceil(cpy.content.numeric_value); cpy.content.numeric_value = std::ceil(cpy.content.numeric_value);
} }
else {
eval_error("argument to ceil must be numeric", cpy.line_number, cpy.file_name);
}
return cpy; return cpy;
} }
...@@ -312,9 +319,12 @@ namespace Sass { ...@@ -312,9 +319,12 @@ namespace Sass {
if (cpy.type == Node::numeric_dimension) { if (cpy.type == Node::numeric_dimension) {
cpy.content.dimension.numeric_value = std::floor(cpy.content.dimension.numeric_value); cpy.content.dimension.numeric_value = std::floor(cpy.content.dimension.numeric_value);
} }
else { else if (cpy.type == Node::number || cpy.type == Node::numeric_percentage){
cpy.content.numeric_value = std::floor(cpy.content.numeric_value); cpy.content.numeric_value = std::floor(cpy.content.numeric_value);
} }
else {
eval_error("argument to floor must be numeric", cpy.line_number, cpy.file_name);
}
return cpy; return cpy;
} }
...@@ -325,8 +335,11 @@ namespace Sass { ...@@ -325,8 +335,11 @@ namespace Sass {
if (cpy.type == Node::numeric_dimension) { if (cpy.type == Node::numeric_dimension) {
cpy.content.dimension.numeric_value = std::fabs(cpy.content.dimension.numeric_value); cpy.content.dimension.numeric_value = std::fabs(cpy.content.dimension.numeric_value);
} }
else if (cpy.type == Node::number || cpy.type == Node::numeric_percentage){
cpy.content.numeric_value = std::abs(cpy.content.numeric_value);
}
else { else {
cpy.content.numeric_value = std::fabs(cpy.content.numeric_value); eval_error("argument to abs must be numeric", cpy.line_number, cpy.file_name);
} }
return cpy; return cpy;
} }
......
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