sassc 1.7.1 → 1.8.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/ext/libsass/.gitignore +10 -6
  4. data/ext/libsass/.travis.yml +4 -1
  5. data/ext/libsass/GNUmakefile.am +88 -0
  6. data/ext/libsass/Makefile +157 -76
  7. data/ext/libsass/Makefile.conf +47 -0
  8. data/ext/libsass/Readme.md +13 -14
  9. data/ext/libsass/appveyor.yml +25 -41
  10. data/ext/libsass/configure.ac +20 -7
  11. data/ext/libsass/contrib/plugin.cpp +1 -1
  12. data/ext/libsass/include/sass.h +15 -0
  13. data/ext/libsass/{sass.h → include/sass/base.h} +17 -9
  14. data/ext/libsass/{sass_context.h → include/sass/context.h} +3 -1
  15. data/ext/libsass/{sass_functions.h → include/sass/functions.h} +4 -4
  16. data/ext/libsass/{sass_interface.h → include/sass/interface.h} +5 -2
  17. data/ext/libsass/{sass_values.h → include/sass/values.h} +15 -1
  18. data/ext/libsass/{sass_version.h → include/sass/version.h} +0 -0
  19. data/ext/libsass/{sass_version.h.in → include/sass/version.h.in} +0 -0
  20. data/ext/libsass/{sass2scss.h → include/sass2scss.h} +6 -7
  21. data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +167 -0
  22. data/ext/libsass/script/ci-build-libsass +67 -23
  23. data/ext/libsass/src/GNUmakefile.am +54 -0
  24. data/ext/libsass/src/ast.cpp +2029 -0
  25. data/ext/libsass/{ast.hpp → src/ast.hpp} +832 -660
  26. data/ext/libsass/src/ast_def_macros.hpp +47 -0
  27. data/ext/libsass/src/ast_factory.hpp +93 -0
  28. data/ext/libsass/{ast_fwd_decl.hpp → src/ast_fwd_decl.hpp} +9 -4
  29. data/ext/libsass/{b64 → src/b64}/cencode.h +1 -1
  30. data/ext/libsass/{b64 → src/b64}/encode.h +0 -0
  31. data/ext/libsass/{backtrace.hpp → src/backtrace.hpp} +9 -10
  32. data/ext/libsass/{base64vlq.cpp → src/base64vlq.cpp} +2 -2
  33. data/ext/libsass/{base64vlq.hpp → src/base64vlq.hpp} +1 -2
  34. data/ext/libsass/{bind.cpp → src/bind.cpp} +96 -59
  35. data/ext/libsass/{bind.hpp → src/bind.hpp} +1 -1
  36. data/ext/libsass/src/c99func.c +54 -0
  37. data/ext/libsass/{cencode.c → src/cencode.c} +5 -5
  38. data/ext/libsass/src/color_maps.cpp +643 -0
  39. data/ext/libsass/src/color_maps.hpp +333 -0
  40. data/ext/libsass/{constants.cpp → src/constants.cpp} +10 -1
  41. data/ext/libsass/{constants.hpp → src/constants.hpp} +7 -0
  42. data/ext/libsass/{context.cpp → src/context.cpp} +152 -122
  43. data/ext/libsass/src/context.hpp +150 -0
  44. data/ext/libsass/{cssize.cpp → src/cssize.cpp} +123 -109
  45. data/ext/libsass/{cssize.hpp → src/cssize.hpp} +9 -13
  46. data/ext/libsass/{debug.hpp → src/debug.hpp} +9 -9
  47. data/ext/libsass/src/debugger.hpp +683 -0
  48. data/ext/libsass/{emitter.cpp → src/emitter.cpp} +13 -13
  49. data/ext/libsass/{emitter.hpp → src/emitter.hpp} +10 -11
  50. data/ext/libsass/src/environment.cpp +184 -0
  51. data/ext/libsass/src/environment.hpp +92 -0
  52. data/ext/libsass/src/error_handling.cpp +46 -0
  53. data/ext/libsass/src/error_handling.hpp +34 -0
  54. data/ext/libsass/src/eval.cpp +1462 -0
  55. data/ext/libsass/src/eval.hpp +107 -0
  56. data/ext/libsass/src/expand.cpp +653 -0
  57. data/ext/libsass/{expand.hpp → src/expand.hpp} +17 -16
  58. data/ext/libsass/{extend.cpp → src/extend.cpp} +198 -139
  59. data/ext/libsass/{extend.hpp → src/extend.hpp} +7 -8
  60. data/ext/libsass/{file.cpp → src/file.cpp} +103 -57
  61. data/ext/libsass/{file.hpp → src/file.hpp} +23 -14
  62. data/ext/libsass/{functions.cpp → src/functions.cpp} +642 -333
  63. data/ext/libsass/{functions.hpp → src/functions.hpp} +17 -4
  64. data/ext/libsass/{inspect.cpp → src/inspect.cpp} +147 -260
  65. data/ext/libsass/{inspect.hpp → src/inspect.hpp} +7 -7
  66. data/ext/libsass/{json.cpp → src/json.cpp} +33 -43
  67. data/ext/libsass/{json.hpp → src/json.hpp} +1 -1
  68. data/ext/libsass/{kwd_arg_macros.hpp → src/kwd_arg_macros.hpp} +0 -0
  69. data/ext/libsass/{lexer.cpp → src/lexer.cpp} +28 -0
  70. data/ext/libsass/{lexer.hpp → src/lexer.hpp} +25 -10
  71. data/ext/libsass/{listize.cpp → src/listize.cpp} +17 -13
  72. data/ext/libsass/{listize.hpp → src/listize.hpp} +0 -2
  73. data/ext/libsass/{mapping.hpp → src/mapping.hpp} +0 -0
  74. data/ext/libsass/src/memory_manager.cpp +76 -0
  75. data/ext/libsass/src/memory_manager.hpp +48 -0
  76. data/ext/libsass/{node.cpp → src/node.cpp} +89 -18
  77. data/ext/libsass/{node.hpp → src/node.hpp} +5 -6
  78. data/ext/libsass/{operation.hpp → src/operation.hpp} +18 -12
  79. data/ext/libsass/{output.cpp → src/output.cpp} +47 -55
  80. data/ext/libsass/{output.hpp → src/output.hpp} +5 -4
  81. data/ext/libsass/src/parser.cpp +2529 -0
  82. data/ext/libsass/{parser.hpp → src/parser.hpp} +84 -60
  83. data/ext/libsass/{paths.hpp → src/paths.hpp} +10 -13
  84. data/ext/libsass/{plugins.cpp → src/plugins.cpp} +14 -17
  85. data/ext/libsass/{plugins.hpp → src/plugins.hpp} +10 -11
  86. data/ext/libsass/{position.cpp → src/position.cpp} +5 -6
  87. data/ext/libsass/{position.hpp → src/position.hpp} +19 -22
  88. data/ext/libsass/{prelexer.cpp → src/prelexer.cpp} +401 -53
  89. data/ext/libsass/{prelexer.hpp → src/prelexer.hpp} +50 -10
  90. data/ext/libsass/{remove_placeholders.cpp → src/remove_placeholders.cpp} +12 -16
  91. data/ext/libsass/{remove_placeholders.hpp → src/remove_placeholders.hpp} +1 -7
  92. data/ext/libsass/{sass.cpp → src/sass.cpp} +3 -5
  93. data/ext/libsass/{sass2scss.cpp → src/sass2scss.cpp} +51 -46
  94. data/ext/libsass/{sass_context.cpp → src/sass_context.cpp} +114 -112
  95. data/ext/libsass/{sass_functions.cpp → src/sass_functions.cpp} +11 -18
  96. data/ext/libsass/{sass_interface.cpp → src/sass_interface.cpp} +44 -81
  97. data/ext/libsass/{sass_util.cpp → src/sass_util.cpp} +26 -8
  98. data/ext/libsass/{sass_util.hpp → src/sass_util.hpp} +14 -18
  99. data/ext/libsass/{sass_values.cpp → src/sass_values.cpp} +91 -20
  100. data/ext/libsass/{source_map.cpp → src/source_map.cpp} +13 -13
  101. data/ext/libsass/{source_map.hpp → src/source_map.hpp} +9 -9
  102. data/ext/libsass/{subset_map.hpp → src/subset_map.hpp} +29 -31
  103. data/ext/libsass/{support → src/support}/libsass.pc.in +0 -0
  104. data/ext/libsass/src/to_c.cpp +73 -0
  105. data/ext/libsass/src/to_c.hpp +41 -0
  106. data/ext/libsass/src/to_string.cpp +47 -0
  107. data/ext/libsass/{to_string.hpp → src/to_string.hpp} +9 -7
  108. data/ext/libsass/src/to_value.cpp +109 -0
  109. data/ext/libsass/src/to_value.hpp +50 -0
  110. data/ext/libsass/{units.cpp → src/units.cpp} +56 -51
  111. data/ext/libsass/{units.hpp → src/units.hpp} +8 -9
  112. data/ext/libsass/{utf8.h → src/utf8.h} +0 -0
  113. data/ext/libsass/{utf8 → src/utf8}/checked.h +0 -0
  114. data/ext/libsass/{utf8 → src/utf8}/core.h +12 -12
  115. data/ext/libsass/{utf8 → src/utf8}/unchecked.h +0 -0
  116. data/ext/libsass/{utf8_string.cpp → src/utf8_string.cpp} +0 -0
  117. data/ext/libsass/{utf8_string.hpp → src/utf8_string.hpp} +6 -6
  118. data/ext/libsass/{util.cpp → src/util.cpp} +144 -86
  119. data/ext/libsass/src/util.hpp +59 -0
  120. data/ext/libsass/src/values.cpp +137 -0
  121. data/ext/libsass/src/values.hpp +12 -0
  122. data/ext/libsass/test/test_node.cpp +33 -33
  123. data/ext/libsass/test/test_paths.cpp +5 -6
  124. data/ext/libsass/test/test_selector_difference.cpp +4 -5
  125. data/ext/libsass/test/test_specificity.cpp +4 -5
  126. data/ext/libsass/test/test_subset_map.cpp +91 -91
  127. data/ext/libsass/test/test_superselector.cpp +11 -11
  128. data/ext/libsass/test/test_unification.cpp +4 -4
  129. data/ext/libsass/win/libsass.targets +101 -0
  130. data/ext/libsass/win/libsass.vcxproj +45 -127
  131. data/ext/libsass/win/libsass.vcxproj.filters +303 -0
  132. data/lib/sassc/import_handler.rb +1 -1
  133. data/lib/sassc/native/native_functions_api.rb +3 -3
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/custom_importer_test.rb +1 -4
  136. data/test/functions_test.rb +3 -2
  137. data/test/native_test.rb +4 -3
  138. metadata +117 -110
  139. data/ext/libsass/Makefile.am +0 -146
  140. data/ext/libsass/ast.cpp +0 -945
  141. data/ext/libsass/ast_def_macros.hpp +0 -21
  142. data/ext/libsass/ast_factory.hpp +0 -92
  143. data/ext/libsass/color_names.hpp +0 -327
  144. data/ext/libsass/context.hpp +0 -157
  145. data/ext/libsass/contextualize.cpp +0 -148
  146. data/ext/libsass/contextualize.hpp +0 -46
  147. data/ext/libsass/contextualize_eval.cpp +0 -93
  148. data/ext/libsass/contextualize_eval.hpp +0 -44
  149. data/ext/libsass/debugger.hpp +0 -558
  150. data/ext/libsass/environment.hpp +0 -163
  151. data/ext/libsass/error_handling.cpp +0 -35
  152. data/ext/libsass/error_handling.hpp +0 -32
  153. data/ext/libsass/eval.cpp +0 -1392
  154. data/ext/libsass/eval.hpp +0 -88
  155. data/ext/libsass/expand.cpp +0 -575
  156. data/ext/libsass/memory_manager.hpp +0 -57
  157. data/ext/libsass/parser.cpp +0 -2403
  158. data/ext/libsass/posix/getopt.c +0 -562
  159. data/ext/libsass/posix/getopt.h +0 -95
  160. data/ext/libsass/to_c.cpp +0 -61
  161. data/ext/libsass/to_c.hpp +0 -44
  162. data/ext/libsass/to_string.cpp +0 -34
  163. data/ext/libsass/util.hpp +0 -54
  164. data/ext/libsass/win/libsass.filters +0 -312
@@ -1,11 +1,3 @@
1
- #ifdef _WIN32
2
- #include <io.h>
3
- #define LFEED "\n"
4
- #else
5
- #include <unistd.h>
6
- #define LFEED "\n"
7
- #endif
8
-
9
1
  #include <string>
10
2
  #include <cstdlib>
11
3
  #include <cstring>
@@ -16,47 +8,16 @@
16
8
  #include "context.hpp"
17
9
  #include "inspect.hpp"
18
10
  #include "error_handling.hpp"
19
- #include "sass_interface.h"
11
+ #include "sass/base.h"
12
+ #include "sass/interface.h"
20
13
 
14
+ #define LFEED "\n"
21
15
 
22
16
  extern "C" {
23
- using namespace std;
24
17
 
25
18
  sass_context* sass_new_context()
26
19
  { return (sass_context*) calloc(1, sizeof(sass_context)); }
27
20
 
28
- // helper for safe access to c_ctx
29
- static const char* safe_str (const char* str) {
30
- return str == NULL ? "" : str;
31
- }
32
-
33
- static void copy_strings(const std::vector<std::string>& strings, char*** array, int skip = 0) {
34
- int num = static_cast<int>(strings.size());
35
- char** arr = (char**) malloc(sizeof(char*) * (num + 1));
36
-
37
- for(int i = skip; i < num; i++) {
38
- arr[i-skip] = (char*) malloc(sizeof(char) * (strings[i].size() + 1));
39
- std::copy(strings[i].begin(), strings[i].end(), arr[i-skip]);
40
- arr[i-skip][strings[i].size()] = '\0';
41
- }
42
-
43
- arr[num-skip] = 0;
44
- *array = arr;
45
- }
46
-
47
- static void free_string_array(char ** arr) {
48
- if(!arr)
49
- return;
50
-
51
- char **it = arr;
52
- while (it && (*it)) {
53
- free(*it);
54
- ++it;
55
- }
56
-
57
- free(arr);
58
- }
59
-
60
21
  void sass_free_context(sass_context* ctx)
61
22
  {
62
23
  if (ctx->output_string) free(ctx->output_string);
@@ -64,7 +25,7 @@ extern "C" {
64
25
  if (ctx->error_message) free(ctx->error_message);
65
26
  if (ctx->c_functions) free(ctx->c_functions);
66
27
 
67
- free_string_array(ctx->included_files);
28
+ Sass::free_string_array(ctx->included_files);
68
29
 
69
30
  free(ctx);
70
31
  }
@@ -79,7 +40,7 @@ extern "C" {
79
40
  if (ctx->error_message) free(ctx->error_message);
80
41
  if (ctx->c_functions) free(ctx->c_functions);
81
42
 
82
- free_string_array(ctx->included_files);
43
+ Sass::free_string_array(ctx->included_files);
83
44
 
84
45
  free(ctx);
85
46
  }
@@ -89,7 +50,7 @@ extern "C" {
89
50
 
90
51
  void sass_free_folder_context(sass_folder_context* ctx)
91
52
  {
92
- free_string_array(ctx->included_files);
53
+ Sass::free_string_array(ctx->included_files);
93
54
  free(ctx);
94
55
  }
95
56
 
@@ -97,9 +58,9 @@ extern "C" {
97
58
  {
98
59
  using namespace Sass;
99
60
  try {
100
- string input_path = safe_str(c_ctx->input_path);
61
+ std::string input_path = safe_str(c_ctx->input_path);
101
62
  int lastindex = static_cast<int>(input_path.find_last_of("."));
102
- string output_path;
63
+ std::string output_path;
103
64
  if (!c_ctx->output_path) {
104
65
  if (input_path != "") {
105
66
  output_path = (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css";
@@ -123,8 +84,8 @@ extern "C" {
123
84
  .plugin_paths_c_str(c_ctx->options.plugin_paths)
124
85
  // .include_paths_array(0)
125
86
  // .plugin_paths_array(0)
126
- .include_paths(vector<string>())
127
- .plugin_paths(vector<string>())
87
+ .include_paths(std::vector<std::string>())
88
+ .plugin_paths(std::vector<std::string>())
128
89
  .precision(c_ctx->options.precision ? c_ctx->options.precision : 5)
129
90
  .indent(c_ctx->options.indent ? c_ctx->options.indent : " ")
130
91
  .linefeed(c_ctx->options.linefeed ? c_ctx->options.linefeed : LFEED)
@@ -141,35 +102,36 @@ extern "C" {
141
102
  c_ctx->error_message = 0;
142
103
  c_ctx->error_status = 0;
143
104
 
144
- copy_strings(cpp_ctx.get_included_files(1), &c_ctx->included_files, 1);
105
+ if (copy_strings(cpp_ctx.get_included_files(true), &c_ctx->included_files, 1) == NULL)
106
+ throw(std::bad_alloc());
145
107
  }
146
- catch (Sass_Error& e) {
147
- stringstream msg_stream;
148
- msg_stream << e.pstate.path << ":" << e.pstate.line << ": " << e.message << endl;
108
+ catch (Error_Invalid& e) {
109
+ std::stringstream msg_stream;
110
+ msg_stream << e.pstate.path << ":" << e.pstate.line << ": " << e.message << std::endl;
149
111
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
150
112
  c_ctx->error_status = 1;
151
113
  c_ctx->output_string = 0;
152
114
  c_ctx->source_map_string = 0;
153
115
  }
154
- catch(bad_alloc& ba) {
155
- stringstream msg_stream;
156
- msg_stream << "Unable to allocate memory: " << ba.what() << endl;
116
+ catch(std::bad_alloc& ba) {
117
+ std::stringstream msg_stream;
118
+ msg_stream << "Unable to allocate memory: " << ba.what() << std::endl;
157
119
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
158
120
  c_ctx->error_status = 1;
159
121
  c_ctx->output_string = 0;
160
122
  c_ctx->source_map_string = 0;
161
123
  }
162
124
  catch (std::exception& e) {
163
- stringstream msg_stream;
164
- msg_stream << "Error: " << e.what() << endl;
125
+ std::stringstream msg_stream;
126
+ msg_stream << "Error: " << e.what() << std::endl;
165
127
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
166
128
  c_ctx->error_status = 1;
167
129
  c_ctx->output_string = 0;
168
130
  c_ctx->source_map_string = 0;
169
131
  }
170
- catch (string& e) {
171
- stringstream msg_stream;
172
- msg_stream << "Error: " << e << endl;
132
+ catch (std::string& e) {
133
+ std::stringstream msg_stream;
134
+ msg_stream << "Error: " << e << std::endl;
173
135
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
174
136
  c_ctx->error_status = 1;
175
137
  c_ctx->output_string = 0;
@@ -177,8 +139,8 @@ extern "C" {
177
139
  }
178
140
  catch (...) {
179
141
  // couldn't find the specified file in the include paths; report an error
180
- stringstream msg_stream;
181
- msg_stream << "Unknown error occurred" << endl;
142
+ std::stringstream msg_stream;
143
+ msg_stream << "Unknown error occurred" << std::endl;
182
144
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
183
145
  c_ctx->error_status = 1;
184
146
  c_ctx->output_string = 0;
@@ -191,9 +153,9 @@ extern "C" {
191
153
  {
192
154
  using namespace Sass;
193
155
  try {
194
- string input_path = safe_str(c_ctx->input_path);
156
+ std::string input_path = safe_str(c_ctx->input_path);
195
157
  int lastindex = static_cast<int>(input_path.find_last_of("."));
196
- string output_path;
158
+ std::string output_path;
197
159
  if (!c_ctx->output_path) {
198
160
  output_path = (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css";
199
161
  }
@@ -215,8 +177,8 @@ extern "C" {
215
177
  .plugin_paths_c_str(c_ctx->options.plugin_paths)
216
178
  // .include_paths_array(0)
217
179
  // .plugin_paths_array(0)
218
- .include_paths(vector<string>())
219
- .plugin_paths(vector<string>())
180
+ .include_paths(std::vector<std::string>())
181
+ .plugin_paths(std::vector<std::string>())
220
182
  .precision(c_ctx->options.precision ? c_ctx->options.precision : 5)
221
183
  .indent(c_ctx->options.indent ? c_ctx->options.indent : " ")
222
184
  .linefeed(c_ctx->options.linefeed ? c_ctx->options.linefeed : LFEED)
@@ -233,35 +195,36 @@ extern "C" {
233
195
  c_ctx->error_message = 0;
234
196
  c_ctx->error_status = 0;
235
197
 
236
- copy_strings(cpp_ctx.get_included_files(), &c_ctx->included_files);
198
+ if (copy_strings(cpp_ctx.get_included_files(false), &c_ctx->included_files) == NULL)
199
+ throw(std::bad_alloc());
237
200
  }
238
- catch (Sass_Error& e) {
239
- stringstream msg_stream;
240
- msg_stream << e.pstate.path << ":" << e.pstate.line << ": " << e.message << endl;
201
+ catch (Error_Invalid& e) {
202
+ std::stringstream msg_stream;
203
+ msg_stream << e.pstate.path << ":" << e.pstate.line << ": " << e.message << std::endl;
241
204
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
242
205
  c_ctx->error_status = 1;
243
206
  c_ctx->output_string = 0;
244
207
  c_ctx->source_map_string = 0;
245
208
  }
246
- catch(bad_alloc& ba) {
247
- stringstream msg_stream;
248
- msg_stream << "Unable to allocate memory: " << ba.what() << endl;
209
+ catch(std::bad_alloc& ba) {
210
+ std::stringstream msg_stream;
211
+ msg_stream << "Unable to allocate memory: " << ba.what() << std::endl;
249
212
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
250
213
  c_ctx->error_status = 1;
251
214
  c_ctx->output_string = 0;
252
215
  c_ctx->source_map_string = 0;
253
216
  }
254
217
  catch (std::exception& e) {
255
- stringstream msg_stream;
256
- msg_stream << "Error: " << e.what() << endl;
218
+ std::stringstream msg_stream;
219
+ msg_stream << "Error: " << e.what() << std::endl;
257
220
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
258
221
  c_ctx->error_status = 1;
259
222
  c_ctx->output_string = 0;
260
223
  c_ctx->source_map_string = 0;
261
224
  }
262
- catch (string& e) {
263
- stringstream msg_stream;
264
- msg_stream << "Error: " << e << endl;
225
+ catch (std::string& e) {
226
+ std::stringstream msg_stream;
227
+ msg_stream << "Error: " << e << std::endl;
265
228
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
266
229
  c_ctx->error_status = 1;
267
230
  c_ctx->output_string = 0;
@@ -269,8 +232,8 @@ extern "C" {
269
232
  }
270
233
  catch (...) {
271
234
  // couldn't find the specified file in the include paths; report an error
272
- stringstream msg_stream;
273
- msg_stream << "Unknown error occurred" << endl;
235
+ std::stringstream msg_stream;
236
+ msg_stream << "Unknown error occurred" << std::endl;
274
237
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
275
238
  c_ctx->error_status = 1;
276
239
  c_ctx->output_string = 0;
@@ -5,8 +5,8 @@ namespace Sass {
5
5
 
6
6
 
7
7
  /*
8
- This is the equivalent of ruby's Sass::Util.paths.
9
-
8
+ # This is the equivalent of ruby's Sass::Util.paths.
9
+ #
10
10
  # Return an array of all possible paths through the given arrays.
11
11
  #
12
12
  # @param arrs [NodeCollection<NodeCollection<Node>>]
@@ -23,7 +23,7 @@ namespace Sass {
23
23
  should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
24
24
 
25
25
  def paths(arrs)
26
- // I changed the inject and maps to an iterative approach to make it easier to implement in C++
26
+ // I changed the inject and maps to an iterative approach to make it easier to implement in C++
27
27
  loopStart = [[]]
28
28
 
29
29
  for arr in arrs do
@@ -36,7 +36,7 @@ namespace Sass {
36
36
  loopStart = permutations
37
37
  end
38
38
  end
39
- */
39
+ */
40
40
  Node paths(const Node& arrs, Context& ctx) {
41
41
  To_String to_string(&ctx);
42
42
 
@@ -61,6 +61,7 @@ namespace Sass {
61
61
  Node& path = *loopStartIter;
62
62
 
63
63
  Node newPermutation = Node::createCollection();
64
+ newPermutation.got_line_feed = arr.got_line_feed;
64
65
  newPermutation.plus(path);
65
66
  newPermutation.collection()->push_back(e);
66
67
 
@@ -75,7 +76,7 @@ namespace Sass {
75
76
  }
76
77
 
77
78
 
78
- /*
79
+ /*
79
80
  This is the equivalent of ruby sass' Sass::Util.flatten and [].flatten.
80
81
  Sass::Util.flatten requires the number of levels to flatten, while
81
82
  [].flatten doesn't and will flatten the entire array. This function
@@ -108,20 +109,37 @@ namespace Sass {
108
109
  return flattened
109
110
  end
110
111
  */
111
- Node flatten(const Node& arr, Context& ctx, int n = -1) {
112
+ Node flatten(Node& arr, Context& ctx, int n) {
112
113
  if (n != -1 && n == 0) {
113
114
  return arr;
114
115
  }
115
116
 
116
117
  Node flattened = Node::createCollection();
118
+ if (arr.got_line_feed) flattened.got_line_feed = true;
117
119
 
118
120
  for (NodeDeque::iterator iter = arr.collection()->begin(), iterEnd = arr.collection()->end();
119
121
  iter != iterEnd; iter++) {
120
122
  Node& e = *iter;
121
123
 
124
+ // e has the lf set
122
125
  if (e.isCollection()) {
126
+
127
+ // e.collection().got_line_feed = e.got_line_feed;
123
128
  Node recurseFlattened = flatten(e, ctx, n - 1);
124
- flattened.collection()->insert(flattened.collection()->end(), recurseFlattened.collection()->begin(), recurseFlattened.collection()->end());
129
+
130
+ if(e.got_line_feed) {
131
+ flattened.got_line_feed = e.got_line_feed;
132
+ recurseFlattened.got_line_feed = e.got_line_feed;
133
+ }
134
+
135
+ for(auto i : (*recurseFlattened.collection())) {
136
+ if (recurseFlattened.got_line_feed) {
137
+
138
+ i.got_line_feed = true;
139
+ }
140
+ flattened.collection()->push_back(i);
141
+ }
142
+
125
143
  } else {
126
144
  flattened.collection()->push_back(e);
127
145
  }
@@ -129,4 +147,4 @@ namespace Sass {
129
147
 
130
148
  return flattened;
131
149
  }
132
- }
150
+ }
@@ -1,9 +1,6 @@
1
1
  #ifndef SASS_SASS_UTIL_H
2
2
  #define SASS_SASS_UTIL_H
3
3
 
4
- #include <deque>
5
- #include <iostream>
6
-
7
4
  #include "ast.hpp"
8
5
  #include "node.hpp"
9
6
  #include "debug.hpp"
@@ -11,7 +8,6 @@
11
8
  namespace Sass {
12
9
 
13
10
 
14
- using namespace std;
15
11
 
16
12
 
17
13
  /*
@@ -54,7 +50,7 @@ namespace Sass {
54
50
  };
55
51
 
56
52
 
57
- typedef vector<vector<int> > LCSTable;
53
+ typedef std::vector<std::vector<int> > LCSTable;
58
54
 
59
55
 
60
56
  /*
@@ -106,7 +102,7 @@ namespace Sass {
106
102
  NodeDeque& xChildren = *(x.collection());
107
103
  NodeDeque& yChildren = *(y.collection());
108
104
 
109
- LCSTable c(xChildren.size(), vector<int>(yChildren.size()));
105
+ LCSTable c(xChildren.size(), std::vector<int>(yChildren.size()));
110
106
 
111
107
  // These shouldn't be necessary since the vector will be initialized to 0 already.
112
108
  // x.size.times {|i| c[i][0] = 0}
@@ -119,7 +115,7 @@ namespace Sass {
119
115
  if (comparator(xChildren[i], yChildren[j], compareOut)) {
120
116
  c[i][j] = c[i - 1][j - 1] + 1;
121
117
  } else {
122
- c[i][j] = max(c[i][j - 1], c[i - 1][j]);
118
+ c[i][j] = std::max(c[i][j - 1], c[i - 1][j]);
123
119
  }
124
120
  }
125
121
  }
@@ -173,7 +169,7 @@ namespace Sass {
173
169
  # @param n [int] The number of levels to flatten
174
170
  # @return [NodeCollection] The flattened array
175
171
  */
176
- Node flatten(const Node& arr, Context& ctx, int n = -1);
172
+ Node flatten(Node& arr, Context& ctx, int n = -1);
177
173
 
178
174
 
179
175
  /*
@@ -221,34 +217,34 @@ namespace Sass {
221
217
 
222
218
  */
223
219
  template<typename EnumType, typename KeyType, typename KeyFunctorType>
224
- void group_by_to_a(vector<EnumType>& enumeration, KeyFunctorType& keyFunc, vector<pair<KeyType, vector<EnumType> > >& arr /*out*/) {
220
+ void group_by_to_a(std::vector<EnumType>& enumeration, KeyFunctorType& keyFunc, std::vector<std::pair<KeyType, std::vector<EnumType> > >& arr /*out*/) {
225
221
 
226
- map<unsigned int, KeyType> order;
222
+ std::map<unsigned int, KeyType> order;
227
223
 
228
- map<KeyType, vector<EnumType> > grouped;
224
+ std::map<KeyType, std::vector<EnumType> > grouped;
229
225
 
230
- for (typename vector<EnumType>::iterator enumIter = enumeration.begin(), enumIterEnd = enumeration.end(); enumIter != enumIterEnd; enumIter++) {
226
+ for (typename std::vector<EnumType>::iterator enumIter = enumeration.begin(), enumIterEnd = enumeration.end(); enumIter != enumIterEnd; enumIter++) {
231
227
  EnumType& e = *enumIter;
232
228
 
233
229
  KeyType key = keyFunc(e);
234
230
 
235
231
  if (grouped.find(key) == grouped.end()) {
236
- order.insert(make_pair(order.size(), key));
232
+ order.insert(std::make_pair((unsigned int)order.size(), key));
237
233
 
238
- vector<EnumType> newCollection;
234
+ std::vector<EnumType> newCollection;
239
235
  newCollection.push_back(e);
240
- grouped.insert(make_pair(key, newCollection));
236
+ grouped.insert(std::make_pair(key, newCollection));
241
237
  } else {
242
- vector<EnumType>& collection = grouped.at(key);
238
+ std::vector<EnumType>& collection = grouped.at(key);
243
239
  collection.push_back(e);
244
240
  }
245
241
  }
246
242
 
247
243
  for (unsigned int index = 0; index < order.size(); index++) {
248
244
  KeyType& key = order.at(index);
249
- vector<EnumType>& values = grouped.at(key);
245
+ std::vector<EnumType>& values = grouped.at(key);
250
246
 
251
- pair<KeyType, vector<EnumType> > grouping = make_pair(key, values);
247
+ std::pair<KeyType, std::vector<EnumType> > grouping = std::make_pair(key, values);
252
248
 
253
249
  arr.push_back(grouping);
254
250
  }
@@ -1,16 +1,11 @@
1
- #ifdef _WIN32
2
- #include <io.h>
3
- #else
4
- #include <unistd.h>
5
- #endif
6
-
7
1
  #include <cstdlib>
8
2
  #include <cstring>
9
3
  #include "util.hpp"
10
- #include "sass_values.h"
4
+ #include "eval.hpp"
5
+ #include "values.hpp"
6
+ #include "sass/values.h"
11
7
 
12
8
  extern "C" {
13
- using namespace std;
14
9
  using namespace Sass;
15
10
 
16
11
  struct Sass_Unknown {
@@ -80,7 +75,7 @@ extern "C" {
80
75
  struct Sass_Map map;
81
76
  struct Sass_Null null;
82
77
  struct Sass_Error error;
83
- struct Sass_Warning warning;
78
+ struct Sass_Warning warning;
84
79
  };
85
80
 
86
81
  struct Sass_MapPair {
@@ -156,7 +151,7 @@ extern "C" {
156
151
 
157
152
  union Sass_Value* ADDCALL sass_make_boolean(bool val)
158
153
  {
159
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
154
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
160
155
  if (v == 0) return 0;
161
156
  v->boolean.tag = SASS_BOOLEAN;
162
157
  v->boolean.value = val;
@@ -165,7 +160,7 @@ extern "C" {
165
160
 
166
161
  union Sass_Value* ADDCALL sass_make_number(double val, const char* unit)
167
162
  {
168
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
163
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
169
164
  if (v == 0) return 0;
170
165
  v->number.tag = SASS_NUMBER;
171
166
  v->number.value = val;
@@ -176,7 +171,7 @@ extern "C" {
176
171
 
177
172
  union Sass_Value* ADDCALL sass_make_color(double r, double g, double b, double a)
178
173
  {
179
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
174
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
180
175
  if (v == 0) return 0;
181
176
  v->color.tag = SASS_COLOR;
182
177
  v->color.r = r;
@@ -188,7 +183,7 @@ extern "C" {
188
183
 
189
184
  union Sass_Value* ADDCALL sass_make_string(const char* val)
190
185
  {
191
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
186
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
192
187
  if (v == 0) return 0;
193
188
  v->string.quoted = false;
194
189
  v->string.tag = SASS_STRING;
@@ -199,7 +194,7 @@ extern "C" {
199
194
 
200
195
  union Sass_Value* ADDCALL sass_make_qstring(const char* val)
201
196
  {
202
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
197
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
203
198
  if (v == 0) return 0;
204
199
  v->string.quoted = true;
205
200
  v->string.tag = SASS_STRING;
@@ -210,7 +205,7 @@ extern "C" {
210
205
 
211
206
  union Sass_Value* ADDCALL sass_make_list(size_t len, enum Sass_Separator sep)
212
207
  {
213
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
208
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
214
209
  if (v == 0) return 0;
215
210
  v->list.tag = SASS_LIST;
216
211
  v->list.length = len;
@@ -222,7 +217,7 @@ extern "C" {
222
217
 
223
218
  union Sass_Value* ADDCALL sass_make_map(size_t len)
224
219
  {
225
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
220
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
226
221
  if (v == 0) return 0;
227
222
  v->map.tag = SASS_MAP;
228
223
  v->map.length = len;
@@ -233,7 +228,7 @@ extern "C" {
233
228
 
234
229
  union Sass_Value* ADDCALL sass_make_null(void)
235
230
  {
236
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
231
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
237
232
  if (v == 0) return 0;
238
233
  v->null.tag = SASS_NULL;
239
234
  return v;
@@ -241,7 +236,7 @@ extern "C" {
241
236
 
242
237
  union Sass_Value* ADDCALL sass_make_error(const char* msg)
243
238
  {
244
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
239
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
245
240
  if (v == 0) return 0;
246
241
  v->error.tag = SASS_ERROR;
247
242
  v->error.message = msg ? sass_strdup(msg) : 0;
@@ -251,7 +246,7 @@ extern "C" {
251
246
 
252
247
  union Sass_Value* ADDCALL sass_make_warning(const char* msg)
253
248
  {
254
- Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
249
+ union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
255
250
  if (v == 0) return 0;
256
251
  v->warning.tag = SASS_WARNING;
257
252
  v->warning.message = msg ? sass_strdup(msg) : 0;
@@ -322,7 +317,7 @@ extern "C" {
322
317
  return sass_make_color(val->color.r, val->color.g, val->color.b, val->color.a);
323
318
  } break;
324
319
  case SASS_STRING: {
325
- return sass_make_string(val->string.value);
320
+ return sass_string_is_quoted(val) ? sass_make_qstring(val->string.value) : sass_make_string(val->string.value);
326
321
  } break;
327
322
  case SASS_LIST: {
328
323
  union Sass_Value* list = sass_make_list(val->list.length, val->list.separator);
@@ -351,4 +346,80 @@ extern "C" {
351
346
 
352
347
  }
353
348
 
349
+ union Sass_Value* ADDCALL sass_value_stringify (const union Sass_Value* v, bool compressed, int precision)
350
+ {
351
+ Memory_Manager mem;
352
+ Value* val = sass_value_to_ast_node(mem, v);
353
+ std::string str(val->to_string(compressed, precision));
354
+ return sass_make_qstring(str.c_str());
355
+ }
356
+
357
+ union Sass_Value* ADDCALL sass_value_op (enum Sass_OP op, const union Sass_Value* a, const union Sass_Value* b)
358
+ {
359
+
360
+ Sass::Value* rv = 0;
361
+ Memory_Manager mem;
362
+
363
+ try {
364
+
365
+ Value* lhs = sass_value_to_ast_node(mem, a);
366
+ Value* rhs = sass_value_to_ast_node(mem, b);
367
+
368
+ // see if it's a relational expression
369
+ switch(op) {
370
+ case Sass_OP::EQ: return sass_make_boolean(Eval::eq(lhs, rhs));
371
+ case Sass_OP::NEQ: return sass_make_boolean(!Eval::eq(lhs, rhs));
372
+ case Sass_OP::GT: return sass_make_boolean(!Eval::lt(lhs, rhs) && !Eval::eq(lhs, rhs));
373
+ case Sass_OP::GTE: return sass_make_boolean(!Eval::lt(lhs, rhs));
374
+ case Sass_OP::LT: return sass_make_boolean(Eval::lt(lhs, rhs));
375
+ case Sass_OP::LTE: return sass_make_boolean(Eval::lt(lhs, rhs) || Eval::eq(lhs, rhs));
376
+ default: break;
377
+ }
378
+
379
+ if (sass_value_is_number(a) && sass_value_is_number(b)) {
380
+ const Number* l_n = dynamic_cast<const Number*>(lhs);
381
+ const Number* r_n = dynamic_cast<const Number*>(rhs);
382
+ rv = Eval::op_numbers(mem, op, *l_n, *r_n);
383
+ }
384
+ else if (sass_value_is_number(a) && sass_value_is_color(a)) {
385
+ const Number* l_n = dynamic_cast<const Number*>(lhs);
386
+ const Color* r_c = dynamic_cast<const Color*>(rhs);
387
+ rv = Eval::op_number_color(mem, op, *l_n, *r_c);
388
+ }
389
+ else if (sass_value_is_color(a) && sass_value_is_number(b)) {
390
+ const Color* l_c = dynamic_cast<const Color*>(lhs);
391
+ const Number* r_n = dynamic_cast<const Number*>(rhs);
392
+ rv = Eval::op_color_number(mem, op, *l_c, *r_n);
393
+ }
394
+ else if (sass_value_is_color(a) && sass_value_is_color(b)) {
395
+ const Color* l_c = dynamic_cast<const Color*>(lhs);
396
+ const Color* r_c = dynamic_cast<const Color*>(rhs);
397
+ rv = Eval::op_colors(mem, op, *l_c, *r_c);
398
+ }
399
+ else /* convert other stuff to string and apply operation */ {
400
+ Value* l_v = dynamic_cast<Value*>(lhs);
401
+ Value* r_v = dynamic_cast<Value*>(rhs);
402
+ rv = Eval::op_strings(mem, op, *l_v, *r_v);
403
+ }
404
+
405
+ // ToDo: maybe we should should return null value?
406
+ if (!rv) return sass_make_error("invalid return value");
407
+
408
+ // convert result back to ast node
409
+ return ast_node_to_sass_value(rv);
410
+
411
+ }
412
+
413
+ // simply pass the error message back to the caller for now
414
+ catch (Error_Invalid& e) { return sass_make_error(e.message.c_str()); }
415
+ catch (std::bad_alloc& ba) { return sass_make_error("memory exhausted"); }
416
+ catch (std::exception& e) { return sass_make_error(e.what()); }
417
+ catch (std::string& e) { return sass_make_error(e.c_str()); }
418
+ catch (const char* e) { return sass_make_error(e); }
419
+ catch (...) { return sass_make_error("unknown"); }
420
+
421
+ return 0;
422
+
423
+ }
424
+
354
425
  }