Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 922011d

Browse files
committed
Merge branch 'master' of git://github.com/hcatlin/libsass into python
2 parents 42110ae + a84b181 commit 922011d

20 files changed

+1029
-522
lines changed

backtrace.hpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#define SASS_BACKTRACE
2+
3+
#include <sstream>
4+
5+
namespace Sass {
6+
7+
using namespace std;
8+
9+
struct Backtrace {
10+
11+
Backtrace* parent;
12+
string path;
13+
size_t line;
14+
string caller;
15+
16+
Backtrace(Backtrace* prn, string pth, size_t ln, string c)
17+
: parent(prn),
18+
path(pth),
19+
line(ln),
20+
caller(c)
21+
{ }
22+
23+
string to_string(bool warning = false)
24+
{
25+
stringstream ss;
26+
Backtrace* this_point = this;
27+
28+
if (!warning) ss << endl << "Backtrace:";
29+
// the first tracepoint (which is parent-less) is an empty placeholder
30+
while (this_point->parent) {
31+
ss << endl
32+
<< "\t"
33+
<< (warning ? " " : "")
34+
<< this_point->path
35+
<< ":"
36+
<< this_point->line
37+
<< this_point->parent->caller;
38+
this_point = this_point->parent;
39+
}
40+
41+
return ss.str();
42+
}
43+
44+
};
45+
46+
}

constants.cpp

Lines changed: 3 additions & 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";
@@ -43,6 +44,7 @@ namespace Sass {
4344
extern const char kHz_kwd[] = "kHz";
4445

4546
// css functions and keywords
47+
extern const char charset_kwd[] = "@charset";
4648
extern const char media_kwd[] = "@media";
4749
extern const char only_kwd[] = "only";
4850
extern const char rgb_kwd[] = "rgb(";
@@ -83,6 +85,7 @@ namespace Sass {
8385
extern const char rbrace[] = "}";
8486
extern const char rparen[] = ")";
8587
extern const char sign_chars[] = "-+";
88+
extern const char hyphen[] = "-";
8689

8790
// type names
8891
extern const char numeric_name[] = "numeric value";

constants.hpp

Lines changed: 3 additions & 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[];
@@ -43,6 +44,7 @@ namespace Sass {
4344
extern const char kHz_kwd[];
4445

4546
// css functions and keywords
47+
extern const char charset_kwd[];
4648
extern const char media_kwd[];
4749
extern const char only_kwd[];
4850
extern const char rgb_kwd[];
@@ -83,6 +85,7 @@ namespace Sass {
8385
extern const char rbrace[];
8486
extern const char rparen[];
8587
extern const char sign_chars[];
88+
extern const char hyphen[];
8689

8790
// type names
8891
extern const char numeric_name[];

context.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#ifdef _WIN32
22
#include <direct.h>
33
#define getcwd _getcwd
4+
#define PATH_SEP ';'
45
#else
56
#include <unistd.h>
7+
#define PATH_SEP ':'
68
#endif
79

810
#include <cstring>
@@ -27,7 +29,7 @@ namespace Sass {
2729

2830
if (paths_str) {
2931
const char* beg = paths_str;
30-
const char* end = Prelexer::find_first<':'>(beg);
32+
const char* end = Prelexer::find_first<PATH_SEP>(beg);
3133

3234
while (end) {
3335
string path(beg, end - beg);
@@ -36,7 +38,7 @@ namespace Sass {
3638
include_paths.push_back(path);
3739
}
3840
beg = end + 1;
39-
end = Prelexer::find_first<':'>(beg);
41+
end = Prelexer::find_first<PATH_SEP>(beg);
4042
}
4143

4244
string path(beg);
@@ -51,7 +53,7 @@ namespace Sass {
5153
// }
5254
}
5355

54-
Context::Context(const char* paths_str, const char* img_path_str)
56+
Context::Context(const char* paths_str, const char* img_path_str, bool sc)
5557
: global_env(Environment()),
5658
function_env(map<string, Function>()),
5759
extensions(multimap<Node, Node>()),
@@ -63,7 +65,8 @@ namespace Sass {
6365
new_Node(Node_Factory()),
6466
image_path(0),
6567
ref_count(0),
66-
has_extensions(false)
68+
has_extensions(false),
69+
source_comments(sc)
6770
{
6871
register_functions();
6972
collect_include_paths(paths_str);
@@ -143,7 +146,8 @@ namespace Sass {
143146
// Other Color Functions
144147
register_function(adjust_color_sig, adjust_color);
145148
register_function(scale_color_sig, scale_color);
146-
register_function(change_color_sig, change_color);
149+
register_function(change_color_sig, change_color);
150+
register_function(ie_hex_str_sig, ie_hex_str);
147151
// String Functions
148152
register_function(unquote_sig, unquote);
149153
register_function(quote_sig, quote);

context.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ namespace Sass {
3333
// string sass_path;
3434
// string css_path;
3535
bool has_extensions;
36+
bool source_comments;
3637

3738
void collect_include_paths(const char* paths_str);
38-
Context(const char* paths_str = 0, const char* img_path_str = 0);
39+
Context(const char* paths_str = 0, const char* img_path_str = 0, bool sc = false);
3940
~Context();
4041

4142
void register_function(Signature sig, Primitive ip);

document.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,39 @@ namespace Sass {
3838
const char* path_str = path.c_str();
3939
struct stat st;
4040
string tmp;
41+
42+
// Resolution order for ambiguous imports:
43+
// (1) filename as given
44+
// (2) underscore + given
45+
// (3) underscore + given + extension
46+
// (4) given + extension
47+
48+
// if the file as given isn't found ...
4149
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode)) {
42-
tmp = path + ".scss";
50+
// then try "_" + given
51+
const char *full_path_str = path.c_str();
52+
const char *file_name_str = Prelexer::folders(full_path_str);
53+
string folder(Token::make(full_path_str, file_name_str).to_string());
54+
string partial_filename("_" + string(file_name_str));
55+
tmp = folder + partial_filename;
56+
path_str = tmp.c_str();
57+
// if "_" + given isn't found ...
58+
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode)) {
59+
// then try "_" + given + ".scss"
60+
tmp += ".scss";
4361
path_str = tmp.c_str();
62+
// if "_" + given + ".scss" isn't found ...
4463
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode)) {
45-
const char *full_path_str = path.c_str();
46-
const char *file_name_str = Prelexer::folders(full_path_str);
47-
tmp = Token::make(full_path_str, file_name_str).to_string() +
48-
"_" +
49-
string(file_name_str);
50-
path_str = tmp.c_str();
51-
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode)) {
52-
tmp = tmp + ".scss";
53-
path_str = tmp.c_str();
54-
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode))
55-
throw path;
56-
}
64+
// then try given + ".scss"
65+
string non_partial_filename(string(file_name_str) + ".scss");
66+
tmp = folder + non_partial_filename;
67+
path_str = tmp.c_str();
68+
// if we still can't find the file, then throw an error
69+
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode)) {
70+
throw path;
71+
}
5772
}
73+
}
5874
}
5975
f = std::fopen(path_str, "rb");
6076
size_t len = st.st_size;
@@ -71,7 +87,7 @@ namespace Sass {
7187
string include_path(path_str, file_name_str - path_str);
7288

7389
Document doc(ctx);
74-
doc.path = path;
90+
doc.path = path_str;
7591
doc.line = 1;
7692
doc.root = ctx.new_Node(Node::root, path, 1, 0);
7793
doc.lexed = Token::make();
@@ -80,9 +96,6 @@ namespace Sass {
8096
doc.end = end;
8197
doc.position = source;
8298
doc.context.source_refs.push_back(source);
83-
if (!include_path.empty()) {
84-
doc.context.include_paths.push_back(include_path);
85-
}
8699

87100
return doc;
88101
}
@@ -135,11 +148,14 @@ namespace Sass {
135148
root.echo(output);
136149
break;
137150
case nested:
138-
root.emit_nested_css(output, 0, true);
151+
root.emit_nested_css(output, 0, true, false, context.source_comments);
139152
break;
140153
case expanded:
141154
root.emit_expanded_css(output, "");
142155
break;
156+
case compressed:
157+
root.emit_compressed_css(output);
158+
break;
143159
default:
144160
break;
145161
}

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();

0 commit comments

Comments
 (0)