Skip to content

Commit 086fd7b

Browse files
mgreterxzyfer
authored andcommitted
Implement static media_queries for imports
Missing implementation for interpolated media queries!
1 parent 2e403dc commit 086fd7b

File tree

6 files changed

+48
-6
lines changed

6 files changed

+48
-6
lines changed

ast.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,15 @@ namespace Sass {
492492
class Import : public Statement {
493493
vector<string> files_;
494494
vector<Expression*> urls_;
495+
ADD_PROPERTY(List*, media_queries);
495496
public:
496497
Import(ParserState pstate)
497498
: Statement(pstate),
498-
files_(vector<string>()), urls_(vector<Expression*>())
499+
files_(vector<string>()),
500+
urls_(vector<Expression*>()),
501+
media_queries_(0)
499502
{ }
500-
vector<string>& files() { return files_; }
503+
vector<string>& files() { return files_; }
501504
vector<Expression*>& urls() { return urls_; }
502505
ATTACH_OPERATIONS()
503506
};

expand.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ namespace Sass {
275275
Statement* Expand::operator()(Import* imp)
276276
{
277277
Import* result = new (ctx.mem) Import(imp->pstate());
278+
result->media_queries(imp->media_queries());
278279
for ( size_t i = 0, S = imp->urls().size(); i < S; ++i) {
279280
result->urls().push_back(imp->urls()[i]->perform(eval->with(env, backtrace)));
280281
}

inspect.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ namespace Sass {
157157
}
158158

159159
import->urls().front()->perform(this);
160+
if (import->media_queries()) {
161+
append_mandatory_space();
162+
import->media_queries()->perform(this);
163+
}
160164
append_delimiter();
161165
for (size_t i = 1, S = import->urls().size(); i < S; ++i) {
162166
append_mandatory_linefeed();
@@ -168,6 +172,10 @@ namespace Sass {
168172
}
169173

170174
import->urls()[i]->perform(this);
175+
if (import->media_queries()) {
176+
append_mandatory_space();
177+
import->media_queries()->perform(this);
178+
}
171179
append_delimiter();
172180
}
173181
}

lexer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,13 @@ namespace Sass {
129129
return *src == 0 || *src == '\n' || *src == '\r' ? src : 0;
130130
}
131131

132+
// Assert end_of_file boundary (/\z/)
133+
// This is a zero-width positive lookahead
134+
const char* end_of_file(const char* src)
135+
{
136+
// end of file or unix linefeed return here
137+
return *src == 0 ? src : 0;
138+
}
139+
132140
}
133141
}

lexer.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ namespace Sass {
6565
// Assert string boundaries (/\Z|\z|\A/)
6666
// There are zero-width positive lookaheads
6767
const char* end_of_line(const char* src);
68-
// const char* end_of_string(const char* src);
68+
69+
// Assert end_of_file boundary (/\z/)
70+
// This is a zero-width positive lookahead
71+
const char* end_of_file(const char* src);
6972
// const char* start_of_string(const char* src);
7073

7174
// Type definition for prelexer functions

parser.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sass_functions.h"
1212

1313
#include <typeinfo>
14+
#include <tuple>
1415

1516
namespace Sass {
1617
using namespace std;
@@ -220,7 +221,8 @@ namespace Sass {
220221

221222
void Parser::import_single_file (Import* imp, string import_path) {
222223

223-
if (!unquote(import_path).substr(0, 7).compare("http://") ||
224+
if (imp->media_queries() ||
225+
!unquote(import_path).substr(0, 7).compare("http://") ||
224226
!unquote(import_path).substr(0, 8).compare("https://") ||
225227
!unquote(import_path).substr(0, 2).compare("//"))
226228
{
@@ -282,14 +284,16 @@ namespace Sass {
282284
{
283285
lex< kwd_import >();
284286
Import* imp = new (ctx.mem) Import(pstate);
287+
vector<pair<string,Function_Call*>> to_import;
285288
bool first = true;
286289
do {
287290
while (lex< block_comment >());
288291
if (lex< quoted_string >()) {
289292
if (!do_import(lexed, imp, ctx.c_importers, true))
290293
{
291294
// push single file import
292-
import_single_file(imp, lexed);
295+
// import_single_file(imp, lexed);
296+
to_import.push_back(pair<string,Function_Call*>(string(lexed), 0));
293297
}
294298
}
295299
else if (lex< uri_prefix >()) {
@@ -311,14 +315,29 @@ namespace Sass {
311315
error("malformed URL", pstate);
312316
}
313317
if (!lex< exactly<')'> >()) error("URI is missing ')'", pstate);
314-
imp->urls().push_back(result);
318+
// imp->urls().push_back(result);
319+
to_import.push_back(pair<string,Function_Call*>("", result));
315320
}
316321
else {
317322
if (first) error("@import directive requires a url or quoted path", pstate);
318323
else error("expecting another url or quoted path in @import list", pstate);
319324
}
320325
first = false;
321326
} while (lex_css< exactly<','> >());
327+
328+
if (!peek_css<alternatives<exactly<';'>,end_of_file>>()) {
329+
List* media_queries = parse_media_queries();
330+
imp->media_queries(media_queries);
331+
}
332+
333+
for(auto location : to_import) {
334+
if (location.second) {
335+
imp->urls().push_back(location.second);
336+
} else {
337+
import_single_file(imp, location.first);
338+
}
339+
}
340+
322341
return imp;
323342
}
324343

0 commit comments

Comments
 (0)