sassc 2.0.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +9 -3
  5. data/CHANGELOG.md +36 -0
  6. data/CODE_OF_CONDUCT.md +1 -1
  7. data/README.md +1 -1
  8. data/Rakefile +43 -7
  9. data/ext/depend +4 -0
  10. data/ext/extconf.rb +92 -0
  11. data/ext/libsass/VERSION +1 -0
  12. data/ext/libsass/include/sass/base.h +9 -1
  13. data/ext/libsass/include/sass/context.h +5 -1
  14. data/ext/libsass/src/MurmurHash2.hpp +91 -0
  15. data/ext/libsass/src/ast.cpp +755 -2028
  16. data/ext/libsass/src/ast.hpp +492 -2477
  17. data/ext/libsass/src/{to_c.cpp → ast2c.cpp} +22 -16
  18. data/ext/libsass/src/ast2c.hpp +39 -0
  19. data/ext/libsass/src/ast_def_macros.hpp +70 -10
  20. data/ext/libsass/src/ast_fwd_decl.cpp +5 -3
  21. data/ext/libsass/src/ast_fwd_decl.hpp +107 -296
  22. data/ext/libsass/src/ast_helpers.hpp +292 -0
  23. data/ext/libsass/src/ast_sel_cmp.cpp +396 -0
  24. data/ext/libsass/src/ast_sel_super.cpp +539 -0
  25. data/ext/libsass/src/ast_sel_unify.cpp +275 -0
  26. data/ext/libsass/src/ast_sel_weave.cpp +616 -0
  27. data/ext/libsass/src/ast_selectors.cpp +1043 -0
  28. data/ext/libsass/src/ast_selectors.hpp +522 -0
  29. data/ext/libsass/src/ast_supports.cpp +114 -0
  30. data/ext/libsass/src/ast_supports.hpp +121 -0
  31. data/ext/libsass/src/ast_values.cpp +1154 -0
  32. data/ext/libsass/src/ast_values.hpp +498 -0
  33. data/ext/libsass/src/backtrace.cpp +11 -7
  34. data/ext/libsass/src/backtrace.hpp +5 -5
  35. data/ext/libsass/src/base64vlq.cpp +5 -2
  36. data/ext/libsass/src/base64vlq.hpp +1 -1
  37. data/ext/libsass/src/bind.cpp +35 -34
  38. data/ext/libsass/src/bind.hpp +3 -1
  39. data/ext/libsass/src/c2ast.cpp +64 -0
  40. data/ext/libsass/src/c2ast.hpp +14 -0
  41. data/ext/libsass/src/cencode.c +4 -6
  42. data/ext/libsass/src/check_nesting.cpp +83 -88
  43. data/ext/libsass/src/check_nesting.hpp +39 -34
  44. data/ext/libsass/src/color_maps.cpp +168 -164
  45. data/ext/libsass/src/color_maps.hpp +152 -160
  46. data/ext/libsass/src/constants.cpp +20 -0
  47. data/ext/libsass/src/constants.hpp +19 -0
  48. data/ext/libsass/src/context.cpp +104 -121
  49. data/ext/libsass/src/context.hpp +43 -55
  50. data/ext/libsass/src/cssize.cpp +103 -188
  51. data/ext/libsass/src/cssize.hpp +45 -51
  52. data/ext/libsass/src/dart_helpers.hpp +199 -0
  53. data/ext/libsass/src/debugger.hpp +524 -361
  54. data/ext/libsass/src/emitter.cpp +26 -26
  55. data/ext/libsass/src/emitter.hpp +20 -18
  56. data/ext/libsass/src/environment.cpp +41 -27
  57. data/ext/libsass/src/environment.hpp +33 -22
  58. data/ext/libsass/src/error_handling.cpp +92 -94
  59. data/ext/libsass/src/error_handling.hpp +73 -50
  60. data/ext/libsass/src/eval.cpp +380 -515
  61. data/ext/libsass/src/eval.hpp +64 -57
  62. data/ext/libsass/src/eval_selectors.cpp +75 -0
  63. data/ext/libsass/src/expand.cpp +322 -263
  64. data/ext/libsass/src/expand.hpp +55 -39
  65. data/ext/libsass/src/extender.cpp +1188 -0
  66. data/ext/libsass/src/extender.hpp +399 -0
  67. data/ext/libsass/src/extension.cpp +43 -0
  68. data/ext/libsass/src/extension.hpp +89 -0
  69. data/ext/libsass/src/file.cpp +134 -88
  70. data/ext/libsass/src/file.hpp +28 -37
  71. data/ext/libsass/src/fn_colors.cpp +596 -0
  72. data/ext/libsass/src/fn_colors.hpp +85 -0
  73. data/ext/libsass/src/fn_lists.cpp +285 -0
  74. data/ext/libsass/src/fn_lists.hpp +34 -0
  75. data/ext/libsass/src/fn_maps.cpp +94 -0
  76. data/ext/libsass/src/fn_maps.hpp +30 -0
  77. data/ext/libsass/src/fn_miscs.cpp +244 -0
  78. data/ext/libsass/src/fn_miscs.hpp +40 -0
  79. data/ext/libsass/src/fn_numbers.cpp +227 -0
  80. data/ext/libsass/src/fn_numbers.hpp +45 -0
  81. data/ext/libsass/src/fn_selectors.cpp +205 -0
  82. data/ext/libsass/src/fn_selectors.hpp +35 -0
  83. data/ext/libsass/src/fn_strings.cpp +268 -0
  84. data/ext/libsass/src/fn_strings.hpp +34 -0
  85. data/ext/libsass/src/fn_utils.cpp +158 -0
  86. data/ext/libsass/src/fn_utils.hpp +62 -0
  87. data/ext/libsass/src/inspect.cpp +253 -266
  88. data/ext/libsass/src/inspect.hpp +72 -74
  89. data/ext/libsass/src/json.cpp +2 -2
  90. data/ext/libsass/src/lexer.cpp +25 -84
  91. data/ext/libsass/src/lexer.hpp +5 -16
  92. data/ext/libsass/src/listize.cpp +27 -43
  93. data/ext/libsass/src/listize.hpp +14 -11
  94. data/ext/libsass/src/mapping.hpp +1 -0
  95. data/ext/libsass/src/memory.hpp +12 -0
  96. data/ext/libsass/src/memory/allocator.cpp +48 -0
  97. data/ext/libsass/src/memory/allocator.hpp +138 -0
  98. data/ext/libsass/src/memory/config.hpp +20 -0
  99. data/ext/libsass/src/memory/memory_pool.hpp +186 -0
  100. data/ext/libsass/src/memory/shared_ptr.cpp +33 -0
  101. data/ext/libsass/src/memory/shared_ptr.hpp +332 -0
  102. data/ext/libsass/src/operation.hpp +193 -143
  103. data/ext/libsass/src/operators.cpp +56 -29
  104. data/ext/libsass/src/operators.hpp +11 -11
  105. data/ext/libsass/src/ordered_map.hpp +112 -0
  106. data/ext/libsass/src/output.cpp +59 -75
  107. data/ext/libsass/src/output.hpp +15 -22
  108. data/ext/libsass/src/parser.cpp +662 -818
  109. data/ext/libsass/src/parser.hpp +96 -100
  110. data/ext/libsass/src/parser_selectors.cpp +189 -0
  111. data/ext/libsass/src/permutate.hpp +164 -0
  112. data/ext/libsass/src/plugins.cpp +12 -8
  113. data/ext/libsass/src/plugins.hpp +8 -8
  114. data/ext/libsass/src/position.cpp +10 -26
  115. data/ext/libsass/src/position.hpp +44 -21
  116. data/ext/libsass/src/prelexer.cpp +14 -8
  117. data/ext/libsass/src/prelexer.hpp +9 -9
  118. data/ext/libsass/src/remove_placeholders.cpp +59 -57
  119. data/ext/libsass/src/remove_placeholders.hpp +20 -18
  120. data/ext/libsass/src/sass.cpp +25 -18
  121. data/ext/libsass/src/sass.hpp +22 -14
  122. data/ext/libsass/src/sass2scss.cpp +49 -18
  123. data/ext/libsass/src/sass_context.cpp +104 -132
  124. data/ext/libsass/src/sass_context.hpp +2 -2
  125. data/ext/libsass/src/sass_functions.cpp +7 -4
  126. data/ext/libsass/src/sass_functions.hpp +1 -1
  127. data/ext/libsass/src/sass_values.cpp +26 -21
  128. data/ext/libsass/src/settings.hpp +19 -0
  129. data/ext/libsass/src/source.cpp +69 -0
  130. data/ext/libsass/src/source.hpp +95 -0
  131. data/ext/libsass/src/source_data.hpp +32 -0
  132. data/ext/libsass/src/source_map.cpp +27 -20
  133. data/ext/libsass/src/source_map.hpp +14 -11
  134. data/ext/libsass/src/stylesheet.cpp +22 -0
  135. data/ext/libsass/src/stylesheet.hpp +57 -0
  136. data/ext/libsass/src/to_value.cpp +24 -22
  137. data/ext/libsass/src/to_value.hpp +18 -22
  138. data/ext/libsass/src/units.cpp +28 -22
  139. data/ext/libsass/src/units.hpp +9 -8
  140. data/ext/libsass/src/utf8/checked.h +12 -10
  141. data/ext/libsass/src/utf8/core.h +3 -0
  142. data/ext/libsass/src/utf8_string.cpp +12 -10
  143. data/ext/libsass/src/utf8_string.hpp +7 -6
  144. data/ext/libsass/src/util.cpp +97 -107
  145. data/ext/libsass/src/util.hpp +74 -30
  146. data/ext/libsass/src/util_string.cpp +125 -0
  147. data/ext/libsass/src/util_string.hpp +73 -0
  148. data/ext/libsass/src/values.cpp +33 -24
  149. data/ext/libsass/src/values.hpp +2 -2
  150. data/lib/sassc.rb +24 -0
  151. data/lib/sassc/engine.rb +7 -5
  152. data/lib/sassc/functions_handler.rb +11 -13
  153. data/lib/sassc/native.rb +10 -9
  154. data/lib/sassc/native/native_functions_api.rb +0 -5
  155. data/lib/sassc/script.rb +4 -6
  156. data/lib/sassc/version.rb +1 -1
  157. data/sassc.gemspec +32 -12
  158. data/test/engine_test.rb +32 -2
  159. data/test/functions_test.rb +38 -1
  160. data/test/native_test.rb +4 -4
  161. metadata +95 -109
  162. data/ext/Rakefile +0 -3
  163. data/ext/libsass/.editorconfig +0 -15
  164. data/ext/libsass/.gitattributes +0 -2
  165. data/ext/libsass/.github/CONTRIBUTING.md +0 -65
  166. data/ext/libsass/.github/ISSUE_TEMPLATE.md +0 -54
  167. data/ext/libsass/.gitignore +0 -85
  168. data/ext/libsass/.travis.yml +0 -64
  169. data/ext/libsass/COPYING +0 -25
  170. data/ext/libsass/GNUmakefile.am +0 -88
  171. data/ext/libsass/INSTALL +0 -1
  172. data/ext/libsass/LICENSE +0 -25
  173. data/ext/libsass/Makefile +0 -351
  174. data/ext/libsass/Makefile.conf +0 -55
  175. data/ext/libsass/Readme.md +0 -104
  176. data/ext/libsass/SECURITY.md +0 -10
  177. data/ext/libsass/appveyor.yml +0 -91
  178. data/ext/libsass/configure.ac +0 -138
  179. data/ext/libsass/contrib/libsass.spec +0 -66
  180. data/ext/libsass/docs/README.md +0 -20
  181. data/ext/libsass/docs/api-context-example.md +0 -45
  182. data/ext/libsass/docs/api-context-internal.md +0 -163
  183. data/ext/libsass/docs/api-context.md +0 -295
  184. data/ext/libsass/docs/api-doc.md +0 -215
  185. data/ext/libsass/docs/api-function-example.md +0 -67
  186. data/ext/libsass/docs/api-function-internal.md +0 -8
  187. data/ext/libsass/docs/api-function.md +0 -74
  188. data/ext/libsass/docs/api-importer-example.md +0 -112
  189. data/ext/libsass/docs/api-importer-internal.md +0 -20
  190. data/ext/libsass/docs/api-importer.md +0 -86
  191. data/ext/libsass/docs/api-value-example.md +0 -55
  192. data/ext/libsass/docs/api-value-internal.md +0 -76
  193. data/ext/libsass/docs/api-value.md +0 -154
  194. data/ext/libsass/docs/build-on-darwin.md +0 -27
  195. data/ext/libsass/docs/build-on-gentoo.md +0 -55
  196. data/ext/libsass/docs/build-on-windows.md +0 -139
  197. data/ext/libsass/docs/build-shared-library.md +0 -35
  198. data/ext/libsass/docs/build-with-autotools.md +0 -78
  199. data/ext/libsass/docs/build-with-makefiles.md +0 -68
  200. data/ext/libsass/docs/build-with-mingw.md +0 -107
  201. data/ext/libsass/docs/build-with-visual-studio.md +0 -90
  202. data/ext/libsass/docs/build.md +0 -97
  203. data/ext/libsass/docs/compatibility-plan.md +0 -48
  204. data/ext/libsass/docs/contributing.md +0 -17
  205. data/ext/libsass/docs/custom-functions-internal.md +0 -122
  206. data/ext/libsass/docs/dev-ast-memory.md +0 -223
  207. data/ext/libsass/docs/implementations.md +0 -56
  208. data/ext/libsass/docs/plugins.md +0 -47
  209. data/ext/libsass/docs/setup-environment.md +0 -68
  210. data/ext/libsass/docs/source-map-internals.md +0 -51
  211. data/ext/libsass/docs/trace.md +0 -26
  212. data/ext/libsass/docs/triage.md +0 -17
  213. data/ext/libsass/docs/unicode.md +0 -39
  214. data/ext/libsass/extconf.rb +0 -6
  215. data/ext/libsass/include/sass/version.h.in +0 -12
  216. data/ext/libsass/m4/.gitkeep +0 -0
  217. data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +0 -167
  218. data/ext/libsass/res/resource.rc +0 -35
  219. data/ext/libsass/script/bootstrap +0 -13
  220. data/ext/libsass/script/branding +0 -10
  221. data/ext/libsass/script/ci-build-libsass +0 -134
  222. data/ext/libsass/script/ci-build-plugin +0 -62
  223. data/ext/libsass/script/ci-install-compiler +0 -6
  224. data/ext/libsass/script/ci-install-deps +0 -20
  225. data/ext/libsass/script/ci-report-coverage +0 -42
  226. data/ext/libsass/script/spec +0 -5
  227. data/ext/libsass/script/tap-driver +0 -652
  228. data/ext/libsass/script/tap-runner +0 -1
  229. data/ext/libsass/script/test-leaks.pl +0 -103
  230. data/ext/libsass/src/GNUmakefile.am +0 -54
  231. data/ext/libsass/src/extend.cpp +0 -2130
  232. data/ext/libsass/src/extend.hpp +0 -86
  233. data/ext/libsass/src/functions.cpp +0 -2234
  234. data/ext/libsass/src/functions.hpp +0 -198
  235. data/ext/libsass/src/memory/SharedPtr.cpp +0 -114
  236. data/ext/libsass/src/memory/SharedPtr.hpp +0 -206
  237. data/ext/libsass/src/node.cpp +0 -319
  238. data/ext/libsass/src/node.hpp +0 -118
  239. data/ext/libsass/src/paths.hpp +0 -71
  240. data/ext/libsass/src/sass_util.cpp +0 -149
  241. data/ext/libsass/src/sass_util.hpp +0 -256
  242. data/ext/libsass/src/subset_map.cpp +0 -55
  243. data/ext/libsass/src/subset_map.hpp +0 -76
  244. data/ext/libsass/src/support/libsass.pc.in +0 -11
  245. data/ext/libsass/src/to_c.hpp +0 -39
  246. data/ext/libsass/test/test_node.cpp +0 -94
  247. data/ext/libsass/test/test_paths.cpp +0 -28
  248. data/ext/libsass/test/test_selector_difference.cpp +0 -25
  249. data/ext/libsass/test/test_specificity.cpp +0 -25
  250. data/ext/libsass/test/test_subset_map.cpp +0 -472
  251. data/ext/libsass/test/test_superselector.cpp +0 -69
  252. data/ext/libsass/test/test_unification.cpp +0 -31
  253. data/ext/libsass/version.sh +0 -10
  254. data/ext/libsass/win/libsass.sln +0 -39
  255. data/ext/libsass/win/libsass.sln.DotSettings +0 -9
  256. data/ext/libsass/win/libsass.targets +0 -118
  257. data/ext/libsass/win/libsass.vcxproj +0 -188
  258. data/ext/libsass/win/libsass.vcxproj.filters +0 -357
  259. data/lib/sassc/native/lib_c.rb +0 -21
  260. data/lib/tasks/libsass.rb +0 -33
@@ -1,149 +0,0 @@
1
- #include "sass.hpp"
2
- #include "node.hpp"
3
-
4
- namespace Sass {
5
-
6
-
7
- /*
8
- # This is the equivalent of ruby's Sass::Util.paths.
9
- #
10
- # Return an array of all possible paths through the given arrays.
11
- #
12
- # @param arrs [NodeCollection<NodeCollection<Node>>]
13
- # @return [NodeCollection<NodeCollection<Node>>]
14
- #
15
- # @example
16
- # paths([[1, 2], [3, 4], [5]]) #=>
17
- # # [[1, 3, 5],
18
- # # [2, 3, 5],
19
- # # [1, 4, 5],
20
- # # [2, 4, 5]]
21
-
22
- The following is the modified version of the ruby code that was more portable to C++. You
23
- should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
24
-
25
- def paths(arrs)
26
- // I changed the inject and maps to an iterative approach to make it easier to implement in C++
27
- loopStart = [[]]
28
-
29
- for arr in arrs do
30
- permutations = []
31
- for e in arr do
32
- for path in loopStart do
33
- permutations.push(path + [e])
34
- end
35
- end
36
- loopStart = permutations
37
- end
38
- end
39
- */
40
- Node paths(const Node& arrs) {
41
-
42
- Node loopStart = Node::createCollection();
43
- loopStart.collection()->push_back(Node::createCollection());
44
-
45
- for (NodeDeque::iterator arrsIter = arrs.collection()->begin(), arrsEndIter = arrs.collection()->end();
46
- arrsIter != arrsEndIter; ++arrsIter) {
47
-
48
- Node& arr = *arrsIter;
49
-
50
- Node permutations = Node::createCollection();
51
-
52
- for (NodeDeque::iterator arrIter = arr.collection()->begin(), arrIterEnd = arr.collection()->end();
53
- arrIter != arrIterEnd; ++arrIter) {
54
-
55
- Node& e = *arrIter;
56
-
57
- for (NodeDeque::iterator loopStartIter = loopStart.collection()->begin(), loopStartIterEnd = loopStart.collection()->end();
58
- loopStartIter != loopStartIterEnd; ++loopStartIter) {
59
-
60
- Node& path = *loopStartIter;
61
-
62
- Node newPermutation = Node::createCollection();
63
- newPermutation.got_line_feed = arr.got_line_feed;
64
- newPermutation.plus(path);
65
- newPermutation.collection()->push_back(e);
66
-
67
- permutations.collection()->push_back(newPermutation);
68
- }
69
- }
70
-
71
- loopStart = permutations;
72
- }
73
-
74
- return loopStart;
75
- }
76
-
77
-
78
- /*
79
- This is the equivalent of ruby sass' Sass::Util.flatten and [].flatten.
80
- Sass::Util.flatten requires the number of levels to flatten, while
81
- [].flatten doesn't and will flatten the entire array. This function
82
- supports both.
83
-
84
- # Flattens the first `n` nested arrays. If n == -1, all arrays will be flattened
85
- #
86
- # @param arr [NodeCollection] The array to flatten
87
- # @param n [int] The number of levels to flatten
88
- # @return [NodeCollection] The flattened array
89
-
90
- The following is the modified version of the ruby code that was more portable to C++. You
91
- should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
92
-
93
- def flatten(arr, n = -1)
94
- if n != -1 and n == 0 then
95
- return arr
96
- end
97
-
98
- flattened = []
99
-
100
- for e in arr do
101
- if e.is_a?(Array) then
102
- flattened.concat(flatten(e, n - 1))
103
- else
104
- flattened << e
105
- end
106
- end
107
-
108
- return flattened
109
- end
110
- */
111
- Node flatten(Node& arr, int n) {
112
- if (n != -1 && n == 0) {
113
- return arr;
114
- }
115
-
116
- Node flattened = Node::createCollection();
117
- if (arr.got_line_feed) flattened.got_line_feed = true;
118
-
119
- for (NodeDeque::iterator iter = arr.collection()->begin(), iterEnd = arr.collection()->end();
120
- iter != iterEnd; iter++) {
121
- Node& e = *iter;
122
-
123
- // e has the lf set
124
- if (e.isCollection()) {
125
-
126
- // e.collection().got_line_feed = e.got_line_feed;
127
- Node recurseFlattened = flatten(e, n - 1);
128
-
129
- if(e.got_line_feed) {
130
- flattened.got_line_feed = e.got_line_feed;
131
- recurseFlattened.got_line_feed = e.got_line_feed;
132
- }
133
-
134
- for(auto i : (*recurseFlattened.collection())) {
135
- if (recurseFlattened.got_line_feed) {
136
-
137
- i.got_line_feed = true;
138
- }
139
- flattened.collection()->push_back(i);
140
- }
141
-
142
- } else {
143
- flattened.collection()->push_back(e);
144
- }
145
- }
146
-
147
- return flattened;
148
- }
149
- }
@@ -1,256 +0,0 @@
1
- #ifndef SASS_SASS_UTIL_H
2
- #define SASS_SASS_UTIL_H
3
-
4
- #include "ast.hpp"
5
- #include "node.hpp"
6
- #include "debug.hpp"
7
-
8
- namespace Sass {
9
-
10
-
11
-
12
-
13
- /*
14
- This is for ports of functions in the Sass:Util module.
15
- */
16
-
17
-
18
- /*
19
- # Return a Node collection of all possible paths through the given Node collection of Node collections.
20
- #
21
- # @param arrs [NodeCollection<NodeCollection<Node>>]
22
- # @return [NodeCollection<NodeCollection<Node>>]
23
- #
24
- # @example
25
- # paths([[1, 2], [3, 4], [5]]) #=>
26
- # # [[1, 3, 5],
27
- # # [2, 3, 5],
28
- # # [1, 4, 5],
29
- # # [2, 4, 5]]
30
- */
31
- Node paths(const Node& arrs);
32
-
33
-
34
- /*
35
- This class is a default implementation of a Node comparator that can be passed to the lcs function below.
36
- It uses operator== for equality comparision. It then returns one if the Nodes are equal.
37
- */
38
- class DefaultLcsComparator {
39
- public:
40
- bool operator()(const Node& one, const Node& two, Node& out) const {
41
- // TODO: Is this the correct C++ interpretation?
42
- // block ||= proc {|a, b| a == b && a}
43
- if (one == two) {
44
- out = one;
45
- return true;
46
- }
47
-
48
- return false;
49
- }
50
- };
51
-
52
-
53
- typedef std::vector<std::vector<int> > LCSTable;
54
-
55
-
56
- /*
57
- This is the equivalent of ruby's Sass::Util.lcs_backtrace.
58
-
59
- # Computes a single longest common subsequence for arrays x and y.
60
- # Algorithm from http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Reading_out_an_LCS
61
- */
62
- template<typename ComparatorType>
63
- Node lcs_backtrace(const LCSTable& c, const Node& x, const Node& y, int i, int j, const ComparatorType& comparator) {
64
- DEBUG_PRINTLN(LCS, "LCSBACK: X=" << x << " Y=" << y << " I=" << i << " J=" << j)
65
-
66
- if (i == 0 || j == 0) {
67
- DEBUG_PRINTLN(LCS, "RETURNING EMPTY")
68
- return Node::createCollection();
69
- }
70
-
71
- NodeDeque& xChildren = *(x.collection());
72
- NodeDeque& yChildren = *(y.collection());
73
-
74
- Node compareOut = Node::createNil();
75
- if (comparator(xChildren[i], yChildren[j], compareOut)) {
76
- DEBUG_PRINTLN(LCS, "RETURNING AFTER ELEM COMPARE")
77
- Node result = lcs_backtrace(c, x, y, i - 1, j - 1, comparator);
78
- result.collection()->push_back(compareOut);
79
- return result;
80
- }
81
-
82
- if (c[i][j - 1] > c[i - 1][j]) {
83
- DEBUG_PRINTLN(LCS, "RETURNING AFTER TABLE COMPARE")
84
- return lcs_backtrace(c, x, y, i, j - 1, comparator);
85
- }
86
-
87
- DEBUG_PRINTLN(LCS, "FINAL RETURN")
88
- return lcs_backtrace(c, x, y, i - 1, j, comparator);
89
- }
90
-
91
-
92
- /*
93
- This is the equivalent of ruby's Sass::Util.lcs_table.
94
-
95
- # Calculates the memoization table for the Least Common Subsequence algorithm.
96
- # Algorithm from http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Computing_the_length_of_the_LCS
97
- */
98
- template<typename ComparatorType>
99
- void lcs_table(const Node& x, const Node& y, const ComparatorType& comparator, LCSTable& out) {
100
- DEBUG_PRINTLN(LCS, "LCSTABLE: X=" << x << " Y=" << y)
101
-
102
- NodeDeque& xChildren = *(x.collection());
103
- NodeDeque& yChildren = *(y.collection());
104
-
105
- LCSTable c(xChildren.size(), std::vector<int>(yChildren.size()));
106
-
107
- // These shouldn't be necessary since the vector will be initialized to 0 already.
108
- // x.size.times {|i| c[i][0] = 0}
109
- // y.size.times {|j| c[0][j] = 0}
110
-
111
- for (size_t i = 1; i < xChildren.size(); i++) {
112
- for (size_t j = 1; j < yChildren.size(); j++) {
113
- Node compareOut = Node::createNil();
114
-
115
- if (comparator(xChildren[i], yChildren[j], compareOut)) {
116
- c[i][j] = c[i - 1][j - 1] + 1;
117
- } else {
118
- c[i][j] = std::max(c[i][j - 1], c[i - 1][j]);
119
- }
120
- }
121
- }
122
-
123
- out = c;
124
- }
125
-
126
-
127
- /*
128
- This is the equivalent of ruby's Sass::Util.lcs.
129
-
130
- # Computes a single longest common subsequence for `x` and `y`.
131
- # If there are more than one longest common subsequences,
132
- # the one returned is that which starts first in `x`.
133
-
134
- # @param x [NodeCollection]
135
- # @param y [NodeCollection]
136
- # @comparator An equality check between elements of `x` and `y`.
137
- # @return [NodeCollection] The LCS
138
-
139
- http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
140
- */
141
- template<typename ComparatorType>
142
- Node lcs(Node& x, Node& y, const ComparatorType& comparator) {
143
- DEBUG_PRINTLN(LCS, "LCS: X=" << x << " Y=" << y)
144
-
145
- Node newX = Node::createCollection();
146
- newX.collection()->push_back(Node::createNil());
147
- newX.plus(x);
148
-
149
- Node newY = Node::createCollection();
150
- newY.collection()->push_back(Node::createNil());
151
- newY.plus(y);
152
-
153
- LCSTable table;
154
- lcs_table(newX, newY, comparator, table);
155
-
156
- return lcs_backtrace(table, newX, newY, static_cast<int>(newX.collection()->size()) - 1, static_cast<int>(newY.collection()->size()) - 1, comparator);
157
- }
158
-
159
-
160
- /*
161
- This is the equivalent of ruby sass' Sass::Util.flatten and [].flatten.
162
- Sass::Util.flatten requires the number of levels to flatten, while
163
- [].flatten doesn't and will flatten the entire array. This function
164
- supports both.
165
-
166
- # Flattens the first `n` nested arrays. If n == -1, all arrays will be flattened
167
- #
168
- # @param arr [NodeCollection] The array to flatten
169
- # @param n [int] The number of levels to flatten
170
- # @return [NodeCollection] The flattened array
171
- */
172
- Node flatten(Node& arr, int n = -1);
173
-
174
-
175
- /*
176
- This is the equivalent of ruby's Sass::Util.group_by_to_a.
177
-
178
- # Performs the equivalent of `enum.group_by.to_a`, but with a guaranteed
179
- # order. Unlike [#hash_to_a], the resulting order isn't sorted key order;
180
- # instead, it's the same order as `#group_by` has under Ruby 1.9 (key
181
- # appearance order).
182
- #
183
- # @param enum [Enumerable]
184
- # @return [Array<[Object, Array]>] An array of pairs.
185
-
186
- TODO: update @param and @return once I know what those are.
187
-
188
- The following is the modified version of the ruby code that was more portable to C++. You
189
- should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
190
-
191
- def group_by_to_a(enum, &block)
192
- order = {}
193
-
194
- arr = []
195
-
196
- grouped = {}
197
-
198
- for e in enum do
199
- key = block[e]
200
- unless order.include?(key)
201
- order[key] = order.size
202
- end
203
-
204
- if not grouped.has_key?(key) then
205
- grouped[key] = [e]
206
- else
207
- grouped[key].push(e)
208
- end
209
- end
210
-
211
- grouped.each do |key, vals|
212
- arr[order[key]] = [key, vals]
213
- end
214
-
215
- arr
216
- end
217
-
218
- */
219
- template<typename EnumType, typename KeyType, typename KeyFunctorType>
220
- void group_by_to_a(std::vector<EnumType>& enumeration, KeyFunctorType& keyFunc, std::vector<std::pair<KeyType, std::vector<EnumType> > >& arr /*out*/) {
221
-
222
- std::map<unsigned int, KeyType> order;
223
-
224
- std::map<size_t, std::vector<EnumType> > grouped;
225
-
226
- for (typename std::vector<EnumType>::iterator enumIter = enumeration.begin(), enumIterEnd = enumeration.end(); enumIter != enumIterEnd; enumIter++) {
227
- EnumType& e = *enumIter;
228
-
229
- KeyType key = keyFunc(e);
230
-
231
- if (grouped.find(key->hash()) == grouped.end()) {
232
- order.insert(std::make_pair((unsigned int)order.size(), key));
233
-
234
- std::vector<EnumType> newCollection;
235
- newCollection.push_back(e);
236
- grouped.insert(std::make_pair(key->hash(), newCollection));
237
- } else {
238
- std::vector<EnumType>& collection = grouped.at(key->hash());
239
- collection.push_back(e);
240
- }
241
- }
242
-
243
- for (unsigned int index = 0; index < order.size(); index++) {
244
- KeyType& key = order.at(index);
245
- std::vector<EnumType>& values = grouped.at(key->hash());
246
-
247
- std::pair<KeyType, std::vector<EnumType> > grouping = std::make_pair(key, values);
248
-
249
- arr.push_back(grouping);
250
- }
251
- }
252
-
253
-
254
- }
255
-
256
- #endif
@@ -1,55 +0,0 @@
1
- #include "sass.hpp"
2
- #include "ast.hpp"
3
- #include "subset_map.hpp"
4
-
5
- namespace Sass {
6
-
7
- void Subset_Map::put(const Compound_Selector_Obj& sel, const SubSetMapPair& value)
8
- {
9
- if (sel->empty()) throw std::runtime_error("internal error: subset map keys may not be empty");
10
- size_t index = values_.size();
11
- values_.push_back(value);
12
- for (size_t i = 0, S = sel->length(); i < S; ++i)
13
- {
14
- hash_[(*sel)[i]].push_back(std::make_pair(sel, index));
15
- }
16
- }
17
-
18
- std::vector<SubSetMapPair> Subset_Map::get_kv(const Compound_Selector_Obj& sel)
19
- {
20
- SimpleSelectorDict dict(sel->begin(), sel->end()); // XXX Set
21
- std::vector<size_t> indices;
22
- for (size_t i = 0, S = sel->length(); i < S; ++i) {
23
- if (!hash_.count((*sel)[i])) {
24
- continue;
25
- }
26
- const std::vector<std::pair<Compound_Selector_Obj, size_t> >& subsets = hash_[(*sel)[i]];
27
- for (const std::pair<Compound_Selector_Obj, size_t>& item : subsets) {
28
- bool include = true;
29
- for (const Simple_Selector_Obj& it : item.first->elements()) {
30
- auto found = dict.find(it);
31
- if (found == dict.end()) {
32
- include = false;
33
- break;
34
- }
35
- }
36
- if (include) indices.push_back(item.second);
37
- }
38
- }
39
- sort(indices.begin(), indices.end());
40
- std::vector<size_t>::iterator indices_end = unique(indices.begin(), indices.end());
41
- indices.resize(distance(indices.begin(), indices_end));
42
-
43
- std::vector<SubSetMapPair> results;
44
- for (size_t i = 0, S = indices.size(); i < S; ++i) {
45
- results.push_back(values_[indices[i]]);
46
- }
47
- return results;
48
- }
49
-
50
- std::vector<SubSetMapPair> Subset_Map::get_v(const Compound_Selector_Obj& sel)
51
- {
52
- return get_kv(sel);
53
- }
54
-
55
- }