Skip to content

Commit

Permalink
Implement missing output styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 1, 2015
1 parent 6cf40f5 commit 1f2f462
Show file tree
Hide file tree
Showing 29 changed files with 781 additions and 337 deletions.
1 change: 1 addition & 0 deletions ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ namespace Sass {
return 0;
}
}
rhs->has_line_break(has_line_break());
return Simple_Selector::unify_with(rhs, ctx);
}

Expand Down
34 changes: 14 additions & 20 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "util.hpp"
#include "units.hpp"
#include "context.hpp"
#include "position.hpp"
#include "constants.hpp"
#include "operation.hpp"
Expand All @@ -41,6 +42,7 @@
#include "environment.hpp"
#include "error_handling.hpp"
#include "ast_def_macros.hpp"
#include "ast_fwd_decl.hpp"
#include "to_string.hpp"

#include "sass.h"
Expand All @@ -53,10 +55,6 @@ namespace Sass {
//////////////////////////////////////////////////////////
// Abstract base class for all abstract syntax tree nodes.
//////////////////////////////////////////////////////////
class Block;
class Statement;
class Expression;
class Selector;
class AST_Node {
ADD_PROPERTY(ParserState, pstate);
public:
Expand Down Expand Up @@ -322,7 +320,6 @@ namespace Sass {
// Rulesets (i.e., sets of styles headed by a selector and containing a block
// of style declarations.
/////////////////////////////////////////////////////////////////////////////
class Selector;
class Ruleset : public Has_Block {
ADD_PROPERTY(Selector*, selector);
public:
Expand All @@ -338,7 +335,6 @@ namespace Sass {
/////////////////////////////////////////////////////////
// Nested declaration sets (i.e., namespaced properties).
/////////////////////////////////////////////////////////
class String;
class Propset : public Has_Block {
ADD_PROPERTY(String*, property_fragment);
public:
Expand All @@ -365,7 +361,6 @@ namespace Sass {
/////////////////
// Media queries.
/////////////////
class List;
class Media_Block : public Has_Block {
ADD_PROPERTY(List*, media_queries);
ADD_PROPERTY(Selector*, selector);
Expand Down Expand Up @@ -454,8 +449,6 @@ namespace Sass {
/////////////////////////////////////
// Assignments -- variable and value.
/////////////////////////////////////
class Variable;
class Expression;
class Assignment : public Statement {
ADD_PROPERTY(string, variable);
ADD_PROPERTY(Expression*, value);
Expand Down Expand Up @@ -538,9 +531,10 @@ namespace Sass {
///////////////////////////////////////////
class Comment : public Statement {
ADD_PROPERTY(String*, text);
ADD_PROPERTY(bool, is_important);
public:
Comment(ParserState pstate, String* txt)
: Statement(pstate), text_(txt)
Comment(ParserState pstate, String* txt, bool is_important)
: Statement(pstate), text_(txt), is_important_(is_important)
{ }
ATTACH_OPERATIONS();
};
Expand Down Expand Up @@ -629,9 +623,7 @@ namespace Sass {
// Definitions for both mixins and functions. The two cases are distinguished
// by a type tag.
/////////////////////////////////////////////////////////////////////////////
struct Context;
struct Backtrace;
class Parameters;
typedef Environment<AST_Node*> Env;
typedef const char* Signature;
typedef Expression* (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtrace*);
Expand Down Expand Up @@ -707,7 +699,6 @@ namespace Sass {
//////////////////////////////////////
// Mixin calls (i.e., `@include ...`).
//////////////////////////////////////
class Arguments;
class Mixin_Call : public Has_Block {
ADD_PROPERTY(string, name);
ADD_PROPERTY(Arguments*, arguments);
Expand Down Expand Up @@ -786,7 +777,6 @@ namespace Sass {
///////////////////////////////////////////////////////////////////////
// Key value paris.
///////////////////////////////////////////////////////////////////////

class Map : public Expression, public Hashed {
void adjust_after_pushing(std::pair<Expression*, Expression*> p) { is_expanded(false); }
public:
Expand Down Expand Up @@ -829,8 +819,6 @@ namespace Sass {
ATTACH_OPERATIONS();
};



//////////////////////////////////////////////////////////////////////////
// Binary expressions. Represents logical, relational, and arithmetic
// operations. Templatized to avoid large switch statements and repetitive
Expand Down Expand Up @@ -1706,11 +1694,17 @@ namespace Sass {
class Selector : public AST_Node {
ADD_PROPERTY(bool, has_reference);
ADD_PROPERTY(bool, has_placeholder);
// line break before list separator
ADD_PROPERTY(bool, has_line_feed);
// line break after list separator
ADD_PROPERTY(bool, has_line_break);
public:
Selector(ParserState pstate, bool r = false, bool h = false)
: AST_Node(pstate),
has_reference_(r),
has_placeholder_(h)
has_placeholder_(h),
has_line_feed_(false),
has_line_break_(false)
{ }
virtual ~Selector() = 0;
virtual Selector_Placeholder* find_placeholder();
Expand Down Expand Up @@ -1953,7 +1947,6 @@ namespace Sass {
// CSS selector combinators (">", "+", "~", and whitespace). Essentially a
// linked list.
////////////////////////////////////////////////////////////////////////////
struct Context;
class Complex_Selector : public Selector {
public:
enum Combinator { ANCESTOR_OF, PARENT_OF, PRECEDES, ADJACENT_TO };
Expand Down Expand Up @@ -2053,11 +2046,12 @@ namespace Sass {
#ifdef DEBUG
ADD_PROPERTY(string, mCachedSelector);
#endif
ADD_PROPERTY(vector<string>, wspace);
protected:
void adjust_after_pushing(Complex_Selector* c);
public:
Selector_List(ParserState pstate, size_t s = 0)
: Selector(pstate), Vectorized<Complex_Selector*>(s)
: Selector(pstate), Vectorized<Complex_Selector*>(s), wspace_(0)
{ }
virtual Selector_Placeholder* find_placeholder();
virtual int specificity()
Expand Down
19 changes: 10 additions & 9 deletions context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ namespace Sass {


Context::Context(Context::Data initializers)
: mem(Memory_Manager<AST_Node>()),
: // Output(this),
mem(Memory_Manager<AST_Node>()),
source_c_str (initializers.source_c_str()),
sources (vector<const char*>()),
include_paths (initializers.include_paths()),
queue (vector<Sass_Queued>()),
style_sheets (map<string, Block*>()),
source_map (resolve_relative_path(initializers.output_path(), initializers.source_map_file(), get_cwd())),
emitter (this),
c_functions (vector<Sass_C_Function_Callback>()),
indent (initializers.indent()),
linefeed (initializers.linefeed()),
Expand Down Expand Up @@ -90,6 +91,9 @@ namespace Sass {
throw "File to read not found or unreadable: " + entry_point;
}
}

emitter.set_filename(output_path);

}

Context::~Context()
Expand Down Expand Up @@ -162,7 +166,7 @@ namespace Sass {
sources.push_back(contents);
included_files.push_back(abs_path);
queue.push_back(Sass_Queued(load_path, abs_path, contents));
source_map.source_index.push_back(sources.size() - 1);
emitter.add_source_index(sources.size() - 1);
include_links.push_back(resolve_relative_path(abs_path, source_map_file, cwd));
}

Expand Down Expand Up @@ -222,15 +226,12 @@ namespace Sass {
char* Context::compile_block(Block* root)
{
if (!root) return 0;
Output emitter(this);
// emmitter.source_comments(source_comments);
root->perform(&emitter);
emitter.append_string("");
emitter.finalize();
string output = emitter.get_buffer();
if (source_map_file != "" && !omit_source_map_url) {
output += linefeed + format_source_mapping_url(source_map_file);
}
source_map = emitter.smap;
return copy_c_str(output.c_str());
}

Expand Down Expand Up @@ -304,7 +305,7 @@ namespace Sass {
{
string url = resolve_relative_path(file, output_path, cwd);
if (source_map_embed) {
string map = source_map.generate_source_map(*this);
string map = emitter.generate_source_map(*this);
istringstream is( map );
ostringstream buffer;
base64::encoder E;
Expand All @@ -319,7 +320,7 @@ namespace Sass {
{
if (source_map_file == "") return 0;
char* result = 0;
string map = source_map.generate_source_map(*this);
string map = emitter.generate_source_map(*this);
result = copy_c_str(map.c_str());
return result;
}
Expand Down
18 changes: 6 additions & 12 deletions context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,19 @@
#define BUFFERSIZE 255
#include "b64/encode.h"

#include "ast_fwd_decl.hpp"
#include "kwd_arg_macros.hpp"
#include "memory_manager.hpp"
#include "environment.hpp"
#include "source_map.hpp"
#include "subset_map.hpp"
#include "output.hpp"
#include "sass_functions.h"

struct Sass_C_Function_Descriptor;

namespace Sass {
using namespace std;
class AST_Node;
class Block;
class Expression;
class Color;
struct Backtrace;
// typedef const char* Signature;
// struct Context;
// typedef Environment<AST_Node*> Env;
// typedef Expression* (*Native_Function)(Env&, Context&, Signature, string, size_t);

struct Sass_Queued {
string abs_path;
string load_path;
Expand All @@ -37,7 +29,8 @@ namespace Sass {
Sass_Queued(const string& load_path, const string& abs_path, const char* source);
};

struct Context {
class Context {
public:
Memory_Manager<AST_Node> mem;

const char* source_c_str;
Expand All @@ -54,7 +47,8 @@ namespace Sass {
vector<string> include_paths; // lookup paths for includes
vector<Sass_Queued> queue; // queue of files to be parsed
map<string, Block*> style_sheets; // map of paths to ASTs
SourceMap source_map;
// SourceMap source_map;
Output emitter;
vector<Sass_C_Function_Callback> c_functions;

string indent; // String to be used for indentation
Expand Down
2 changes: 2 additions & 0 deletions contextualize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace Sass {
for (size_t j = 0, L = s->length(); j < L; ++j) {
parent = (*p)[i];
Complex_Selector* comb = static_cast<Complex_Selector*>((*s)[j]->perform(this));
if (parent->has_line_feed()) comb->has_line_feed(true);
if (comb) *ss << comb;
}
}
Expand Down Expand Up @@ -94,6 +95,7 @@ namespace Sass {
return extender;
}
Compound_Selector* ss = new (ctx.mem) Compound_Selector(s->pstate(), s->length());
ss->has_line_break(s->has_line_break());
for (size_t i = 0, L = s->length(); i < L; ++i) {
Simple_Selector* simp = static_cast<Simple_Selector*>((*s)[i]->perform(this));
if (simp) *ss << simp;
Expand Down
19 changes: 3 additions & 16 deletions contextualize.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
#ifndef SASS_CONTEXTUALIZE_H
#define SASS_CONTEXTUALIZE_H

#include "eval.hpp"
#include "context.hpp"
#include "operation.hpp"
#include "environment.hpp"
#include "ast_fwd_decl.hpp"

namespace Sass {
class AST_Node;
class Selector;
class Selector_Schema;
class Selector_List;
class Complex_Selector;
class Compound_Selector;
class Wrapped_Selector;
class Pseudo_Selector;
class Attribute_Selector;
class Selector_Qualifier;
class Type_Selector;
class Selector_Placeholder;
class Selector_Reference;
class Simple_Selector;
struct Context;
class Eval;
struct Backtrace;

typedef Environment<AST_Node*> Env;
Expand Down
2 changes: 1 addition & 1 deletion cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +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());
// (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
2 changes: 1 addition & 1 deletion cssize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <iostream>

#include "ast.hpp"
#include "context.hpp"
#include "operation.hpp"
#include "environment.hpp"

namespace Sass {
using namespace std;

struct Context;
typedef Environment<AST_Node*> Env;
struct Backtrace;

Expand Down
Loading

0 comments on commit 1f2f462

Please sign in to comment.