Commit e476b60c by Aaron Leung

Expanded-style output works (with some whitespace hiccups).

parent 016aabe9
#include <iostream> #include <iostream>
#include "node.hpp"
#include <string> #include <string>
#include "node.hpp"
using std::string; using std::string;
using std::stringstream;
using std::cout; using std::cout;
using std::endl; using std::endl;
...@@ -66,4 +67,43 @@ namespace Sass { ...@@ -66,4 +67,43 @@ namespace Sass {
default: cout << "HUH?"; break; default: cout << "HUH?"; break;
} }
} }
void Node::emit_expanded_css(stringstream& buf, string prefix) {
switch (type) {
case value:
case selector:
buf << string(token);
break;
case comment:
buf << string(token) << endl;
break;
case property:
buf << string(token) << ":";
break;
case values:
for (int i = 0; i < children.size(); ++i)
buf << " " << string(children[i].token);
break;
case rule:
buf << " ";
children[0].emit_expanded_css(buf, prefix);
children[1].emit_expanded_css(buf, prefix);
buf << ";" << endl;
break;
case declarations:
buf << " {" << endl;
for (int i = 0; i < children.size(); ++i)
children[i].emit_expanded_css(buf, prefix);
buf << "}" << endl;
for (int i = 0; i < opt_children.size(); ++i)
opt_children[i].emit_expanded_css(buf, prefix);
break;
case ruleset:
buf << prefix << " ";
children[0].emit_expanded_css(buf, prefix);
children[1].emit_expanded_css(buf, prefix + string(children[0].token));
break;
}
}
} }
\ No newline at end of file
#include <vector> #include <vector>
#include <sstream>
#include "token.hpp" #include "token.hpp"
namespace Sass { namespace Sass {
...@@ -32,5 +33,6 @@ namespace Sass { ...@@ -32,5 +33,6 @@ namespace Sass {
void push_child(const Node& node); void push_child(const Node& node);
void push_opt_child(const Node& node); void push_opt_child(const Node& node);
void dump(unsigned int depth = 0); void dump(unsigned int depth = 0);
void emit_expanded_css(std::stringstream& buf, string prefix);
}; };
} }
\ No newline at end of file
...@@ -4,6 +4,11 @@ div { ...@@ -4,6 +4,11 @@ div {
background: blue; background: blue;
span { span {
font-weight: bold; font-weight: bold;
a {
text-decoration: none;
color: green;
}
/* second comment that should be preserved */
display: inline-block; display: inline-block;
} }
margin: 10px 5px; margin: 10px 5px;
......
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
#include <sstream>
#include "document.hpp" #include "document.hpp"
using namespace Sass; using namespace Sass;
...@@ -50,10 +51,14 @@ int main(int argc, char* argv[]) { ...@@ -50,10 +51,14 @@ int main(int argc, char* argv[]) {
int i; int i;
int j = doc.statements.size(); int j = doc.statements.size();
printf("%d\n", j); std::stringstream output;
for (i = 0; i < j; ++i) { for (i = 0; i < j; ++i) {
doc.statements[i].dump(); doc.statements[i].emit_expanded_css(output, "");
} }
std::cout << output.str();
} }
return 0; return 0;
......
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