diff --git a/src/document.cpp b/src/document.cpp index e69de29bb2..c797b988a1 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -0,0 +1,27 @@ +#include +#include "document.hpp" + +namespace Sass { + Document::Document(char* _path, char* _source) { + path = _path; + if (!source) { + std::FILE *f; + f = std::fopen(path, "rb"); + // if (!f) { + // printf("ERROR: could not open file %s", path); + // abort(); + // } + std::fseek(f, 0, SEEK_END); + int len = std::ftell(f); + std::rewind(f); + // char *buf = (char *)malloc(len * sizeof(char) + 1); + source = new char[len + 1]; + std::fread(source, sizeof(char), len, f); + source[len] = '\0'; + std::fclose(f); + } + else { + source = _source; + } + } +} \ No newline at end of file diff --git a/src/document.hpp b/src/document.hpp index 30e850cd53..cafc2c231e 100644 --- a/src/document.hpp +++ b/src/document.hpp @@ -2,11 +2,15 @@ #include "node.hpp" namespace Sass { + using std::vector; + struct Document { - using std::vector; - + char* path; char* source; unsigned int position; + unsigned int line_number; vector statements; + + Document(char* _path, char* _source = 0); }; } \ No newline at end of file diff --git a/src/node.cpp b/src/node.cpp index e69de29bb2..b0598b710b 100644 --- a/src/node.cpp +++ b/src/node.cpp @@ -0,0 +1,15 @@ +#include "node.hpp" + +namespace Sass { + Node::Node() { } + Node::Node(Node_Type _type, Token& _token) { + type = _type; + token = _token; + } + void Node::push_child(Node& node) { + children.push_back(node); + } + void Node::push_opt_child(Node& node) { + opt_children.push_back(node); + } +} \ No newline at end of file diff --git a/src/node.hpp b/src/node.hpp index 04613f2ce4..458e02dc7c 100644 --- a/src/node.hpp +++ b/src/node.hpp @@ -2,5 +2,29 @@ #include "token.hpp" namespace Sass { + using std::vector; struct Node { - \ No newline at end of file + enum Node_Type { + null, + comment, + rule_set, + declaration, + selector_group, + selector, + simple_selector_sequence, + simple_selector, + property, + value + }; + + Node_Type type; + Token token; + vector children; + vector opt_children; + + Node(); + Node(Node_Type _type, Token& _token); + void push_child(Node& node); + void push_opt_child(Node& node); + }; +} \ No newline at end of file diff --git a/src/token.cpp b/src/token.cpp new file mode 100644 index 0000000000..e183d480a6 --- /dev/null +++ b/src/token.cpp @@ -0,0 +1,16 @@ +#include "token.hpp" + +namespace Sass { + Token::Token() { + begin = 0; + end = 0; + line_number = 1; + } + Token::Token(const char* _begin, + const char* _end, + unsigned int _line_number) { + begin = _begin; + end = _end; + line_number = _line_number; + } +} \ No newline at end of file diff --git a/src/token.hpp b/src/token.hpp new file mode 100644 index 0000000000..3e3d5588b4 --- /dev/null +++ b/src/token.hpp @@ -0,0 +1,12 @@ +namespace Sass { + struct Token { + const char* begin; + const char* end; + unsigned int line_number; + Token(); + Token(const char* _begin, + const char* _end, + unsigned int _line_number); + inline bool is_null() { return begin == 0 || end == 0; } + }; +} \ No newline at end of file diff --git a/src/vectest.cpp b/src/vectest.cpp new file mode 100644 index 0000000000..e733442b17 --- /dev/null +++ b/src/vectest.cpp @@ -0,0 +1,33 @@ +#include +#include + +using namespace std; + +struct box { + vector vec; + vector vec2; +}; + +int main() { + box b; + + b.vec.push_back(1); + b.vec.push_back(2); + b.vec.push_back(3); + + box c = b; + c.vec.push_back(4); + + cout << b.vec.size() << endl; + cout << c.vec.size() << endl; + + c.vec[0] = 42; + cout << b.vec[0] << endl; + cout << c.vec[0] << endl; + + b.vec2.push_back(c); + cout << b.vec2[0].vec[0] << endl; + + return 0; +} +