Skip to content

Commit

Permalink
Working on mixin content.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Leung committed Nov 19, 2012
1 parent aaa65af commit 5605be0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions constants.cpp
Expand Up @@ -12,6 +12,7 @@ namespace Sass {
extern const char function_kwd[] = "@function";
extern const char return_kwd[] = "@return";
extern const char include_kwd[] = "@include";
extern const char content_kwd[] = "@content";
extern const char extend_kwd[] = "@extend";
extern const char if_kwd[] = "@if";
extern const char else_kwd[] = "@else";
Expand Down
1 change: 1 addition & 0 deletions constants.hpp
Expand Up @@ -12,6 +12,7 @@ namespace Sass {
extern const char function_kwd[];
extern const char return_kwd[];
extern const char include_kwd[];
extern const char content_kwd[];
extern const char extend_kwd[];
extern const char if_kwd[];
extern const char else_kwd[];
Expand Down
2 changes: 1 addition & 1 deletion document.hpp
Expand Up @@ -133,7 +133,7 @@ namespace Sass {
Node parse_function_definition();
Node parse_parameters();
Node parse_parameter(Node::Type);
Node parse_mixin_call();
Node parse_mixin_call(Node::Type inside_of = Node::none);
Node parse_arguments();
Node parse_argument(Node::Type);
Node parse_assignment();
Expand Down
33 changes: 25 additions & 8 deletions document_parser.cpp
Expand Up @@ -26,7 +26,7 @@ namespace Sass {
else root += importee;
if (!lex< exactly<';'> >()) throw_syntax_error("top-level @import directive must be terminated by ';'");
}
else if (peek< mixin >() || peek< exactly<'='> >()) {
else if (peek< mixin >() /* || peek< exactly<'='> >() */) {
root << parse_mixin_definition();
}
else if (peek< function >()) {
Expand All @@ -42,9 +42,10 @@ namespace Sass {
else if ((lookahead_result = lookahead_for_selector(position)).found) {
root << parse_ruleset(lookahead_result);
}
else if (peek< include >() || peek< exactly<'+'> >()) {
root << parse_mixin_call();
if (!lex< exactly<';'> >()) throw_syntax_error("top-level @include directive must be terminated by ';'");
else if (peek< include >() /* || peek< exactly<'+'> >() */) {
Node mixin_call(parse_mixin_call());
root << mixin_call;
if (mixin_call.size() < 3 && !lex< exactly<';'> >()) throw_syntax_error("top-level @include directive must be terminated by ';'");
}
else if (peek< if_directive >()) {
root << parse_if_directive(Node(), Node::none);
Expand Down Expand Up @@ -138,7 +139,7 @@ namespace Sass {

Node Document::parse_mixin_definition()
{
lex< mixin >() || lex< exactly<'='> >();
lex< mixin >() /* || lex< exactly<'='> >() */;
if (!lex< identifier >()) throw_syntax_error("invalid name in @mixin directive");
Node name(context.new_Node(Node::identifier, path, line, lexed));
Node params(parse_parameters());
Expand Down Expand Up @@ -210,14 +211,21 @@ namespace Sass {
return var;
}

Node Document::parse_mixin_call()
Node Document::parse_mixin_call(Node::Type inside_of)
{
lex< include >() || lex< exactly<'+'> >();
lex< include >() /* || lex< exactly<'+'> >() */;
if (!lex< identifier >()) throw_syntax_error("invalid name in @include directive");
Node name(context.new_Node(Node::identifier, path, line, lexed));
Node args(parse_arguments());
Node the_call(context.new_Node(Node::mixin_call, path, line, 2));
Node content;
bool has_content = false;
if (peek< exactly<'{'> >()) {
content = parse_block(Node(), inside_of);
has_content = true;
}
Node the_call(context.new_Node(Node::mixin_call, path, line, has_content ? 3 : 2));
the_call << name << args;
if (has_content) the_call << content;
return the_call;
}

Expand Down Expand Up @@ -596,16 +604,25 @@ namespace Sass {
block << parse_mixin_call();
semicolon = true;
}
else if (peek< content >(position)) {
if (inside_of != Node::mixin) {
throw_syntax_error("@content may only be used within a mixin");
}
block << context.new_Node(Node::mixin_content, path, line, Token::make()); // just a stub
semicolon = true;
}
else if (peek< sequence< identifier, optional_spaces, exactly<':'>, optional_spaces, exactly<'{'> > >(position)) {
block << parse_propset();
}
else if ((lookahead_result = lookahead_for_selector(position)).found) {
block << parse_ruleset(lookahead_result, inside_of);
}
/*
else if (peek< exactly<'+'> >()) {
block << parse_mixin_call();
semicolon = true;
}
*/
else if (lex< extend >()) {
Node request(context.new_Node(Node::extend_directive, path, line, 1));
Selector_Lookahead lookahead = lookahead_for_extension_target(position);
Expand Down
1 change: 1 addition & 0 deletions node.hpp
Expand Up @@ -154,6 +154,7 @@ namespace Sass {
function_call,
mixin,
mixin_call,
mixin_content,
parameters,
arguments,

Expand Down
4 changes: 4 additions & 0 deletions prelexer.cpp
Expand Up @@ -138,6 +138,10 @@ namespace Sass {
return exactly<include_kwd>(src);
}

const char* content(const char* src) {
return exactly<content_kwd>(src);
}

const char* extend(const char* src) {
return exactly<extend_kwd>(src);
}
Expand Down
1 change: 1 addition & 0 deletions prelexer.hpp
Expand Up @@ -317,6 +317,7 @@ namespace Sass {
const char* function(const char* src);
const char* return_directive(const char* src);
const char* include(const char* src);
const char* content(const char* src);
const char* extend(const char* src);

const char* if_directive(const char* src);
Expand Down

0 comments on commit 5605be0

Please sign in to comment.