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

Commit d6f089b

Browse files
committed
Merge branch 'master' of git://github.com/hcatlin/libsass into python
2 parents 07fcc3e + 169243a commit d6f089b

18 files changed

+1188
-709
lines changed

color_names.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#define SASS_COLOR_NAMES_INCLUDED
1+
#define SASS_COLOR_NAMES
22

33
namespace Sass {
44

context.cpp

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "context.hpp"
22
#include <cstring>
33
#include <iostream>
4+
#include <sstream>
45
#include <unistd.h>
56
#include "prelexer.hpp"
67
#include "color_names.hpp"
@@ -60,7 +61,7 @@ namespace Sass {
6061
collect_include_paths(paths_str);
6162
setup_color_map();
6263

63-
string path_string(img_path_str);
64+
string path_string(img_path_str ? img_path_str : "");
6465
path_string = "'" + path_string + "/'";
6566
image_path = new char[path_string.length() + 1];
6667
std::strcpy(image_path, path_string.c_str());
@@ -73,21 +74,20 @@ namespace Sass {
7374
}
7475
delete[] image_path;
7576
new_Node.free();
76-
// cerr << "Deallocated " << i << " source string(s)." << endl;
7777
}
7878

79-
inline void Context::register_function(Function_Descriptor d, Primitive ip)
79+
inline void Context::register_function(Signature sig, Primitive ip)
8080
{
81-
Function f(d, ip, new_Node);
82-
// function_env[pair<string, size_t>(f.name, f.parameters.size())] = f;
81+
Function f(const_cast<char*>(sig), ip, *this);
8382
function_env[f.name] = f;
8483
}
8584

86-
inline void Context::register_function(Function_Descriptor d, Primitive ip, size_t arity)
85+
inline void Context::register_function(Signature sig, Primitive ip, size_t arity)
8786
{
88-
Function f(d, ip, new_Node);
89-
// function_env[pair<string, size_t>(f.name, arity)] = f;
90-
function_env[f.name] = f;
87+
Function f(const_cast<char*>(sig), ip, *this);
88+
std::stringstream stub;
89+
stub << f.name << " " << arity;
90+
function_env[stub.str()] = f;
9191
}
9292

9393
inline void Context::register_overload_stub(string name)
@@ -98,66 +98,63 @@ namespace Sass {
9898
void Context::register_functions()
9999
{
100100
using namespace Functions;
101+
101102
// RGB Functions
102-
register_function(rgb_descriptor, rgb);
103+
register_function(rgb_sig, rgb);
103104
register_overload_stub("rgba");
104-
register_function(rgba_4_descriptor, rgba_4);
105-
register_function(rgba_2_descriptor, rgba_2);
106-
register_function(red_descriptor, red);
107-
register_function(green_descriptor, green);
108-
register_function(blue_descriptor, blue);
109-
register_overload_stub("mix");
110-
register_function(mix_2_descriptor, mix_2);
111-
register_function(mix_3_descriptor, mix_3);
105+
register_function(rgba_4_sig, rgba_4, 4);
106+
register_function(rgba_2_sig, rgba_2, 2);
107+
register_function(red_sig, red);
108+
register_function(green_sig, green);
109+
register_function(blue_sig, blue);
110+
register_function(mix_sig, mix);
112111
// HSL Functions
113-
register_function(hsla_descriptor, hsla);
114-
register_function(hsl_descriptor, hsl);
115-
register_function(invert_descriptor, invert);
112+
register_function(hsl_sig, hsl);
113+
register_function(hsla_sig, hsla);
114+
register_function(hue_sig, hue);
115+
register_function(saturation_sig, saturation);
116+
register_function(lightness_sig, lightness);
117+
register_function(adjust_hue_sig, adjust_hue);
118+
register_function(lighten_sig, lighten);
119+
register_function(darken_sig, darken);
120+
register_function(saturate_sig, saturate);
121+
register_function(desaturate_sig, desaturate);
122+
register_function(grayscale_sig, grayscale);
123+
register_function(complement_sig, complement);
124+
register_function(invert_sig, invert);
116125
// Opacity Functions
117-
register_function(alpha_descriptor, alpha);
118-
register_function(opacity_descriptor, alpha);
119-
register_function(opacify_descriptor, opacify);
120-
register_function(fade_in_descriptor, opacify);
121-
register_function(transparentize_descriptor, transparentize);
122-
register_function(fade_out_descriptor, transparentize);
126+
register_function(alpha_sig, alpha);
127+
register_function(opacity_sig, opacity);
128+
register_function(opacify_sig, opacify);
129+
register_function(fade_in_sig, fade_in);
130+
register_function(transparentize_sig, transparentize);
131+
register_function(fade_out_sig, fade_out);
132+
// Other Color Functions
133+
register_function(adjust_color_sig, adjust_color);
134+
register_function(change_color_sig, change_color);
123135
// String Functions
124-
register_function(unquote_descriptor, unquote);
125-
register_function(quote_descriptor, quote);
136+
register_function(unquote_sig, unquote);
137+
register_function(quote_sig, quote);
126138
// Number Functions
127-
register_function(percentage_descriptor, percentage);
128-
register_function(round_descriptor, round);
129-
register_function(ceil_descriptor, ceil);
130-
register_function(floor_descriptor, floor);
131-
register_function(abs_descriptor, abs);
139+
register_function(percentage_sig, percentage);
140+
register_function(round_sig, round);
141+
register_function(ceil_sig, ceil);
142+
register_function(floor_sig, floor);
143+
register_function(abs_sig, abs);
132144
// List Functions
133-
register_function(length_descriptor, length);
134-
register_function(nth_descriptor, nth);
135-
register_overload_stub("join");
136-
register_function(join_2_descriptor, join_2);
137-
register_function(join_3_descriptor, join_3);
138-
register_overload_stub("append");
139-
register_function(append_2_descriptor, append_2);
140-
register_function(append_3_descriptor, append_3);
141-
register_overload_stub("compact");
142-
register_function(compact_1_descriptor, compact);
143-
register_function(compact_2_descriptor, compact);
144-
register_function(compact_3_descriptor, compact);
145-
register_function(compact_4_descriptor, compact);
146-
register_function(compact_5_descriptor, compact);
147-
register_function(compact_6_descriptor, compact);
148-
register_function(compact_7_descriptor, compact);
149-
register_function(compact_8_descriptor, compact);
150-
register_function(compact_9_descriptor, compact);
151-
register_function(compact_10_descriptor, compact);
152-
register_function(compact_11_descriptor, compact);
153-
register_function(compact_12_descriptor, compact);
145+
register_function(length_sig, length);
146+
register_function(nth_sig, nth);
147+
register_function(join_sig, join);
148+
register_function(append_sig, append);
149+
register_function(compact_sig, compact);
154150
// Introspection Functions
155-
register_function(type_of_descriptor, type_of);
156-
register_function(unit_descriptor, unit);
157-
register_function(unitless_descriptor, unitless);
158-
register_function(comparable_descriptor, comparable);
151+
register_function(type_of_sig, type_of);
152+
register_function(unit_sig, unit);
153+
register_function(unitless_sig, unitless);
154+
register_function(comparable_sig, comparable);
159155
// Boolean Functions
160-
register_function(not_descriptor, not_impl);
156+
register_function(not_sig, not_impl);
157+
register_function(if_sig, if_impl);
161158
}
162159

163160
void Context::setup_color_map()

context.hpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,23 @@
1-
#define SASS_CONTEXT_INCLUDED
1+
#define SASS_CONTEXT
22

3+
//#ifndef SASS_ENVIRONMENT
4+
#include "environment.hpp"
5+
//#endif
36

47
#include <utility>
5-
#include <map>
8+
9+
#ifndef SASS_NODE_FACTORY
610
#include "node_factory.hpp"
11+
#endif
12+
13+
#ifndef SASS_FUNCTIONS
714
#include "functions.hpp"
15+
#endif
816

917
namespace Sass {
1018
using std::pair;
1119
using std::map;
1220

13-
struct Environment {
14-
map<Token, Node> current_frame;
15-
Environment* parent;
16-
Environment* global;
17-
18-
Environment()
19-
: current_frame(map<Token, Node>()), parent(0), global(0)
20-
{ }
21-
22-
void link(Environment& env)
23-
{
24-
parent = &env;
25-
global = parent->global ? parent->global : parent;
26-
}
27-
28-
bool query(const Token& key) const
29-
{
30-
if (current_frame.count(key)) return true;
31-
else if (parent) return parent->query(key);
32-
else return false;
33-
}
34-
35-
Node& operator[](const Token& key)
36-
{
37-
if (current_frame.count(key)) return current_frame[key];
38-
else if (parent) return (*parent)[key];
39-
else return current_frame[key];
40-
}
41-
};
42-
4321
struct Context {
4422
Environment global_env;
4523
map<string, Function> function_env;
@@ -59,9 +37,9 @@ namespace Sass {
5937
void collect_include_paths(const char* paths_str);
6038
Context(const char* paths_str = 0, const char* img_path_str = 0);
6139
~Context();
62-
63-
void register_function(Function_Descriptor d, Primitive ip);
64-
void register_function(Function_Descriptor d, Primitive ip, size_t arity);
40+
41+
void register_function(Signature sig, Primitive ip);
42+
void register_function(Signature sig, Primitive ip, size_t arity);
6543
void register_overload_stub(string name);
6644
void register_functions();
6745
void setup_color_map();

document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace Sass {
6767

6868
Document doc(ctx);
6969
doc.path = path;
70-
doc.line = 1;
70+
doc.line = 1;
7171
doc.root = ctx.new_Node(Node::root, path, 1, 0);
7272
doc.lexed = Token::make();
7373
doc.own_source = true;

document.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
#define SASS_DOCUMENT
2+
13
#include <map>
24

3-
#ifndef SASS_PRELEXER_INCLUDED
5+
#ifndef SASS_PRELEXER
46
#include "prelexer.hpp"
57
#endif
68

7-
#ifndef SASS_NODE_INCLUDED
9+
#ifndef SASS_NODE
810
#include "node.hpp"
911
#endif
1012

11-
#ifndef SASS_CONTEXT_INCLUDED
13+
#ifndef SASS_CONTEXT
1214
#include "context.hpp"
1315
#endif
1416

@@ -130,10 +132,10 @@ namespace Sass {
130132
Node parse_mixin_definition();
131133
Node parse_function_definition();
132134
Node parse_parameters();
133-
Node parse_parameter();
135+
Node parse_parameter(Node::Type);
134136
Node parse_mixin_call();
135137
Node parse_arguments();
136-
Node parse_argument();
138+
Node parse_argument(Node::Type);
137139
Node parse_assignment();
138140
Node parse_propset();
139141
Node parse_ruleset(Selector_Lookahead lookahead, Node::Type inside_of = Node::none);

0 commit comments

Comments
 (0)