sassc 2.0.1 → 2.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +1 -1
  4. data/.travis.yml +7 -3
  5. data/CHANGELOG.md +3 -0
  6. data/CODE_OF_CONDUCT.md +1 -1
  7. data/README.md +1 -1
  8. data/Rakefile +23 -8
  9. data/ext/extconf.rb +39 -0
  10. data/ext/libsass/.gitignore +1 -0
  11. data/ext/libsass/GNUmakefile.am +23 -39
  12. data/ext/libsass/Makefile +56 -91
  13. data/ext/libsass/Makefile.conf +16 -2
  14. data/ext/libsass/configure.ac +8 -12
  15. data/ext/libsass/include/sass/base.h +1 -0
  16. data/ext/libsass/include/sass/context.h +1 -1
  17. data/ext/libsass/src/GNUmakefile.am +1 -5
  18. data/ext/libsass/src/ast.cpp +747 -2010
  19. data/ext/libsass/src/ast.hpp +239 -2383
  20. data/ext/libsass/src/{to_c.cpp → ast2c.cpp} +22 -16
  21. data/ext/libsass/src/ast2c.hpp +39 -0
  22. data/ext/libsass/src/ast_def_macros.hpp +62 -10
  23. data/ext/libsass/src/ast_fwd_decl.cpp +1 -0
  24. data/ext/libsass/src/ast_fwd_decl.hpp +43 -165
  25. data/ext/libsass/src/ast_sel_cmp.cpp +909 -0
  26. data/ext/libsass/src/ast_sel_unify.cpp +280 -0
  27. data/ext/libsass/src/ast_selectors.cpp +1475 -0
  28. data/ext/libsass/src/ast_selectors.hpp +568 -0
  29. data/ext/libsass/src/ast_supports.cpp +130 -0
  30. data/ext/libsass/src/ast_supports.hpp +121 -0
  31. data/ext/libsass/src/ast_values.cpp +967 -0
  32. data/ext/libsass/src/ast_values.hpp +489 -0
  33. data/ext/libsass/src/backtrace.cpp +4 -0
  34. data/ext/libsass/src/base64vlq.cpp +3 -0
  35. data/ext/libsass/src/bind.cpp +18 -17
  36. data/ext/libsass/src/bind.hpp +3 -1
  37. data/ext/libsass/src/c2ast.cpp +64 -0
  38. data/ext/libsass/src/c2ast.hpp +14 -0
  39. data/ext/libsass/src/cencode.c +2 -2
  40. data/ext/libsass/src/check_nesting.cpp +52 -56
  41. data/ext/libsass/src/check_nesting.hpp +35 -34
  42. data/ext/libsass/src/color_maps.cpp +156 -153
  43. data/ext/libsass/src/color_maps.hpp +152 -152
  44. data/ext/libsass/src/constants.cpp +15 -0
  45. data/ext/libsass/src/constants.hpp +13 -0
  46. data/ext/libsass/src/context.cpp +24 -14
  47. data/ext/libsass/src/context.hpp +6 -6
  48. data/ext/libsass/src/cssize.cpp +69 -71
  49. data/ext/libsass/src/cssize.hpp +50 -50
  50. data/ext/libsass/src/debugger.hpp +117 -110
  51. data/ext/libsass/src/emitter.cpp +13 -12
  52. data/ext/libsass/src/emitter.hpp +13 -9
  53. data/ext/libsass/src/environment.cpp +15 -1
  54. data/ext/libsass/src/environment.hpp +6 -0
  55. data/ext/libsass/src/error_handling.cpp +36 -59
  56. data/ext/libsass/src/error_handling.hpp +29 -16
  57. data/ext/libsass/src/eval.cpp +302 -323
  58. data/ext/libsass/src/eval.hpp +64 -55
  59. data/ext/libsass/src/expand.cpp +94 -88
  60. data/ext/libsass/src/expand.hpp +33 -37
  61. data/ext/libsass/src/extend.cpp +38 -36
  62. data/ext/libsass/src/extend.hpp +15 -15
  63. data/ext/libsass/src/file.cpp +34 -2
  64. data/ext/libsass/src/fn_colors.cpp +594 -0
  65. data/ext/libsass/src/fn_colors.hpp +85 -0
  66. data/ext/libsass/src/fn_lists.cpp +284 -0
  67. data/ext/libsass/src/fn_lists.hpp +34 -0
  68. data/ext/libsass/src/fn_maps.cpp +94 -0
  69. data/ext/libsass/src/fn_maps.hpp +30 -0
  70. data/ext/libsass/src/fn_miscs.cpp +256 -0
  71. data/ext/libsass/src/fn_miscs.hpp +40 -0
  72. data/ext/libsass/src/fn_numbers.cpp +220 -0
  73. data/ext/libsass/src/fn_numbers.hpp +45 -0
  74. data/ext/libsass/src/fn_selectors.cpp +235 -0
  75. data/ext/libsass/src/fn_selectors.hpp +35 -0
  76. data/ext/libsass/src/fn_strings.cpp +254 -0
  77. data/ext/libsass/src/fn_strings.hpp +34 -0
  78. data/ext/libsass/src/fn_utils.cpp +156 -0
  79. data/ext/libsass/src/fn_utils.hpp +56 -0
  80. data/ext/libsass/src/inspect.cpp +101 -152
  81. data/ext/libsass/src/inspect.hpp +69 -73
  82. data/ext/libsass/src/json.cpp +2 -2
  83. data/ext/libsass/src/lexer.cpp +6 -3
  84. data/ext/libsass/src/listize.cpp +9 -11
  85. data/ext/libsass/src/listize.hpp +11 -7
  86. data/ext/libsass/src/memory/SharedPtr.cpp +2 -83
  87. data/ext/libsass/src/memory/SharedPtr.hpp +127 -143
  88. data/ext/libsass/src/node.cpp +13 -10
  89. data/ext/libsass/src/node.hpp +3 -3
  90. data/ext/libsass/src/operation.hpp +184 -144
  91. data/ext/libsass/src/operators.cpp +43 -17
  92. data/ext/libsass/src/operators.hpp +5 -5
  93. data/ext/libsass/src/output.cpp +21 -18
  94. data/ext/libsass/src/output.hpp +14 -21
  95. data/ext/libsass/src/parser.cpp +215 -183
  96. data/ext/libsass/src/parser.hpp +28 -24
  97. data/ext/libsass/src/plugins.cpp +5 -1
  98. data/ext/libsass/src/position.cpp +3 -0
  99. data/ext/libsass/src/prelexer.cpp +9 -3
  100. data/ext/libsass/src/prelexer.hpp +9 -9
  101. data/ext/libsass/src/remove_placeholders.cpp +14 -11
  102. data/ext/libsass/src/remove_placeholders.hpp +8 -9
  103. data/ext/libsass/src/sass.cpp +9 -3
  104. data/ext/libsass/src/sass.hpp +12 -9
  105. data/ext/libsass/src/sass2scss.cpp +45 -14
  106. data/ext/libsass/src/sass_context.cpp +18 -15
  107. data/ext/libsass/src/sass_functions.cpp +6 -3
  108. data/ext/libsass/src/sass_functions.hpp +1 -1
  109. data/ext/libsass/src/sass_util.cpp +3 -0
  110. data/ext/libsass/src/sass_values.cpp +21 -13
  111. data/ext/libsass/src/source_map.cpp +5 -2
  112. data/ext/libsass/src/source_map.hpp +2 -2
  113. data/ext/libsass/src/subset_map.cpp +4 -1
  114. data/ext/libsass/src/to_value.cpp +23 -21
  115. data/ext/libsass/src/to_value.hpp +18 -22
  116. data/ext/libsass/src/units.cpp +4 -0
  117. data/ext/libsass/src/units.hpp +1 -0
  118. data/ext/libsass/src/utf8/checked.h +12 -10
  119. data/ext/libsass/src/utf8/core.h +3 -0
  120. data/ext/libsass/src/utf8_string.cpp +3 -0
  121. data/ext/libsass/src/util.cpp +67 -75
  122. data/ext/libsass/src/util.hpp +64 -19
  123. data/ext/libsass/src/util_string.cpp +75 -0
  124. data/ext/libsass/src/util_string.hpp +19 -0
  125. data/ext/libsass/src/values.cpp +22 -13
  126. data/ext/libsass/src/values.hpp +2 -2
  127. data/ext/libsass/win/libsass.targets +30 -4
  128. data/ext/libsass/win/libsass.vcxproj.filters +82 -4
  129. data/lib/sassc.rb +24 -0
  130. data/lib/sassc/engine.rb +2 -2
  131. data/lib/sassc/native.rb +8 -1
  132. data/lib/sassc/version.rb +1 -1
  133. data/sassc.gemspec +19 -11
  134. data/test/engine_test.rb +26 -1
  135. data/test/native_test.rb +1 -1
  136. metadata +66 -72
  137. data/ext/Rakefile +0 -3
  138. data/ext/libsass/.github/CONTRIBUTING.md +0 -65
  139. data/ext/libsass/.github/ISSUE_TEMPLATE.md +0 -54
  140. data/ext/libsass/.travis.yml +0 -64
  141. data/ext/libsass/Readme.md +0 -104
  142. data/ext/libsass/SECURITY.md +0 -10
  143. data/ext/libsass/appveyor.yml +0 -91
  144. data/ext/libsass/docs/README.md +0 -20
  145. data/ext/libsass/docs/api-context-example.md +0 -45
  146. data/ext/libsass/docs/api-context-internal.md +0 -163
  147. data/ext/libsass/docs/api-context.md +0 -295
  148. data/ext/libsass/docs/api-doc.md +0 -215
  149. data/ext/libsass/docs/api-function-example.md +0 -67
  150. data/ext/libsass/docs/api-function-internal.md +0 -8
  151. data/ext/libsass/docs/api-function.md +0 -74
  152. data/ext/libsass/docs/api-importer-example.md +0 -112
  153. data/ext/libsass/docs/api-importer-internal.md +0 -20
  154. data/ext/libsass/docs/api-importer.md +0 -86
  155. data/ext/libsass/docs/api-value-example.md +0 -55
  156. data/ext/libsass/docs/api-value-internal.md +0 -76
  157. data/ext/libsass/docs/api-value.md +0 -154
  158. data/ext/libsass/docs/build-on-darwin.md +0 -27
  159. data/ext/libsass/docs/build-on-gentoo.md +0 -55
  160. data/ext/libsass/docs/build-on-windows.md +0 -139
  161. data/ext/libsass/docs/build-shared-library.md +0 -35
  162. data/ext/libsass/docs/build-with-autotools.md +0 -78
  163. data/ext/libsass/docs/build-with-makefiles.md +0 -68
  164. data/ext/libsass/docs/build-with-mingw.md +0 -107
  165. data/ext/libsass/docs/build-with-visual-studio.md +0 -90
  166. data/ext/libsass/docs/build.md +0 -97
  167. data/ext/libsass/docs/compatibility-plan.md +0 -48
  168. data/ext/libsass/docs/contributing.md +0 -17
  169. data/ext/libsass/docs/custom-functions-internal.md +0 -122
  170. data/ext/libsass/docs/dev-ast-memory.md +0 -223
  171. data/ext/libsass/docs/implementations.md +0 -56
  172. data/ext/libsass/docs/plugins.md +0 -47
  173. data/ext/libsass/docs/setup-environment.md +0 -68
  174. data/ext/libsass/docs/source-map-internals.md +0 -51
  175. data/ext/libsass/docs/trace.md +0 -26
  176. data/ext/libsass/docs/triage.md +0 -17
  177. data/ext/libsass/docs/unicode.md +0 -39
  178. data/ext/libsass/extconf.rb +0 -6
  179. data/ext/libsass/script/bootstrap +0 -13
  180. data/ext/libsass/script/branding +0 -10
  181. data/ext/libsass/script/ci-build-libsass +0 -134
  182. data/ext/libsass/script/ci-build-plugin +0 -62
  183. data/ext/libsass/script/ci-install-compiler +0 -6
  184. data/ext/libsass/script/ci-install-deps +0 -20
  185. data/ext/libsass/script/ci-report-coverage +0 -42
  186. data/ext/libsass/script/spec +0 -5
  187. data/ext/libsass/script/tap-driver +0 -652
  188. data/ext/libsass/script/tap-runner +0 -1
  189. data/ext/libsass/script/test-leaks.pl +0 -103
  190. data/ext/libsass/src/functions.cpp +0 -2234
  191. data/ext/libsass/src/functions.hpp +0 -198
  192. data/ext/libsass/src/to_c.hpp +0 -39
  193. data/ext/libsass/test/test_node.cpp +0 -94
  194. data/ext/libsass/test/test_paths.cpp +0 -28
  195. data/ext/libsass/test/test_selector_difference.cpp +0 -25
  196. data/ext/libsass/test/test_specificity.cpp +0 -25
  197. data/ext/libsass/test/test_subset_map.cpp +0 -472
  198. data/ext/libsass/test/test_superselector.cpp +0 -69
  199. data/ext/libsass/test/test_unification.cpp +0 -31
  200. data/lib/tasks/libsass.rb +0 -33
@@ -1,223 +0,0 @@
1
- # LibSass smart pointer implementation
2
-
3
- LibSass uses smart pointers very similar to `shared_ptr` known
4
- by Boost or C++11. Implementation is a bit less modular since
5
- it was not needed. Various compile time debug options are
6
- available if you need to debug memory life-cycles.
7
-
8
-
9
- ## Memory Classes
10
-
11
- ### SharedObj
12
-
13
- Base class for the actual node implementations. This ensures
14
- that every object has a reference counter and other values.
15
-
16
- ```c++
17
- class AST_Node : public SharedObj { ... };
18
- ```
19
-
20
- ### SharedPtr (base class for SharedImpl)
21
-
22
- Base class that holds on to the pointer. The reference counter
23
- is stored inside the pointer object directly (`SharedObj`).
24
-
25
- ### SharedImpl (inherits from SharedPtr)
26
-
27
- This is the main base class for objects you use in your code. It
28
- will make sure that the memory it points at will be deleted once
29
- all copies to the same object/memory go out of scope.
30
-
31
- ```c++
32
- Class* pointer = new Class(...);
33
- SharedImpl<Class> obj(pointer);
34
- ```
35
-
36
- To spare the developer of typing the templated class every time,
37
- we created typedefs for each available AST Node specialization.
38
-
39
- ```c++
40
- typedef SharedImpl<Number> Number_Obj;
41
- Number_Obj number = SASS_MEMORY_NEW(...);
42
- ```
43
-
44
-
45
- ## Memory life-cycles
46
-
47
- ### Pointer pickups
48
-
49
- I often use the terminology of "pickup". This means the moment when
50
- a raw pointer not under any control is assigned to a reference counted
51
- object (`XYZ_Obj = XYZ_Ptr`). From that point on memory will be
52
- automatically released once the object goes out of scope (but only
53
- if the reference counter reaches zero). Main point beeing, you don't
54
- have to worry about memory management yourself.
55
-
56
- ### Object detach
57
-
58
- Sometimes we can't return reference counted objects directly (see
59
- invalid covariant return types problems below). But we often still
60
- need to use reference objects inside a function to avoid leaks when
61
- something throws. For this you can use `detach`, which basically
62
- detaches the pointer memory from the reference counted object. So
63
- when the reference counted object goes out of scope, it will not
64
- free the attached memory. You are now again in charge of freeing
65
- the memory (just assign it to a reference counted object again).
66
-
67
-
68
- ## Circular references
69
-
70
- Reference counted memory implementations are prone to circular references.
71
- This can be addressed by using a multi generation garbage collector. But
72
- for our use-case that seems overkill. There is no way so far for users
73
- (sass code) to create circular references. Therefore we can code around
74
- this possible issue. But developers should be aware of this limitation.
75
-
76
- There are AFAIR two places where circular references could happen. One is
77
- the `sources` member on every `Selector`. The other one can happen in the
78
- extend code (Node handling). The easy way to avoid this is to only assign
79
- complete object clones to these members. If you know the objects lifetime
80
- is longer than the reference you create, you can also just store the raw
81
- pointer. Once needed this could be solved with weak pointers.
82
-
83
-
84
- ## Addressing the invalid covariant return types problems
85
-
86
- If you are not familiar with the mentioned problem, you may want
87
- to read up on covariant return types and virtual functions, i.e.
88
-
89
- - http://stackoverflow.com/questions/6924754/return-type-covariance-with-smart-pointers
90
- - http://stackoverflow.com/questions/196733/how-can-i-use-covariant-return-types-with-smart-pointers
91
- - http://stackoverflow.com/questions/2687790/how-to-accomplish-covariant-return-types-when-returning-a-shared-ptr
92
-
93
- We hit this issue at least with the CRTP visitor pattern (eval, expand,
94
- listize and so forth). This means we cannot return reference counted
95
- objects directly. We are forced to return raw pointers or we would need
96
- to have a lot of explicit and expensive upcasts by callers/consumers.
97
-
98
- ### Simple functions that allocate new AST Nodes
99
-
100
- In the parser step we often create new objects and can just return a
101
- unique pointer (meaning ownership clearly shifts back to the caller).
102
- The caller/consumer is responsible that the memory is freed.
103
-
104
- ```c++
105
- typedef Number* Number_Ptr;
106
- int parse_integer() {
107
- ... // do the parsing
108
- return 42;
109
- }
110
- Number_Ptr parse_number() {
111
- Number_Ptr p_nr = SASS_MEMORY_NEW(...);
112
- p_nr->value(parse_integer());
113
- return p_nr;
114
- }
115
- Number_Obj nr = parse_number();
116
- ```
117
-
118
- The above would be the encouraged pattern for such simple cases.
119
-
120
- ### Allocate new AST Nodes in functions that can throw
121
-
122
- There is a major caveat with the previous example, considering this
123
- more real-life implementation that throws an error. The throw may
124
- happen deep down in another function. Holding raw pointers that
125
- we need to free would leak in this case.
126
-
127
- ```c++
128
- int parse_integer() {
129
- ... // do the parsing
130
- if (error) throw(error);
131
- return 42;
132
- }
133
- ```
134
-
135
- With this `parse_integer` function the previous example would leak memory.
136
- I guess it is pretty obvious, as the allocated memory will not be freed,
137
- as it was never assigned to a SharedObj value. Therefore the above code
138
- would better be written as:
139
-
140
- ```c++
141
- typedef Number* Number_Ptr;
142
- int parse_integer() {
143
- ... // do the parsing
144
- if (error) throw(error);
145
- return 42;
146
- }
147
- // this leaks due to pointer return
148
- // should return Number_Obj instead
149
- // though not possible for virtuals!
150
- Number_Ptr parse_number() {
151
- Number_Obj nr = SASS_MEMORY_NEW(...);
152
- nr->value(parse_integer()); // throws
153
- return &nr; // Ptr from Obj
154
- }
155
- Number_Obj nr = parse_number();
156
- // will now be freed automatically
157
- ```
158
-
159
- The example above unfortunately will not work as is, since we return a
160
- `Number_Ptr` from that function. Therefore the object allocated inside
161
- the function is already gone when it is picked up again by the caller.
162
- The easy fix for the given simplified use case would be to change the
163
- return type of `parse_number` to `Number_Obj`. Indeed we do it exactly
164
- this way in the parser. But as stated above, this will not work for
165
- virtual functions due to invalid covariant return types!
166
-
167
- ### Return managed objects from virtual functions
168
-
169
- The easy fix would be to just create a new copy on the heap and return
170
- that. But this seems like a very inelegant solution to this problem. I
171
- mean why can't we just tell the object to treat it like a newly allocated
172
- object? And indeed we can. I've added a `detach` method that will tell
173
- the object to survive deallocation until the next pickup. This means
174
- that it will leak if it is not picked up by consumer.
175
-
176
- ```c++
177
- typedef Number* Number_Ptr;
178
- int parse_integer() {
179
- ... // do the parsing
180
- if (error) throw(error);
181
- return 42;
182
- }
183
- Number_Ptr parse_number() {
184
- Number_Obj nr = SASS_MEMORY_NEW(...);
185
- nr->value(parse_integer()); // throws
186
- return nr.detach();
187
- }
188
- Number_Obj nr = parse_number();
189
- // will now be freed automatically
190
- ```
191
-
192
-
193
- ## Compile time debug options
194
-
195
- To enable memory debugging you need to define `DEBUG_SHARED_PTR`.
196
- This can i.e. be done in `include/sass/base.h`
197
-
198
- ```c++
199
- define DEBUG_SHARED_PTR
200
- ```
201
-
202
- This will print lost memory on exit to stderr. You can also use
203
- `setDbg(true)` on sepecific variables to emit reference counter
204
- increase, decrease and other events.
205
-
206
-
207
- ## Why reinvent the wheel when there is `shared_ptr` from C++11
208
-
209
- First, implementing a smart pointer class is not really that hard. It
210
- was indeed also a learning experience for myself. But there are more
211
- profound advantages:
212
-
213
- - Better GCC 4.4 compatibility (which most code still has OOTB)
214
- - Not thread safe (give us some free performance on some compiler)
215
- - Beeing able to track memory allocations for debugging purposes
216
- - Adding additional features if needed (as seen in `detach`)
217
- - Optional: optimized weak pointer implementation possible
218
-
219
- ### Thread Safety
220
-
221
- As said above, this is not thread safe currently. But we don't need
222
- this ATM anyway. And I guess we probably never will share AST Nodes
223
- across different threads.
@@ -1,56 +0,0 @@
1
- There are several implementations of `libsass` for a variety of languages. Here are just a few of them. Note, some implementations may or may not be up to date. We have not verified whether they work.
2
-
3
- ### C
4
- * [sassc](https://github.com/hcatlin/sassc)
5
-
6
- ### Crystal
7
- * [sass.cr](https://github.com/straight-shoota/sass.cr)
8
-
9
- ### Elixir
10
- * [sass.ex](https://github.com/scottdavis/sass.ex)
11
-
12
- ### Go
13
- * [go-libsass](https://github.com/wellington/go-libsass)
14
- * [go_sass](https://github.com/suapapa/go_sass)
15
- * [go-sass](https://github.com/SamWhited/go-sass)
16
-
17
- ### Lua
18
- * [lua-sass](https://github.com/craigbarnes/lua-sass)
19
-
20
- ### .NET
21
- * [libsass-net](https://github.com/darrenkopp/libsass-net)
22
- * [NSass](https://github.com/TBAPI-0KA/NSass)
23
- * [Sass.Net](https://github.com/andyalm/Sass.Net)
24
-
25
- ### node.js
26
- * [node-sass](https://github.com/andrew/node-sass)
27
-
28
- ### Java
29
- * [libsass-maven-plugin](https://github.com/warmuuh/libsass-maven-plugin)
30
- * [jsass](https://github.com/bit3/jsass)
31
-
32
- ### JavaScript
33
- * [sass.js](https://github.com/medialize/sass.js)
34
-
35
- ### Perl
36
- * [CSS::Sass](https://github.com/caldwell/CSS-Sass)
37
- * [Text::Sass::XS](https://github.com/ysasaki/Text-Sass-XS)
38
-
39
- ### PHP
40
- * [sassphp](https://github.com/sensational/sassphp)
41
- * [php-sass](https://github.com/lesstif/php-sass)
42
-
43
- ### Python
44
- * [libsass-python](https://github.com/dahlia/libsass-python)
45
- * [SassPython](https://github.com/marianoguerra/SassPython)
46
- * [pylibsass](https://github.com/rsenk330/pylibsass)
47
- * [python-scss](https://github.com/pistolero/python-scss)
48
-
49
- ### Ruby
50
- * [sassruby](https://github.com/hcatlin/sassruby)
51
-
52
- ### Scala
53
- * [Sass-Scala](https://github.com/kkung/Sass-Scala)
54
-
55
- ### Tcl
56
- * [tclsass](https://github.com/flightaware/tclsass)
@@ -1,47 +0,0 @@
1
- Plugins are shared object files (.so on *nix and .dll on win) that can be loaded by LibSass on runtime. Currently we only provide a way to load internal/custom functions from plugins. In the future we probably will also add a way to provide custom importers via plugins (needs more refactoring to [support multiple importers with some kind of priority system](https://github.com/sass/libsass/issues/962)).
2
-
3
- ## plugin.cpp
4
-
5
- ```C++
6
- #include <cstring>
7
- #include <iostream>
8
- #include <stdint.h>
9
- #include "sass_values.h"
10
-
11
- union Sass_Value* ADDCALL call_fn_foo(const union Sass_Value* s_args, void* cookie)
12
- {
13
- // we actually abuse the void* to store an "int"
14
- return sass_make_number((intptr_t)cookie, "px");
15
- }
16
-
17
- extern "C" const char* ADDCALL libsass_get_version() {
18
- return libsass_version();
19
- }
20
-
21
- extern "C" Sass_C_Function_List ADDCALL libsass_load_functions()
22
- {
23
- // allocate a custom function caller
24
- Sass_C_Function_Callback fn_foo =
25
- sass_make_function("foo()", call_fn_foo, (void*)42);
26
- // create list of all custom functions
27
- Sass_C_Function_List fn_list = sass_make_function_list(1);
28
- // put the only function in this plugin to the list
29
- sass_function_set_list_entry(fn_list, 0, fn_foo);
30
- // return the list
31
- return fn_list;
32
- }
33
- ```
34
-
35
- To compile the plugin you need to have LibSass already built as a shared library (to link against it). The commands below expect the shared library in the `lib` sub-directory (`-Llib`). The plugin and the main LibSass process should "consume" the same shared LibSass library on runtime. It will propably also work if they use different LibSass versions. In this case we check if the major versions are compatible (i.e. 3.1.3 and 3.1.1 would be considered compatible).
36
-
37
- ## Compile with gcc on linux
38
-
39
- ```bash
40
- g++ -O2 -shared plugin.cpp -o plugin.so -fPIC -Llib -lsass
41
- ```
42
-
43
- ## Compile with mingw on windows
44
-
45
- ```bash
46
- g++ -O2 -shared plugin.cpp -o plugin.dll -Llib -lsass
47
- ```
@@ -1,68 +0,0 @@
1
- ## Requirements
2
- In order to install and setup your local development environment, there are some prerequisites:
3
-
4
- * git
5
- * gcc/clang/llvm (Linux: build tools, Mac OS X: XCode w/ Command Line Tools)
6
- * ruby w/ bundler
7
-
8
- OS X:
9
- First you'll need to install XCode which you can now get from the AppStore installed on your mac. After you download that and run it, then run this on the command line:
10
-
11
- ````
12
- xcode-select --install
13
- ````
14
-
15
- ## Cloning the Projects
16
-
17
- First, clone the project and then add a line to your `~/.bash_profile` that will let other programs know where the LibSass dev files are.
18
-
19
- ````
20
- git clone git@github.com:sass/libsass.git
21
- cd libsass
22
- echo "export SASS_LIBSASS_PATH=$(pwd)" >> ~/.bash_profile
23
-
24
- ````
25
-
26
- Then, if you run the "bootstrap" script, it should clone all the other required projects.
27
-
28
- ````
29
- ./script/bootstrap
30
- ````
31
-
32
- You should now have a `sass-spec` and `sassc` folder within the libsass folder. Both of these are clones of their respective git projects. If you want to do a pull request, remember to work in those folders. For instance, if you want to add a test (see other documentation for how to do that), make sure to commit it to your *fork* of the sass-spec github project. Also, whenever you are running tests, make sure to `pull` from the origin! We want to make sure we are testing against the newest libsass, sassc, and sass-spec!
33
-
34
- Now, try and see if you can build the project. We do that with the `make` command.
35
-
36
- ````
37
- make
38
- ````
39
-
40
- At this point, if you get an error, something is most likely wrong with your compiler installation. Yikes. It's hard to cover how to fix this in an article. Feel free to open an issue and we'll try and help! But, remember, before you do that, googling the error message is your friend! Many problems are solved quickly that way.
41
-
42
- ## Running The Spec Against LibSass
43
-
44
- Then, to run the spec against LibSass, just run:
45
-
46
- ````
47
- ./script/spec
48
- ````
49
-
50
- If you get an error about `SASS_LIBSASS_PATH`, you may still need to set a variable pointing to the libsass folder, like this:
51
-
52
- ````
53
- export SASS_LIBSASS_PATH=/Users/you/path/libsass
54
- ````
55
-
56
- ...where the latter part is to the `libsass` directory you've cloned. You can get this path by typing `pwd` in the Terminal
57
-
58
- ## Running the Spec Against Ruby Sass
59
-
60
- Go into the sass-spec folder that should have been cloned earlier with the "bootstrap" command. Run the following.
61
-
62
- ````
63
- bundle install
64
- ./sass-spec.rb
65
- ````
66
-
67
- Voila! Now you are testing against Sass too!
68
-
@@ -1,51 +0,0 @@
1
- This document is mainly intended for developers!
2
-
3
- # Documenting some of the source map internals
4
-
5
- Since source maps are somewhat a black box to all LibSass maintainers, [I](@mgreter) will try to document my findings with source maps in LibSass, as I come across them. This document will also brievely explain how LibSass parses the source and how it outputs the result.
6
-
7
- The main storage for SourceMap mappings is the `mappings` vector:
8
-
9
- ```
10
- # in source_map.hpp
11
- vector<Mapping> mappings
12
- # in mappings.hpp
13
- struct Mapping ...
14
- Position original_position;
15
- Position generated_position;
16
- ```
17
-
18
- ## Every parsed token has its source associated
19
-
20
- LibSass uses a lexical parser. Whenever LibSass finds a token of interest, it creates a specific `AST_Node`, which will hold a reference to the input source with line/column information. `AST_Node` is the base class for all parsed items. They are declared in `ast.hpp` and are used in `parser.hpp`. Here a simple example:
21
-
22
- ```
23
- if (lex< custom_property_name >()) {
24
- Sass::String* prop = new (ctx.mem) String_Constant(path, source_position, lexed);
25
- return new (ctx.mem) Declaration(path, prop->position(), prop, ...);
26
- }
27
- ```
28
-
29
- ## How is the `source_position` calculated
30
-
31
- This is automatically done with `lex` in `parser.hpp`. Whenever something is lexed, the `source_position` is updated. But be aware that `source_position` points to the begining of the parsed text. If you need a mapping for the position where the parsing ended, you need to add another call to `lex` (to match nothing)!
32
-
33
- ```
34
- lex< exactly < empty_str > >();
35
- end = new (ctx.mem) String_Constant(path, source_position, lexed);
36
- ```
37
-
38
- ## How are mappings for the output created
39
-
40
- So far we have collected all needed data for all tokens in the input stream. We can now use this information to create mappings when we put things into the output stream. Mappings are created via the `add_mappings` method:
41
-
42
- ```
43
- # in source_map.hpp
44
- void add_mapping(AST_Node* node);
45
- ```
46
-
47
- This method is called in two places:
48
- - `Inspect::append_to_buffer`
49
- - `Output_[Nested|Compressed]::append_to_buffer`
50
-
51
- Mappings can only be created for things that have been parsed into a `AST_Node`. Otherwise we do not have the information to create the mappings, which is the reason why LibSass currently only maps the most important tokens in source maps.