Commit 2e424258 by Aaron Leung

Putting parsing functions in place. Don't try to compile yet.

parent b47fadb1
......@@ -31,10 +31,8 @@ namespace Sass {
}
void Document::parse_stylesheet() {
printf("ABOUT TO MUNCH LEADING SPACES\n");
try_munching<optional_spaces>();
while (*position) {
printf("LOOPING OVER STATEMENTS\n");
statements.push_back(parse_statement());
try_munching<optional_spaces>();
}
......@@ -42,10 +40,34 @@ namespace Sass {
Node Document::parse_statement() {
if (try_munching<block_comment>()) {
printf("MUNCHING A COMMENT\n");
return Node(Node::comment, top);
}
else return Node();
else return parse_ruleset();
}
Node Document::parse_ruleset() {
Node ruleset(Node::ruleset);
ruleset.push_child(parse_selector());
ruleset.push_child(parse_declarations());
return ruleset;
}
Node Document::parse_selector() {
try_munching<identifier>();
return Node(Node::selector, top);
}
Node Document::parse_declarations() {
try_munching<exactly<'{'> >();
while(!try_munching<exactly<'}'> >()) {
try_munching<identifier>();
Token id = top;
if (try_munching<exactly<':'> >()) {
Node rule(Node::rule);
rule.push_child(Node(Node::property, id));
rule.push_child(Node(Node::value, parse_value()));
return rule;
}
}
}
}
\ No newline at end of file
......@@ -56,6 +56,9 @@ namespace Sass {
void parse_stylesheet();
Node parse_statement();
Node parse_ruleset();
Node parse_selector();
Node parse_declarations();
};
}
\ No newline at end of file
......@@ -2,14 +2,17 @@
namespace Sass {
Node::Node() { }
Node::Node(Node_Type _type) {
type = _type;
}
Node::Node(Node_Type _type, Token& _token) {
type = _type;
token = _token;
}
void Node::push_child(Node& node) {
void Node::push_child(const Node& node) {
children.push_back(node);
}
void Node::push_opt_child(Node& node) {
void Node::push_opt_child(const Node& node) {
opt_children.push_back(node);
}
}
\ No newline at end of file
......@@ -7,12 +7,13 @@ namespace Sass {
enum Node_Type {
null,
comment,
rule_set,
declaration,
ruleset,
declarations,
selector_group,
selector,
simple_selector_sequence,
simple_selector,
rule,
property,
value,
lookahead_sequence,
......@@ -25,8 +26,9 @@ namespace Sass {
vector<Node> opt_children;
Node();
Node(Node_Type _type);
Node(Node_Type _type, Token& _token);
void push_child(Node& node);
void push_opt_child(Node& node);
void push_child(const Node& node);
void push_opt_child(const Node& node);
};
}
\ No newline at end of file
......@@ -15,5 +15,11 @@ namespace Sass {
else begin = _begin, end = _end;
line_number = _line_number;
}
Token::Token(const Token& t) {
type = t.type;
begin = t.begin;
end = t.end;
line_number = t.line_number;
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ namespace Sass {
const char* _begin,
const char* _end,
unsigned int _line_number);
Token(const Token& t);
inline bool is_null() { return begin == 0 || end == 0; }
inline operator string() { return string(begin, end - begin); }
};
......
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