forked from sass/libsass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Eric Kimn
committed
Mar 17, 2015
1 parent
98977d8
commit 5b6d06a
Showing
10 changed files
with
166 additions
and
11 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
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
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
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,95 @@ | ||
#include <iostream> | ||
#include <typeinfo> | ||
|
||
#include "listize.hpp" | ||
#include "to_string.hpp" | ||
#include "context.hpp" | ||
#include "backtrace.hpp" | ||
#include "error_handling.hpp" | ||
|
||
namespace Sass { | ||
|
||
Listize::Listize(Context& ctx, Env* env, Backtrace* bt) | ||
: ctx(ctx), | ||
env(env), | ||
backtrace(bt) | ||
{ } | ||
|
||
Expression* Listize::operator()(Selector_List* sel) | ||
{ | ||
List* l = new (ctx.mem) List(sel->pstate(), sel->length(), List::COMMA); | ||
for (size_t i = 0, L = sel->length(); i < L; ++i) { | ||
*l << (*sel)[i]->perform(this); | ||
} | ||
return l; | ||
} | ||
|
||
Expression* Listize::operator()(Compound_Selector* sel) | ||
{ | ||
To_String to_string; | ||
string str; | ||
for (size_t i = 0, L = sel->length(); i < L; ++i) { | ||
Expression* e = (*sel)[i]->perform(this); | ||
if (e) str += e->perform(&to_string); | ||
} | ||
return new (ctx.mem) String_Constant(sel->pstate(), str); | ||
} | ||
|
||
Expression* Listize::operator()(Type_Selector* sel) | ||
{ | ||
return new (ctx.mem) String_Constant(sel->pstate(), sel->name()); | ||
} | ||
|
||
Expression* Listize::operator()(Selector_Qualifier* sel) | ||
{ | ||
return new (ctx.mem) String_Constant(sel->pstate(), sel->name()); | ||
} | ||
|
||
Expression* Listize::operator()(Complex_Selector* sel) | ||
{ | ||
List* l = new (ctx.mem) List(sel->pstate(), 2); | ||
|
||
Compound_Selector* head = sel->head(); | ||
if (head && !head->is_empty_reference()) | ||
{ | ||
Expression* hh = head->perform(this); | ||
if (hh) *l << hh; | ||
} | ||
|
||
switch(sel->combinator()) | ||
{ | ||
case Complex_Selector::PARENT_OF: | ||
*l << new (ctx.mem) String_Constant(sel->pstate(), ">"); | ||
break; | ||
case Complex_Selector::ADJACENT_TO: | ||
*l << new (ctx.mem) String_Constant(sel->pstate(), "+"); | ||
break; | ||
case Complex_Selector::PRECEDES: | ||
*l << new (ctx.mem) String_Constant(sel->pstate(), "~"); | ||
break; | ||
case Complex_Selector::ANCESTOR_OF: | ||
break; | ||
} | ||
|
||
Complex_Selector* tail = sel->tail(); | ||
if (tail) | ||
{ | ||
Expression* tt = tail->perform(this); | ||
if (tt && tt->concrete_type() == Expression::LIST) | ||
{ *l += static_cast<List*>(tt); } | ||
else if (tt) *l << static_cast<List*>(tt); | ||
} | ||
if (l->length() == 0) return 0; | ||
return l; | ||
} | ||
|
||
Expression* Listize::operator()(Selector_Reference* sel) | ||
{ | ||
return 0; | ||
} | ||
|
||
Expression* Listize::fallback_impl(AST_Node* n) | ||
{ | ||
return 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,45 @@ | ||
#ifndef SASS_LISTIZE_H | ||
#define SASS_LISTIZE_H | ||
|
||
#include <vector> | ||
#include <iostream> | ||
|
||
#include "ast.hpp" | ||
#include "context.hpp" | ||
#include "operation.hpp" | ||
#include "environment.hpp" | ||
|
||
namespace Sass { | ||
using namespace std; | ||
|
||
typedef Environment<AST_Node*> Env; | ||
struct Backtrace; | ||
|
||
class Listize : public Operation_CRTP<Expression*, Listize> { | ||
|
||
Context& ctx; | ||
Env* env; | ||
Backtrace* backtrace; | ||
|
||
Expression* fallback_impl(AST_Node* n); | ||
|
||
public: | ||
Listize(Context&, Env*, Backtrace*); | ||
virtual ~Listize() { } | ||
|
||
using Operation<Expression*>::operator(); | ||
|
||
Expression* operator()(Selector_List*); | ||
Expression* operator()(Complex_Selector*); | ||
Expression* operator()(Compound_Selector*); | ||
Expression* operator()(Type_Selector*); | ||
Expression* operator()(Selector_Qualifier*); | ||
Expression* operator()(Selector_Reference*); | ||
|
||
template <typename U> | ||
Expression* fallback(U x) { return fallback_impl(x); } | ||
}; | ||
|
||
} | ||
|
||
#endif |
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