Skip to content

Commit 5605be0

Browse files
author
Aaron Leung
committed
Working on mixin content.
1 parent aaa65af commit 5605be0

File tree

7 files changed

+34
-9
lines changed

7 files changed

+34
-9
lines changed

constants.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Sass {
1212
extern const char function_kwd[] = "@function";
1313
extern const char return_kwd[] = "@return";
1414
extern const char include_kwd[] = "@include";
15+
extern const char content_kwd[] = "@content";
1516
extern const char extend_kwd[] = "@extend";
1617
extern const char if_kwd[] = "@if";
1718
extern const char else_kwd[] = "@else";

constants.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Sass {
1212
extern const char function_kwd[];
1313
extern const char return_kwd[];
1414
extern const char include_kwd[];
15+
extern const char content_kwd[];
1516
extern const char extend_kwd[];
1617
extern const char if_kwd[];
1718
extern const char else_kwd[];

document.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace Sass {
133133
Node parse_function_definition();
134134
Node parse_parameters();
135135
Node parse_parameter(Node::Type);
136-
Node parse_mixin_call();
136+
Node parse_mixin_call(Node::Type inside_of = Node::none);
137137
Node parse_arguments();
138138
Node parse_argument(Node::Type);
139139
Node parse_assignment();

document_parser.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Sass {
2626
else root += importee;
2727
if (!lex< exactly<';'> >()) throw_syntax_error("top-level @import directive must be terminated by ';'");
2828
}
29-
else if (peek< mixin >() || peek< exactly<'='> >()) {
29+
else if (peek< mixin >() /* || peek< exactly<'='> >() */) {
3030
root << parse_mixin_definition();
3131
}
3232
else if (peek< function >()) {
@@ -42,9 +42,10 @@ namespace Sass {
4242
else if ((lookahead_result = lookahead_for_selector(position)).found) {
4343
root << parse_ruleset(lookahead_result);
4444
}
45-
else if (peek< include >() || peek< exactly<'+'> >()) {
46-
root << parse_mixin_call();
47-
if (!lex< exactly<';'> >()) throw_syntax_error("top-level @include directive must be terminated by ';'");
45+
else if (peek< include >() /* || peek< exactly<'+'> >() */) {
46+
Node mixin_call(parse_mixin_call());
47+
root << mixin_call;
48+
if (mixin_call.size() < 3 && !lex< exactly<';'> >()) throw_syntax_error("top-level @include directive must be terminated by ';'");
4849
}
4950
else if (peek< if_directive >()) {
5051
root << parse_if_directive(Node(), Node::none);
@@ -138,7 +139,7 @@ namespace Sass {
138139

139140
Node Document::parse_mixin_definition()
140141
{
141-
lex< mixin >() || lex< exactly<'='> >();
142+
lex< mixin >() /* || lex< exactly<'='> >() */;
142143
if (!lex< identifier >()) throw_syntax_error("invalid name in @mixin directive");
143144
Node name(context.new_Node(Node::identifier, path, line, lexed));
144145
Node params(parse_parameters());
@@ -210,14 +211,21 @@ namespace Sass {
210211
return var;
211212
}
212213

213-
Node Document::parse_mixin_call()
214+
Node Document::parse_mixin_call(Node::Type inside_of)
214215
{
215-
lex< include >() || lex< exactly<'+'> >();
216+
lex< include >() /* || lex< exactly<'+'> >() */;
216217
if (!lex< identifier >()) throw_syntax_error("invalid name in @include directive");
217218
Node name(context.new_Node(Node::identifier, path, line, lexed));
218219
Node args(parse_arguments());
219-
Node the_call(context.new_Node(Node::mixin_call, path, line, 2));
220+
Node content;
221+
bool has_content = false;
222+
if (peek< exactly<'{'> >()) {
223+
content = parse_block(Node(), inside_of);
224+
has_content = true;
225+
}
226+
Node the_call(context.new_Node(Node::mixin_call, path, line, has_content ? 3 : 2));
220227
the_call << name << args;
228+
if (has_content) the_call << content;
221229
return the_call;
222230
}
223231

@@ -596,16 +604,25 @@ namespace Sass {
596604
block << parse_mixin_call();
597605
semicolon = true;
598606
}
607+
else if (peek< content >(position)) {
608+
if (inside_of != Node::mixin) {
609+
throw_syntax_error("@content may only be used within a mixin");
610+
}
611+
block << context.new_Node(Node::mixin_content, path, line, Token::make()); // just a stub
612+
semicolon = true;
613+
}
599614
else if (peek< sequence< identifier, optional_spaces, exactly<':'>, optional_spaces, exactly<'{'> > >(position)) {
600615
block << parse_propset();
601616
}
602617
else if ((lookahead_result = lookahead_for_selector(position)).found) {
603618
block << parse_ruleset(lookahead_result, inside_of);
604619
}
620+
/*
605621
else if (peek< exactly<'+'> >()) {
606622
block << parse_mixin_call();
607623
semicolon = true;
608624
}
625+
*/
609626
else if (lex< extend >()) {
610627
Node request(context.new_Node(Node::extend_directive, path, line, 1));
611628
Selector_Lookahead lookahead = lookahead_for_extension_target(position);

node.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ namespace Sass {
154154
function_call,
155155
mixin,
156156
mixin_call,
157+
mixin_content,
157158
parameters,
158159
arguments,
159160

prelexer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ namespace Sass {
138138
return exactly<include_kwd>(src);
139139
}
140140

141+
const char* content(const char* src) {
142+
return exactly<content_kwd>(src);
143+
}
144+
141145
const char* extend(const char* src) {
142146
return exactly<extend_kwd>(src);
143147
}

prelexer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ namespace Sass {
317317
const char* function(const char* src);
318318
const char* return_directive(const char* src);
319319
const char* include(const char* src);
320+
const char* content(const char* src);
320321
const char* extend(const char* src);
321322

322323
const char* if_directive(const char* src);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy