Commit 12fcaccb by Aaron Leung

New node type for hex triples. Modified the emitter to print hex triples…

New node type for hex triples. Modified the emitter to print hex triples correctly. Next: hex triple arithmetic.
parent b4de782d
...@@ -57,10 +57,29 @@ namespace Sass { ...@@ -57,10 +57,29 @@ namespace Sass {
} break; } break;
case Node::textual_hex: { case Node::textual_hex: {
long numval = std::strtol(expr.token.begin + 1, NULL, 16); // long numval = std::strtol(expr.token.begin + 1, NULL, 16);
Node result(expr.line_number, numval); // Node result(expr.line_number, numval);
result.is_hex = true; // result.is_hex = true;
return result; // return result;
Node triple(expr.line_number, Node::hex_triple, 3);
Token hext(expr.token.begin+1, expr.token.end);
if (hext.length() == 6) {
for (int i = 0; i < 6; i += 2) {
Node thing(expr.line_number, static_cast<double>(std::strtol(string(hext.begin+i, 2).c_str(), NULL, 16)));
cerr << "evaled a hex triplet: " << thing.to_string("") << endl;
triple << Node(expr.line_number, static_cast<double>(std::strtol(string(hext.begin+i, 2).c_str(), NULL, 16)));
}
}
else {
for (int i = 0; i < 3; ++i) {
triple << Node(expr.line_number, static_cast<double>(std::strtol(string(2, hext.begin[i]).c_str(), NULL, 16)));
}
}
return triple;
} break; } break;
default: { default: {
......
div {
p01: #abc;
p02: #aabbcc;
p03: #abc + hello;
p04: #abc + 1; // add 1 to each triplet
p05: #abc + #001; // triplet-wise addition
p06: #0000ff + 1; // add 1 to each triplet; ignore overflow because it doesn't correspond to a color name
p07: #0000ff + #000001; // convert overflow to name of color (blue)
p08: #00ffff + #000101; // aqua
p09: #000000;
p10: #000000 - 1; // black
p11: #000000 - #000001; // black
p12: #ffff00 + #010100; // yellow
p13: (#101010 / 7)
}
\ No newline at end of file
#include <iostream> #include <iostream>
#include <iomanip>
#include <string> #include <string>
#include <cctype> #include <cctype>
#include <cstdlib> #include <cstdlib>
...@@ -138,6 +139,15 @@ namespace Sass { ...@@ -138,6 +139,15 @@ namespace Sass {
ss << numeric_value; ss << numeric_value;
return ss.str(); return ss.str();
} break; } break;
case hex_triple: {
stringstream ss;
ss << '#' << std::setw(2) << std::setfill('0');
for (int i = 0; i < 3; ++i) {
ss << std::hex << std::setw(2) << static_cast<long>(children->at(i).numeric_value);
}
return ss.str();
} break;
default: { default: {
return string(token); return string(token);
......
...@@ -58,6 +58,7 @@ namespace Sass { ...@@ -58,6 +58,7 @@ namespace Sass {
numeric_percentage, numeric_percentage,
numeric_dimension, numeric_dimension,
number, number,
hex_triple,
comment comment
}; };
......
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