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
@@ -0,0 +1,568 @@
1
+ #ifndef SASS_AST_SEL_H
2
+ #define SASS_AST_SEL_H
3
+
4
+ // sass.hpp must go before all system headers to get the
5
+ // __EXTENSIONS__ fix on Solaris.
6
+ #include "sass.hpp"
7
+
8
+ #include <set>
9
+ #include <deque>
10
+ #include <vector>
11
+ #include <string>
12
+ #include <sstream>
13
+ #include <iostream>
14
+ #include <typeinfo>
15
+ #include <algorithm>
16
+ #include "sass/base.h"
17
+ #include "ast_fwd_decl.hpp"
18
+
19
+ #include "util.hpp"
20
+ #include "units.hpp"
21
+ #include "context.hpp"
22
+ #include "position.hpp"
23
+ #include "constants.hpp"
24
+ #include "operation.hpp"
25
+ #include "position.hpp"
26
+ #include "inspect.hpp"
27
+ #include "source_map.hpp"
28
+ #include "environment.hpp"
29
+ #include "error_handling.hpp"
30
+ #include "ast_def_macros.hpp"
31
+ #include "ast_fwd_decl.hpp"
32
+ #include "source_map.hpp"
33
+ #include "fn_utils.hpp"
34
+
35
+ #include "sass.h"
36
+
37
+ namespace Sass {
38
+
39
+ /////////////////////////////////////////
40
+ // Abstract base class for CSS selectors.
41
+ /////////////////////////////////////////
42
+ class Selector : public Expression {
43
+ // line break before list separator
44
+ ADD_PROPERTY(bool, has_line_feed)
45
+ // line break after list separator
46
+ ADD_PROPERTY(bool, has_line_break)
47
+ // maybe we have optional flag
48
+ ADD_PROPERTY(bool, is_optional)
49
+ // must not be a reference counted object
50
+ // otherwise we create circular references
51
+ ADD_PROPERTY(Media_Block*, media_block)
52
+ protected:
53
+ mutable size_t hash_;
54
+ public:
55
+ Selector(ParserState pstate);
56
+ virtual ~Selector() = 0;
57
+ size_t hash() const override = 0;
58
+ virtual unsigned long specificity() const = 0;
59
+ virtual int unification_order() const = 0;
60
+ virtual void set_media_block(Media_Block* mb);
61
+ virtual bool has_parent_ref() const;
62
+ virtual bool has_real_parent_ref() const;
63
+ // dispatch to correct handlers
64
+ virtual bool operator<(const Selector& rhs) const = 0;
65
+ virtual bool operator==(const Selector& rhs) const = 0;
66
+ bool operator>(const Selector& rhs) const { return rhs < *this; };
67
+ bool operator!=(const Selector& rhs) const { return !(rhs == *this); };
68
+ ATTACH_VIRTUAL_AST_OPERATIONS(Selector);
69
+ };
70
+ inline Selector::~Selector() { }
71
+
72
+ /////////////////////////////////////////////////////////////////////////
73
+ // Interpolated selectors -- the interpolated String will be expanded and
74
+ // re-parsed into a normal selector class.
75
+ /////////////////////////////////////////////////////////////////////////
76
+ class Selector_Schema final : public AST_Node {
77
+ ADD_PROPERTY(String_Obj, contents)
78
+ ADD_PROPERTY(bool, connect_parent);
79
+ // must not be a reference counted object
80
+ // otherwise we create circular references
81
+ ADD_PROPERTY(Media_Block*, media_block)
82
+ // store computed hash
83
+ mutable size_t hash_;
84
+ public:
85
+ Selector_Schema(ParserState pstate, String_Obj c);
86
+ bool has_parent_ref() const;
87
+ bool has_real_parent_ref() const;
88
+ bool operator<(const Selector& rhs) const;
89
+ bool operator==(const Selector& rhs) const;
90
+ // selector schema is not yet a final selector, so we do not
91
+ // have a specificity for it yet. We need to
92
+ virtual unsigned long specificity() const;
93
+ size_t hash() const override;
94
+ ATTACH_AST_OPERATIONS(Selector_Schema)
95
+ ATTACH_CRTP_PERFORM_METHODS()
96
+ };
97
+
98
+ ////////////////////////////////////////////
99
+ // Abstract base class for simple selectors.
100
+ ////////////////////////////////////////////
101
+ class Simple_Selector : public Selector {
102
+ public:
103
+ enum Simple_Type {
104
+ ID_SEL,
105
+ TYPE_SEL,
106
+ CLASS_SEL,
107
+ PSEUDO_SEL,
108
+ PARENT_SEL,
109
+ WRAPPED_SEL,
110
+ ATTRIBUTE_SEL,
111
+ PLACEHOLDER_SEL,
112
+ };
113
+ public:
114
+ HASH_CONSTREF(std::string, ns)
115
+ HASH_CONSTREF(std::string, name)
116
+ ADD_PROPERTY(Simple_Type, simple_type)
117
+ HASH_PROPERTY(bool, has_ns)
118
+ public:
119
+ Simple_Selector(ParserState pstate, std::string n = "");
120
+ virtual std::string ns_name() const;
121
+ size_t hash() const override;
122
+ bool empty() const;
123
+ // namespace compare functions
124
+ bool is_ns_eq(const Simple_Selector& r) const;
125
+ // namespace query functions
126
+ bool is_universal_ns() const;
127
+ bool is_empty_ns() const;
128
+ bool has_empty_ns() const;
129
+ bool has_qualified_ns() const;
130
+ // name query functions
131
+ bool is_universal() const;
132
+ virtual bool has_placeholder();
133
+
134
+ virtual ~Simple_Selector() = 0;
135
+ virtual Compound_Selector* unify_with(Compound_Selector*);
136
+
137
+ virtual bool has_parent_ref() const override;
138
+ virtual bool has_real_parent_ref() const override;
139
+ virtual bool is_pseudo_element() const;
140
+ virtual bool is_superselector_of(const Compound_Selector* sub) const;
141
+
142
+ bool operator<(const Selector& rhs) const final override;
143
+ bool operator==(const Selector& rhs) const final override;
144
+ virtual bool operator<(const Selector_List& rhs) const;
145
+ virtual bool operator==(const Selector_List& rhs) const;
146
+ virtual bool operator<(const Complex_Selector& rhs) const;
147
+ virtual bool operator==(const Complex_Selector& rhs) const;
148
+ virtual bool operator<(const Compound_Selector& rhs) const;
149
+ virtual bool operator==(const Compound_Selector& rhs) const;
150
+ virtual bool operator<(const Simple_Selector& rhs) const;
151
+ virtual bool operator==(const Simple_Selector& rhs) const;
152
+
153
+ ATTACH_VIRTUAL_AST_OPERATIONS(Simple_Selector);
154
+ ATTACH_CRTP_PERFORM_METHODS();
155
+
156
+ };
157
+ inline Simple_Selector::~Simple_Selector() { }
158
+
159
+ //////////////////////////////////
160
+ // The Parent Selector Expression.
161
+ //////////////////////////////////
162
+ class Parent_Selector final : public Simple_Selector {
163
+ // a real parent selector is given by the user
164
+ // others are added implicitly to connect the
165
+ // selector scopes automatically when rendered
166
+ // a Parent_Reference is never seen in selectors
167
+ // and is only used in values (e.g. `prop: #{&};`)
168
+ ADD_PROPERTY(bool, real)
169
+ public:
170
+ Parent_Selector(ParserState pstate, bool r = true);
171
+
172
+ virtual bool has_parent_ref() const override;
173
+ virtual bool has_real_parent_ref() const override;
174
+
175
+ virtual unsigned long specificity() const override;
176
+ int unification_order() const override
177
+ {
178
+ throw std::runtime_error("unification_order for Parent_Selector is undefined");
179
+ }
180
+ std::string type() const override { return "selector"; }
181
+ static std::string type_name() { return "selector"; }
182
+ bool operator<(const Simple_Selector& rhs) const final override;
183
+ bool operator==(const Simple_Selector& rhs) const final override;
184
+ bool operator<(const Parent_Selector& rhs) const;
185
+ bool operator==(const Parent_Selector& rhs) const;
186
+ ATTACH_AST_OPERATIONS(Parent_Selector)
187
+ ATTACH_CRTP_PERFORM_METHODS()
188
+ };
189
+
190
+
191
+ /////////////////////////////////////////////////////////////////////////
192
+ // Placeholder selectors (e.g., "%foo") for use in extend-only selectors.
193
+ /////////////////////////////////////////////////////////////////////////
194
+ class Placeholder_Selector final : public Simple_Selector {
195
+ public:
196
+ Placeholder_Selector(ParserState pstate, std::string n);
197
+
198
+ int unification_order() const override
199
+ {
200
+ return Constants::UnificationOrder_Placeholder;
201
+ }
202
+ virtual ~Placeholder_Selector() {};
203
+ virtual unsigned long specificity() const override;
204
+ virtual bool has_placeholder() override;
205
+ bool operator<(const Simple_Selector& rhs) const override;
206
+ bool operator==(const Simple_Selector& rhs) const override;
207
+ bool operator<(const Placeholder_Selector& rhs) const;
208
+ bool operator==(const Placeholder_Selector& rhs) const;
209
+ ATTACH_AST_OPERATIONS(Placeholder_Selector)
210
+ ATTACH_CRTP_PERFORM_METHODS()
211
+ };
212
+
213
+ /////////////////////////////////////////////////////////////////////
214
+ // Type selectors (and the universal selector) -- e.g., div, span, *.
215
+ /////////////////////////////////////////////////////////////////////
216
+ class Type_Selector final : public Simple_Selector {
217
+ public:
218
+ Type_Selector(ParserState pstate, std::string n);
219
+ virtual unsigned long specificity() const override;
220
+ int unification_order() const override
221
+ {
222
+ return Constants::UnificationOrder_Element;
223
+ }
224
+ Simple_Selector* unify_with(Simple_Selector*);
225
+ Compound_Selector* unify_with(Compound_Selector*) override;
226
+ bool operator<(const Simple_Selector& rhs) const final override;
227
+ bool operator==(const Simple_Selector& rhs) const final override;
228
+ bool operator<(const Type_Selector& rhs) const;
229
+ bool operator==(const Type_Selector& rhs) const;
230
+ ATTACH_AST_OPERATIONS(Type_Selector)
231
+ ATTACH_CRTP_PERFORM_METHODS()
232
+ };
233
+
234
+ ////////////////////////////////////////////////
235
+ // Class selectors -- i.e., .foo.
236
+ ////////////////////////////////////////////////
237
+ class Class_Selector final : public Simple_Selector {
238
+ public:
239
+ Class_Selector(ParserState pstate, std::string n);
240
+ virtual unsigned long specificity() const override;
241
+ int unification_order() const override
242
+ {
243
+ return Constants::UnificationOrder_Class;
244
+ }
245
+ Compound_Selector* unify_with(Compound_Selector*) override;
246
+ bool operator<(const Simple_Selector& rhs) const final override;
247
+ bool operator==(const Simple_Selector& rhs) const final override;
248
+ bool operator<(const Class_Selector& rhs) const;
249
+ bool operator==(const Class_Selector& rhs) const;
250
+ ATTACH_AST_OPERATIONS(Class_Selector)
251
+ ATTACH_CRTP_PERFORM_METHODS()
252
+ };
253
+
254
+ ////////////////////////////////////////////////
255
+ // ID selectors -- i.e., #foo.
256
+ ////////////////////////////////////////////////
257
+ class Id_Selector final : public Simple_Selector {
258
+ public:
259
+ Id_Selector(ParserState pstate, std::string n);
260
+ virtual unsigned long specificity() const override;
261
+ int unification_order() const override
262
+ {
263
+ return Constants::UnificationOrder_Id;
264
+ }
265
+ Compound_Selector* unify_with(Compound_Selector*) override;
266
+ bool operator<(const Simple_Selector& rhs) const final override;
267
+ bool operator==(const Simple_Selector& rhs) const final override;
268
+ bool operator<(const Id_Selector& rhs) const;
269
+ bool operator==(const Id_Selector& rhs) const;
270
+ ATTACH_AST_OPERATIONS(Id_Selector)
271
+ ATTACH_CRTP_PERFORM_METHODS()
272
+ };
273
+
274
+ ///////////////////////////////////////////////////
275
+ // Attribute selectors -- e.g., [src*=".jpg"], etc.
276
+ ///////////////////////////////////////////////////
277
+ class Attribute_Selector final : public Simple_Selector {
278
+ ADD_CONSTREF(std::string, matcher)
279
+ // this cannot be changed to obj atm!!!!!!????!!!!!!!
280
+ ADD_PROPERTY(String_Obj, value) // might be interpolated
281
+ ADD_PROPERTY(char, modifier);
282
+ public:
283
+ Attribute_Selector(ParserState pstate, std::string n, std::string m, String_Obj v, char o = 0);
284
+ size_t hash() const override;
285
+ virtual unsigned long specificity() const override;
286
+ int unification_order() const override
287
+ {
288
+ return Constants::UnificationOrder_Attribute;
289
+ }
290
+ bool operator<(const Simple_Selector& rhs) const final override;
291
+ bool operator==(const Simple_Selector& rhs) const final override;
292
+ bool operator<(const Attribute_Selector& rhs) const;
293
+ bool operator==(const Attribute_Selector& rhs) const;
294
+ ATTACH_AST_OPERATIONS(Attribute_Selector)
295
+ ATTACH_CRTP_PERFORM_METHODS()
296
+ };
297
+
298
+ //////////////////////////////////////////////////////////////////
299
+ // Pseudo selectors -- e.g., :first-child, :nth-of-type(...), etc.
300
+ //////////////////////////////////////////////////////////////////
301
+ /* '::' starts a pseudo-element, ':' a pseudo-class */
302
+ /* Except :first-line, :first-letter, :before and :after */
303
+ /* Note that pseudo-elements are restricted to one per selector */
304
+ /* and occur only in the last simple_selector_sequence. */
305
+ inline bool is_pseudo_class_element(const std::string& name)
306
+ {
307
+ return name == ":before" ||
308
+ name == ":after" ||
309
+ name == ":first-line" ||
310
+ name == ":first-letter";
311
+ }
312
+
313
+ // Pseudo Selector cannot have any namespace?
314
+ class Pseudo_Selector final : public Simple_Selector {
315
+ ADD_PROPERTY(String_Obj, expression)
316
+ public:
317
+ Pseudo_Selector(ParserState pstate, std::string n, String_Obj expr = {});
318
+ virtual bool is_pseudo_element() const override;
319
+ size_t hash() const override;
320
+ virtual unsigned long specificity() const override;
321
+ int unification_order() const override
322
+ {
323
+ if (is_pseudo_element())
324
+ return Constants::UnificationOrder_PseudoElement;
325
+ return Constants::UnificationOrder_PseudoClass;
326
+ }
327
+ bool operator<(const Simple_Selector& rhs) const final override;
328
+ bool operator==(const Simple_Selector& rhs) const final override;
329
+ bool operator<(const Pseudo_Selector& rhs) const;
330
+ bool operator==(const Pseudo_Selector& rhs) const;
331
+ Compound_Selector* unify_with(Compound_Selector*) override;
332
+ ATTACH_AST_OPERATIONS(Pseudo_Selector)
333
+ ATTACH_CRTP_PERFORM_METHODS()
334
+ };
335
+
336
+ /////////////////////////////////////////////////
337
+ // Wrapped selector -- pseudo selector that takes a list of selectors as argument(s) e.g., :not(:first-of-type), :-moz-any(ol p.blah, ul, menu, dir)
338
+ /////////////////////////////////////////////////
339
+ class Wrapped_Selector final : public Simple_Selector {
340
+ ADD_PROPERTY(Selector_List_Obj, selector)
341
+ public:
342
+ Wrapped_Selector(ParserState pstate, std::string n, Selector_List_Obj sel);
343
+ using Simple_Selector::is_superselector_of;
344
+ bool is_superselector_of(const Wrapped_Selector* sub) const;
345
+ // Selectors inside the negation pseudo-class are counted like any
346
+ // other, but the negation itself does not count as a pseudo-class.
347
+ size_t hash() const override;
348
+ bool has_parent_ref() const override;
349
+ bool has_real_parent_ref() const override;
350
+ unsigned long specificity() const override;
351
+ int unification_order() const override
352
+ {
353
+ return Constants::UnificationOrder_Wrapped;
354
+ }
355
+ bool find ( bool (*f)(AST_Node_Obj) ) override;
356
+ bool operator<(const Simple_Selector& rhs) const final override;
357
+ bool operator==(const Simple_Selector& rhs) const final override;
358
+ bool operator<(const Wrapped_Selector& rhs) const;
359
+ bool operator==(const Wrapped_Selector& rhs) const;
360
+ void cloneChildren() override;
361
+ ATTACH_AST_OPERATIONS(Wrapped_Selector)
362
+ ATTACH_CRTP_PERFORM_METHODS()
363
+ };
364
+
365
+ ////////////////////////////////////////////////////////////////////////////
366
+ // Simple selector sequences. Maintains flags indicating whether it contains
367
+ // any parent references or placeholders, to simplify expansion.
368
+ ////////////////////////////////////////////////////////////////////////////
369
+ class Compound_Selector final : public Selector, public Vectorized<Simple_Selector_Obj> {
370
+ private:
371
+ ComplexSelectorSet sources_;
372
+ ADD_PROPERTY(bool, extended);
373
+ ADD_PROPERTY(bool, has_parent_reference);
374
+ protected:
375
+ void adjust_after_pushing(Simple_Selector_Obj s) override
376
+ {
377
+ // if (s->has_reference()) has_reference(true);
378
+ // if (s->has_placeholder()) has_placeholder(true);
379
+ }
380
+ public:
381
+ Compound_Selector(ParserState pstate, size_t s = 0);
382
+ bool contains_placeholder();
383
+ void append(Simple_Selector_Obj element) override;
384
+ bool is_universal() const;
385
+ Complex_Selector_Obj to_complex();
386
+ Compound_Selector* unify_with(Compound_Selector* rhs);
387
+ // virtual Placeholder_Selector* find_placeholder();
388
+ bool has_parent_ref() const override;
389
+ bool has_real_parent_ref() const override;
390
+ Simple_Selector* base() const;
391
+ bool is_superselector_of(const Compound_Selector* sub, std::string wrapped = "") const;
392
+ bool is_superselector_of(const Complex_Selector* sub, std::string wrapped = "") const;
393
+ bool is_superselector_of(const Selector_List* sub, std::string wrapped = "") const;
394
+ size_t hash() const override;
395
+ virtual unsigned long specificity() const override;
396
+ virtual bool has_placeholder();
397
+ bool is_empty_reference();
398
+ int unification_order() const override
399
+ {
400
+ throw std::runtime_error("unification_order for Compound_Selector is undefined");
401
+ }
402
+ bool find ( bool (*f)(AST_Node_Obj) ) override;
403
+
404
+ bool operator<(const Selector& rhs) const override;
405
+ bool operator==(const Selector& rhs) const override;
406
+ bool operator<(const Selector_List& rhs) const;
407
+ bool operator==(const Selector_List& rhs) const;
408
+ bool operator<(const Complex_Selector& rhs) const;
409
+ bool operator==(const Complex_Selector& rhs) const;
410
+ bool operator<(const Compound_Selector& rhs) const;
411
+ bool operator==(const Compound_Selector& rhs) const;
412
+ bool operator<(const Simple_Selector& rhs) const;
413
+ bool operator==(const Simple_Selector& rhs) const;
414
+
415
+ ComplexSelectorSet& sources() { return sources_; }
416
+ void clearSources() { sources_.clear(); }
417
+ void mergeSources(ComplexSelectorSet& sources);
418
+
419
+ Compound_Selector* minus(Compound_Selector* rhs);
420
+ void cloneChildren() override;
421
+ ATTACH_AST_OPERATIONS(Compound_Selector)
422
+ ATTACH_CRTP_PERFORM_METHODS()
423
+ };
424
+
425
+ ////////////////////////////////////////////////////////////////////////////
426
+ // General selectors -- i.e., simple sequences combined with one of the four
427
+ // CSS selector combinators (">", "+", "~", and whitespace). Essentially a
428
+ // linked list.
429
+ ////////////////////////////////////////////////////////////////////////////
430
+ class Complex_Selector final : public Selector {
431
+ public:
432
+ enum Combinator { ANCESTOR_OF, PARENT_OF, PRECEDES, ADJACENT_TO, REFERENCE };
433
+ private:
434
+ HASH_CONSTREF(Combinator, combinator)
435
+ HASH_PROPERTY(Compound_Selector_Obj, head)
436
+ HASH_PROPERTY(Complex_Selector_Obj, tail)
437
+ HASH_PROPERTY(String_Obj, reference);
438
+ public:
439
+ bool contains_placeholder() {
440
+ if (head() && head()->contains_placeholder()) return true;
441
+ if (tail() && tail()->contains_placeholder()) return true;
442
+ return false;
443
+ };
444
+ Complex_Selector(ParserState pstate,
445
+ Combinator c = ANCESTOR_OF,
446
+ Compound_Selector_Obj h = {},
447
+ Complex_Selector_Obj t = {},
448
+ String_Obj r = {});
449
+
450
+ bool empty() const;
451
+
452
+ bool has_parent_ref() const override;
453
+ bool has_real_parent_ref() const override;
454
+ Complex_Selector_Obj skip_empty_reference();
455
+
456
+ // can still have a tail
457
+ bool is_empty_ancestor() const;
458
+
459
+ Selector_List* tails(Selector_List* tails);
460
+
461
+ // front returns the first real tail
462
+ // skips over parent and empty ones
463
+ const Complex_Selector* first() const;
464
+ Complex_Selector* mutable_first();
465
+
466
+ // last returns the last real tail
467
+ const Complex_Selector* last() const;
468
+ Complex_Selector* mutable_last();
469
+
470
+ size_t length() const;
471
+ Selector_List* resolve_parent_refs(SelectorStack& pstack, Backtraces& traces, bool implicit_parent = true);
472
+ bool is_superselector_of(const Compound_Selector* sub, std::string wrapping = "") const;
473
+ bool is_superselector_of(const Complex_Selector* sub, std::string wrapping = "") const;
474
+ bool is_superselector_of(const Selector_List* sub, std::string wrapping = "") const;
475
+ Selector_List* unify_with(Complex_Selector* rhs);
476
+ Combinator clear_innermost();
477
+ void append(Complex_Selector_Obj, Backtraces& traces);
478
+ void set_innermost(Complex_Selector_Obj, Combinator);
479
+
480
+ size_t hash() const override;
481
+ virtual unsigned long specificity() const override;
482
+ virtual void set_media_block(Media_Block* mb) override;
483
+ virtual bool has_placeholder();
484
+ int unification_order() const override
485
+ {
486
+ throw std::runtime_error("unification_order for Complex_Selector is undefined");
487
+ }
488
+ bool find ( bool (*f)(AST_Node_Obj) ) override;
489
+
490
+ bool operator<(const Selector& rhs) const override;
491
+ bool operator==(const Selector& rhs) const override;
492
+ bool operator<(const Selector_List& rhs) const;
493
+ bool operator==(const Selector_List& rhs) const;
494
+ bool operator<(const Complex_Selector& rhs) const;
495
+ bool operator==(const Complex_Selector& rhs) const;
496
+ bool operator<(const Compound_Selector& rhs) const;
497
+ bool operator==(const Compound_Selector& rhs) const;
498
+ bool operator<(const Simple_Selector& rhs) const;
499
+ bool operator==(const Simple_Selector& rhs) const;
500
+
501
+ const ComplexSelectorSet sources();
502
+ void addSources(ComplexSelectorSet& sources);
503
+ void clearSources();
504
+
505
+ void cloneChildren() override;
506
+ ATTACH_AST_OPERATIONS(Complex_Selector)
507
+ ATTACH_CRTP_PERFORM_METHODS()
508
+ };
509
+
510
+ ///////////////////////////////////
511
+ // Comma-separated selector groups.
512
+ ///////////////////////////////////
513
+ class Selector_List final : public Selector, public Vectorized<Complex_Selector_Obj> {
514
+ ADD_PROPERTY(Selector_Schema_Obj, schema)
515
+ ADD_CONSTREF(std::vector<std::string>, wspace)
516
+ protected:
517
+ void adjust_after_pushing(Complex_Selector_Obj c) override;
518
+ public:
519
+ Selector_List(ParserState pstate, size_t s = 0);
520
+ std::string type() const override { return "list"; }
521
+ // remove parent selector references
522
+ // basically unwraps parsed selectors
523
+ bool has_parent_ref() const override;
524
+ bool has_real_parent_ref() const override;
525
+ void remove_parent_selectors();
526
+ Selector_List* resolve_parent_refs(SelectorStack& pstack, Backtraces& traces, bool implicit_parent = true);
527
+ bool is_superselector_of(const Compound_Selector* sub, std::string wrapping = "") const;
528
+ bool is_superselector_of(const Complex_Selector* sub, std::string wrapping = "") const;
529
+ bool is_superselector_of(const Selector_List* sub, std::string wrapping = "") const;
530
+ Selector_List* unify_with(Selector_List*);
531
+ void populate_extends(Selector_List_Obj, Subset_Map&);
532
+ Selector_List_Obj eval(Eval& eval);
533
+
534
+ size_t hash() const override;
535
+ virtual unsigned long specificity() const override;
536
+ virtual void set_media_block(Media_Block* mb) override;
537
+ virtual bool has_placeholder();
538
+ int unification_order() const override
539
+ {
540
+ throw std::runtime_error("unification_order for Selector_List is undefined");
541
+ }
542
+ bool find ( bool (*f)(AST_Node_Obj) ) override;
543
+ bool operator<(const Selector& rhs) const override;
544
+ bool operator==(const Selector& rhs) const override;
545
+ bool operator<(const Selector_List& rhs) const;
546
+ bool operator==(const Selector_List& rhs) const;
547
+ bool operator<(const Complex_Selector& rhs) const;
548
+ bool operator==(const Complex_Selector& rhs) const;
549
+ bool operator<(const Compound_Selector& rhs) const;
550
+ bool operator==(const Compound_Selector& rhs) const;
551
+ bool operator<(const Simple_Selector& rhs) const;
552
+ bool operator==(const Simple_Selector& rhs) const;
553
+ // Selector Lists can be compared to comma lists
554
+ bool operator<(const Expression& rhs) const override;
555
+ bool operator==(const Expression& rhs) const override;
556
+ void cloneChildren() override;
557
+ ATTACH_AST_OPERATIONS(Selector_List)
558
+ ATTACH_CRTP_PERFORM_METHODS()
559
+ };
560
+
561
+ // compare function for sorting and probably other other uses
562
+ struct cmp_complex_selector { inline bool operator() (const Complex_Selector_Obj l, const Complex_Selector_Obj r) { return (*l < *r); } };
563
+ struct cmp_compound_selector { inline bool operator() (const Compound_Selector_Obj l, const Compound_Selector_Obj r) { return (*l < *r); } };
564
+ struct cmp_simple_selector { inline bool operator() (const Simple_Selector_Obj l, const Simple_Selector_Obj r) { return (*l < *r); } };
565
+
566
+ }
567
+
568
+ #endif