Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fleshing out the classes for documents, nodes, and tokens.
- Loading branch information
Aaron Leung
committed
Feb 28, 2012
1 parent
0418884
commit cefe1e2
Showing
7 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <cstdio> | ||
#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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <vector> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
struct box { | ||
vector<int> vec; | ||
vector<box> 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; | ||
} | ||
|