Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparation for interpolate/output refactor #899

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
428cf8e
Suppress compiler warning
mgreter Feb 20, 2015
7f81d2b
Remember white-space with lexed tokens
mgreter Feb 20, 2015
62b82b0
Add LFEED constant
mgreter Feb 20, 2015
2e0d936
Add ctx for To_String
mgreter Feb 20, 2015
c3b76bb
Improve prelexer for interpolation parsing
mgreter Feb 20, 2015
047846d
Remove debug messages
mgreter Feb 20, 2015
c3168da
Add new escape util functions
mgreter Feb 20, 2015
eb399b2
Fix some constant declarations
mgreter Feb 20, 2015
892e94a
Fix some white-space
mgreter Feb 20, 2015
91ff64a
Remove debug statements
mgreter Feb 20, 2015
94ec7bd
Preserve tabs over cssize operation
mgreter Feb 20, 2015
cc7f149
Add ctx to To_String
mgreter Feb 20, 2015
9ada376
Add String_Constant renderer for To_String
mgreter Feb 20, 2015
e5dc577
Fix lexer for spaces_and_comments
mgreter Feb 20, 2015
8056d6b
Clean up sass functions code
mgreter Feb 21, 2015
1dd9f71
Rename sass color fix flag
mgreter Feb 21, 2015
0b2ff30
Add code comments plus one ctx
mgreter Feb 21, 2015
f0a28f6
Rename quotemark to quote_mark
mgreter Feb 21, 2015
f315889
Add minor fixes to parser
mgreter Feb 21, 2015
1974c70
Improve parse_value_schema
mgreter Feb 21, 2015
fa1242c
Remove debug code
mgreter Feb 21, 2015
0a28945
Remove skip_source_map_update flag
mgreter Feb 21, 2015
78b3a68
Add ctx for To_String
mgreter Feb 21, 2015
59794ad
Remove dequote flag
mgreter Feb 21, 2015
2936171
Improve string schema parsing
mgreter Feb 21, 2015
1d00343
Fix some functions for interpolation quotes
mgreter Feb 21, 2015
5e67a6f
Add check for concrete string type
mgreter Feb 21, 2015
1d887fd
Rename unq to sass_fix_1291
mgreter Feb 21, 2015
d6f7214
Implement quotemark return on unquote function
mgreter Feb 21, 2015
7d3753a
Add initial implementation for String_Quoted
mgreter Feb 21, 2015
b6d8b81
Add new parser function prototype
mgreter Feb 21, 2015
45fae94
Add initial implementation for String_Quoted
mgreter Feb 21, 2015
accb26e
Add initial implementation for String_Quoted #2
mgreter Feb 21, 2015
fd74497
Refactor some code
mgreter Feb 21, 2015
430018e
Add ctx to To_String
mgreter Feb 21, 2015
1e1b6e6
Refactor String Ast Nodes
mgreter Feb 21, 2015
daa0898
Refactor node.cpp
mgreter Feb 21, 2015
f310b3b
Add quote_mark property to String_Constant
mgreter Feb 21, 2015
ba0fe1e
Add output.cpp (move code from header)
mgreter Feb 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ SOURCES = \
inspect.cpp \
node.cpp \
json.cpp \
output.cpp \
output_compressed.cpp \
output_nested.cpp \
parser.cpp \
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ libsass_la_SOURCES = \
inspect.cpp inspect.hpp \
node.cpp node.hpp \
json.cpp json.hpp \
output.cpp output.hpp \
output_compressed.cpp output_compressed.hpp \
output_nested.cpp output_nested.hpp \
parser.cpp parser.hpp \
Expand Down
6 changes: 3 additions & 3 deletions ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace Sass {

Compound_Selector* Simple_Selector::unify_with(Compound_Selector* rhs, Context& ctx)
{
To_String to_string;
To_String to_string(&ctx);
for (size_t i = 0, L = rhs->length(); i < L; ++i)
{ if (perform(&to_string) == (*rhs)[i]->perform(&to_string)) return rhs; }

Expand Down Expand Up @@ -451,7 +451,7 @@ namespace Sass {
{
Complex_Selector* cpy = new (ctx.mem) Complex_Selector(*this);

if (head()) {
if (head()) {
cpy->head(head()->clone(ctx));
}

Expand Down Expand Up @@ -533,7 +533,7 @@ namespace Sass {

Compound_Selector* Compound_Selector::minus(Compound_Selector* rhs, Context& ctx)
{
To_String to_string;
To_String to_string(&ctx);
Compound_Selector* result = new (ctx.mem) Compound_Selector(pstate());

// not very efficient because it needs to preserve order
Expand Down
78 changes: 48 additions & 30 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#endif

#include "units.hpp"
#include "token.hpp"
#include "position.hpp"
#include "constants.hpp"
#include "operation.hpp"
#include "position.hpp"
Expand All @@ -40,7 +40,7 @@
#include "environment.hpp"
#include "error_handling.hpp"
#include "ast_def_macros.hpp"
#include "to_string.hpp"
#include "to_string.hpp"

#include "sass.h"
#include "sass_values.h"
Expand All @@ -59,7 +59,9 @@ namespace Sass {
class AST_Node {
ADD_PROPERTY(ParserState, pstate);
public:
AST_Node(ParserState pstate) : pstate_(pstate) { }
AST_Node(ParserState pstate)
: pstate_(pstate)
{ }
virtual ~AST_Node() = 0;
// virtual Block* block() { return 0; }
public:
Expand Down Expand Up @@ -98,7 +100,10 @@ namespace Sass {
Expression(ParserState pstate,
bool d = false, bool e = false, bool i = false, Concrete_Type ct = NONE)
: AST_Node(pstate),
is_delayed_(d), is_expanded_(d), is_interpolant_(i), concrete_type_(ct)
is_delayed_(d),
is_expanded_(d),
is_interpolant_(i),
concrete_type_(ct)
{ }
virtual operator bool() { return true; }
virtual ~Expression() { };
Expand Down Expand Up @@ -184,7 +189,7 @@ namespace Sass {
inline Vectorized<T>::~Vectorized() { }

/////////////////////////////////////////////////////////////////////////////
// Mixin class for AST nodes that should behave like ahash table. Uses an
// Mixin class for AST nodes that should behave like a hash table. Uses an
// extra <vector> internally to maintain insertion order for interation.
/////////////////////////////////////////////////////////////////////////////
class Hashed {
Expand Down Expand Up @@ -471,7 +476,7 @@ namespace Sass {
////////////////////////////////////////////////////////////////////////////
class Import : public Statement {
vector<string> files_;
vector<Expression*> urls_;
vector<Expression*> urls_;
public:
Import(ParserState pstate)
: Statement(pstate),
Expand Down Expand Up @@ -1326,10 +1331,10 @@ namespace Sass {
// "flat" strings.
////////////////////////////////////////////////////////////////////////
class String : public Expression {
ADD_PROPERTY(bool, needs_unquoting);
ADD_PROPERTY(bool, sass_fix_1291);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about this variable name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The needs_unquoting flag will not be needed with the full refactoring. I my WIP this flag is needed to have the same behavior as ruby sass (sass/sass#1291) which will be deprecated. Which means the sass_fix_1291 can probably be removed once sass has it deprecated. But you're right, currently it doesn't make sense as needs_unquoting is still in the code. Please see comment below about String_Constant vs. String_Quoted. I would favor to ignore it for now.

public:
String(ParserState pstate, bool unq = false, bool delayed = false)
: Expression(pstate, delayed), needs_unquoting_(unq)
String(ParserState pstate, bool delayed = false, bool sass_fix_1291 = false)
: Expression(pstate, delayed), sass_fix_1291_(sass_fix_1291)
{ concrete_type(STRING); }
static string type_name() { return "string"; }
virtual ~String() = 0;
Expand All @@ -1342,12 +1347,11 @@ namespace Sass {
// evaluation phase.
///////////////////////////////////////////////////////////////////////
class String_Schema : public String, public Vectorized<Expression*> {
ADD_PROPERTY(char, quote_mark);
ADD_PROPERTY(bool, has_interpolants);
size_t hash_;
public:
String_Schema(ParserState pstate, size_t size = 0, bool unq = false, char qm = '\0', bool i = false)
: String(pstate, unq), Vectorized<Expression*>(size), quote_mark_(qm), has_interpolants_(i), hash_(0)
String_Schema(ParserState pstate, size_t size = 0, bool has_interpolants = false)
: String(pstate), Vectorized<Expression*>(size), has_interpolants_(has_interpolants), hash_(0)
{ }
string type() { return "string"; }
static string type_name() { return "string"; }
Expand Down Expand Up @@ -1386,22 +1390,23 @@ namespace Sass {
// Flat strings -- the lowest level of raw textual data.
////////////////////////////////////////////////////////
class String_Constant : public String {
ADD_PROPERTY(char, quote_mark);
ADD_PROPERTY(string, value);
string unquoted_;
size_t hash_;
public:
String_Constant(ParserState pstate, string val, bool unq = false)
: String(pstate, unq, true), value_(val), hash_(0)
{ unquoted_ = unquote(value_); }
String_Constant(ParserState pstate, const char* beg, bool unq = false)
: String(pstate, unq, true), value_(string(beg)), hash_(0)
{ unquoted_ = unquote(value_); }
String_Constant(ParserState pstate, const char* beg, const char* end, bool unq = false)
: String(pstate, unq, true), value_(string(beg, end-beg)), hash_(0)
{ unquoted_ = unquote(value_); }
String_Constant(ParserState pstate, const Token& tok, bool unq = false)
: String(pstate, unq, true), value_(string(tok.begin, tok.end)), hash_(0)
{ unquoted_ = unquote(value_); }
String_Constant(ParserState pstate, string val)
: String(pstate), quote_mark_(0), value_(val), hash_(0)
{ unquoted_ = unquote(value_, &quote_mark_); }
String_Constant(ParserState pstate, const char* beg)
: String(pstate), quote_mark_(0), value_(string(beg)), hash_(0)
{ unquoted_ = unquote(value_, &quote_mark_); }
String_Constant(ParserState pstate, const char* beg, const char* end)
: String(pstate), quote_mark_(0), value_(string(beg, end-beg)), hash_(0)
{ unquoted_ = unquote(value_, &quote_mark_); }
String_Constant(ParserState pstate, const Token& tok)
: String(pstate), quote_mark_(0), value_(string(tok.begin, tok.end)), hash_(0)
{ unquoted_ = unquote(value_, &quote_mark_); }
string type() { return "string"; }
static string type_name() { return "string"; }

Expand All @@ -1425,11 +1430,23 @@ namespace Sass {
return hash_;
}

static char single_quote() { return '\''; }
// static char auto_quote() { return '*'; }
static char double_quote() { return '"'; }
static char single_quote() { return '\''; }

bool is_quoted() { return value_.length() && (value_[0] == '"' || value_[0] == '\''); }
char quote_mark() { return is_quoted() ? value_[0] : '\0'; }
ATTACH_OPERATIONS();
};

////////////////////////////////////////////////////////
// Possibly quoted string (unquote on instantiation)
////////////////////////////////////////////////////////
class String_Quoted : public String_Constant {
public:
String_Quoted(ParserState pstate, string val)
: String_Constant(pstate, val)
{
// value_ = unquote(value_, &quote_mark_);
}
ATTACH_OPERATIONS();
};

Expand Down Expand Up @@ -1690,7 +1707,9 @@ namespace Sass {
ADD_PROPERTY(bool, has_placeholder);
public:
Selector(ParserState pstate, bool r = false, bool h = false)
: AST_Node(pstate), has_reference_(r), has_placeholder_(h)
: AST_Node(pstate),
has_reference_(r),
has_placeholder_(h)
{ }
virtual ~Selector() = 0;
virtual Selector_Placeholder* find_placeholder();
Expand Down Expand Up @@ -2029,8 +2048,7 @@ namespace Sass {
///////////////////////////////////
// Comma-separated selector groups.
///////////////////////////////////
class Selector_List
: public Selector, public Vectorized<Complex_Selector*> {
class Selector_List : public Selector, public Vectorized<Complex_Selector*> {
#ifdef DEBUG
ADD_PROPERTY(string, mCachedSelector);
#endif
Expand Down
3 changes: 3 additions & 0 deletions ast_fwd_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/////////////////////////////////////////////
namespace Sass {

enum Output_Style { NESTED, EXPANDED, COMPACT, COMPRESSED, FORMATTED };

class AST_Node;
// statements
class Statement;
Expand Down Expand Up @@ -51,6 +53,7 @@ namespace Sass {
class String_Schema;
class String;
class String_Constant;
class String_Quoted;
class Media_Query;
class Media_Query_Expression;
class Feature_Query;
Expand Down
2 changes: 1 addition & 1 deletion bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace Sass {
// That's only okay if they have default values, or were already bound by
// named arguments, or if it's a single rest-param.
for (size_t i = ip; i < LP; ++i) {
To_String to_string;
To_String to_string(&ctx);
Parameter* leftover = (*ps)[i];
// cerr << "env for default params:" << endl;
// env->print();
Expand Down
4 changes: 0 additions & 4 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ namespace Sass {
names_to_colors (map<string, Color*>()),
colors_to_names (map<int, string>()),
precision (initializers.precision()),
_skip_source_map_update (initializers._skip_source_map_update()),
subset_map (Subset_Map<string, pair<Complex_Selector*, Compound_Selector*> >())
{
cwd = get_cwd();
Expand Down Expand Up @@ -277,9 +276,6 @@ namespace Sass {
Contextualize contextualize(*this, &eval, &tge, &backtrace);
Expand expand(*this, &eval, &contextualize, &tge, &backtrace);
Cssize cssize(*this, &tge, &backtrace);
// Inspect inspect(this);
// Output_Nested output_nested(*this);

root = root->perform(&expand)->block();
root = root->perform(&cssize)->block();
if (!subset_map.empty()) {
Expand Down
4 changes: 0 additions & 4 deletions context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ namespace Sass {
// typedef Environment<AST_Node*> Env;
// typedef Expression* (*Native_Function)(Env&, Context&, Signature, string, size_t);

enum Output_Style { NESTED, EXPANDED, COMPACT, COMPRESSED, FORMATTED };

struct Sass_Queued {
string abs_path;
string load_path;
Expand Down Expand Up @@ -79,7 +77,6 @@ namespace Sass {
map<int, string> colors_to_names;

size_t precision; // precision for outputting fractional numbers
bool _skip_source_map_update; // status flag to skip source map updates

KWD_ARG_SET(Data) {
KWD_ARG(Data, const char*, source_c_str);
Expand All @@ -97,7 +94,6 @@ namespace Sass {
KWD_ARG(Data, bool, omit_source_map_url);
KWD_ARG(Data, bool, is_indented_syntax_src);
KWD_ARG(Data, size_t, precision);
KWD_ARG(Data, bool, _skip_source_map_update);
KWD_ARG(Data, bool, source_map_embed);
KWD_ARG(Data, bool, source_map_contents);
KWD_ARG(Data, Sass_C_Import_Callback, importer);
Expand Down
8 changes: 4 additions & 4 deletions contextualize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Sass {

Selector* Contextualize::operator()(Selector_Schema* s)
{
To_String to_string;
To_String to_string(&ctx);
string result_str(s->contents()->perform(eval->with(env, backtrace))->perform(&to_string));
result_str += '{'; // the parser looks for a brace to end the selector
Selector* result_sel = Parser::from_c_str(result_str.c_str(), ctx, s->pstate()).parse_selector_group();
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace Sass {

Selector* Contextualize::operator()(Complex_Selector* s)
{
To_String to_string;
To_String to_string(&ctx);
Complex_Selector* ss = new (ctx.mem) Complex_Selector(*s);
Compound_Selector* new_head = 0;
Complex_Selector* new_tail = 0;
Expand Down Expand Up @@ -89,7 +89,7 @@ namespace Sass {

Selector* Contextualize::operator()(Compound_Selector* s)
{
To_String to_string;
To_String to_string(&ctx);
if (placeholder && extender && s->perform(&to_string) == placeholder->perform(&to_string)) {
return extender;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace Sass {

Selector* Contextualize::operator()(Selector_Placeholder* p)
{
To_String to_string;
To_String to_string(&ctx);
if (placeholder && extender && p->perform(&to_string) == placeholder->perform(&to_string)) {
return extender;
}
Expand Down
7 changes: 6 additions & 1 deletion cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Sass {
new_env.link(*env);
env = &new_env;
Block* bb = new (ctx.mem) Block(b->pstate(), b->length(), b->is_root());
// bb->tabs(b->tabs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to comment out these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it probably produced wrong output in my WIP branch and unit tests don't seem to fail. I will need to check nested/compressed rendering anyway in the end. The goal is to get 100% equal output as ruby sass (which my WIP branch currently does).

block_stack.push_back(bb);
append_block(b);
block_stack.pop_back();
Expand Down Expand Up @@ -97,6 +98,7 @@ namespace Sass {
Ruleset* rr = new (ctx.mem) Ruleset(r->pstate(),
r->selector(),
r->block()->perform(this)->block());
// rr->tabs(r->block()->tabs());
p_stack.pop_back();

Block* props = new Block(rr->block()->pstate());
Expand Down Expand Up @@ -191,6 +193,7 @@ namespace Sass {
{
Block* bb = m->block()->perform(this)->block();
for (size_t i = 0, L = bb->length(); i < L; ++i) {
(bb->elements())[i]->tabs(m->tabs());
if (bubblable((*bb)[i])) (*bb)[i]->tabs((*bb)[i]->tabs() + m->tabs());
}
if (bb->length() && bubblable(bb->last())) bb->last()->group_end(m->group_end());
Expand Down Expand Up @@ -295,6 +298,8 @@ namespace Sass {
wrapper_block,
m->selector());

mm->tabs(m->tabs());

Bubble* bubble = new (ctx.mem) Bubble(mm->pstate(), mm);

return bubble;
Expand Down Expand Up @@ -496,7 +501,7 @@ namespace Sass {

Media_Query* Cssize::merge_media_query(Media_Query* mq1, Media_Query* mq2)
{
To_String to_string;
To_String to_string(&ctx);

string type;
string mod;
Expand Down
Loading