sassc 2.2.1 → 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 (147) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +18 -0
  4. data/Rakefile +1 -3
  5. data/ext/extconf.rb +13 -5
  6. data/ext/libsass/VERSION +1 -1
  7. data/ext/libsass/include/sass/base.h +2 -1
  8. data/ext/libsass/include/sass/context.h +4 -0
  9. data/ext/libsass/src/MurmurHash2.hpp +91 -0
  10. data/ext/libsass/src/ast.cpp +158 -168
  11. data/ext/libsass/src/ast.hpp +389 -230
  12. data/ext/libsass/src/ast_def_macros.hpp +18 -10
  13. data/ext/libsass/src/ast_fwd_decl.cpp +4 -3
  14. data/ext/libsass/src/ast_fwd_decl.hpp +98 -165
  15. data/ext/libsass/src/ast_helpers.hpp +292 -0
  16. data/ext/libsass/src/ast_sel_cmp.cpp +219 -732
  17. data/ext/libsass/src/ast_sel_super.cpp +539 -0
  18. data/ext/libsass/src/ast_sel_unify.cpp +207 -212
  19. data/ext/libsass/src/ast_sel_weave.cpp +616 -0
  20. data/ext/libsass/src/ast_selectors.cpp +594 -1026
  21. data/ext/libsass/src/ast_selectors.hpp +339 -385
  22. data/ext/libsass/src/ast_supports.cpp +36 -52
  23. data/ext/libsass/src/ast_supports.hpp +29 -29
  24. data/ext/libsass/src/ast_values.cpp +271 -84
  25. data/ext/libsass/src/ast_values.hpp +116 -107
  26. data/ext/libsass/src/backtrace.cpp +9 -9
  27. data/ext/libsass/src/backtrace.hpp +5 -5
  28. data/ext/libsass/src/base64vlq.cpp +2 -2
  29. data/ext/libsass/src/base64vlq.hpp +1 -1
  30. data/ext/libsass/src/bind.cpp +18 -18
  31. data/ext/libsass/src/bind.hpp +1 -1
  32. data/ext/libsass/src/c2ast.cpp +3 -3
  33. data/ext/libsass/src/c2ast.hpp +1 -1
  34. data/ext/libsass/src/cencode.c +4 -6
  35. data/ext/libsass/src/check_nesting.cpp +40 -41
  36. data/ext/libsass/src/check_nesting.hpp +6 -2
  37. data/ext/libsass/src/color_maps.cpp +14 -13
  38. data/ext/libsass/src/color_maps.hpp +1 -9
  39. data/ext/libsass/src/constants.cpp +5 -0
  40. data/ext/libsass/src/constants.hpp +6 -0
  41. data/ext/libsass/src/context.cpp +92 -119
  42. data/ext/libsass/src/context.hpp +41 -53
  43. data/ext/libsass/src/cssize.cpp +66 -149
  44. data/ext/libsass/src/cssize.hpp +17 -23
  45. data/ext/libsass/src/dart_helpers.hpp +199 -0
  46. data/ext/libsass/src/debugger.hpp +451 -295
  47. data/ext/libsass/src/emitter.cpp +15 -16
  48. data/ext/libsass/src/emitter.hpp +10 -12
  49. data/ext/libsass/src/environment.cpp +27 -27
  50. data/ext/libsass/src/environment.hpp +29 -24
  51. data/ext/libsass/src/error_handling.cpp +62 -41
  52. data/ext/libsass/src/error_handling.hpp +61 -51
  53. data/ext/libsass/src/eval.cpp +167 -281
  54. data/ext/libsass/src/eval.hpp +27 -29
  55. data/ext/libsass/src/eval_selectors.cpp +75 -0
  56. data/ext/libsass/src/expand.cpp +275 -222
  57. data/ext/libsass/src/expand.hpp +36 -16
  58. data/ext/libsass/src/extender.cpp +1188 -0
  59. data/ext/libsass/src/extender.hpp +399 -0
  60. data/ext/libsass/src/extension.cpp +43 -0
  61. data/ext/libsass/src/extension.hpp +89 -0
  62. data/ext/libsass/src/file.cpp +81 -72
  63. data/ext/libsass/src/file.hpp +28 -37
  64. data/ext/libsass/src/fn_colors.cpp +20 -18
  65. data/ext/libsass/src/fn_lists.cpp +30 -29
  66. data/ext/libsass/src/fn_maps.cpp +3 -3
  67. data/ext/libsass/src/fn_miscs.cpp +34 -46
  68. data/ext/libsass/src/fn_numbers.cpp +20 -13
  69. data/ext/libsass/src/fn_selectors.cpp +98 -128
  70. data/ext/libsass/src/fn_strings.cpp +47 -33
  71. data/ext/libsass/src/fn_utils.cpp +31 -29
  72. data/ext/libsass/src/fn_utils.hpp +17 -11
  73. data/ext/libsass/src/inspect.cpp +186 -148
  74. data/ext/libsass/src/inspect.hpp +31 -29
  75. data/ext/libsass/src/lexer.cpp +20 -82
  76. data/ext/libsass/src/lexer.hpp +5 -16
  77. data/ext/libsass/src/listize.cpp +23 -37
  78. data/ext/libsass/src/listize.hpp +8 -9
  79. data/ext/libsass/src/mapping.hpp +1 -0
  80. data/ext/libsass/src/memory/allocator.cpp +48 -0
  81. data/ext/libsass/src/memory/allocator.hpp +138 -0
  82. data/ext/libsass/src/memory/config.hpp +20 -0
  83. data/ext/libsass/src/memory/memory_pool.hpp +186 -0
  84. data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
  85. data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
  86. data/ext/libsass/src/memory.hpp +12 -0
  87. data/ext/libsass/src/operation.hpp +71 -61
  88. data/ext/libsass/src/operators.cpp +19 -18
  89. data/ext/libsass/src/operators.hpp +11 -11
  90. data/ext/libsass/src/ordered_map.hpp +112 -0
  91. data/ext/libsass/src/output.cpp +45 -64
  92. data/ext/libsass/src/output.hpp +6 -6
  93. data/ext/libsass/src/parser.cpp +512 -700
  94. data/ext/libsass/src/parser.hpp +89 -97
  95. data/ext/libsass/src/parser_selectors.cpp +189 -0
  96. data/ext/libsass/src/permutate.hpp +164 -0
  97. data/ext/libsass/src/plugins.cpp +7 -7
  98. data/ext/libsass/src/plugins.hpp +8 -8
  99. data/ext/libsass/src/position.cpp +7 -26
  100. data/ext/libsass/src/position.hpp +44 -21
  101. data/ext/libsass/src/prelexer.cpp +6 -6
  102. data/ext/libsass/src/remove_placeholders.cpp +55 -56
  103. data/ext/libsass/src/remove_placeholders.hpp +21 -18
  104. data/ext/libsass/src/sass.cpp +16 -15
  105. data/ext/libsass/src/sass.hpp +10 -5
  106. data/ext/libsass/src/sass2scss.cpp +4 -4
  107. data/ext/libsass/src/sass_context.cpp +91 -122
  108. data/ext/libsass/src/sass_context.hpp +2 -2
  109. data/ext/libsass/src/sass_functions.cpp +1 -1
  110. data/ext/libsass/src/sass_values.cpp +8 -11
  111. data/ext/libsass/src/settings.hpp +19 -0
  112. data/ext/libsass/src/source.cpp +69 -0
  113. data/ext/libsass/src/source.hpp +95 -0
  114. data/ext/libsass/src/source_data.hpp +32 -0
  115. data/ext/libsass/src/source_map.cpp +22 -18
  116. data/ext/libsass/src/source_map.hpp +12 -9
  117. data/ext/libsass/src/stylesheet.cpp +22 -0
  118. data/ext/libsass/src/stylesheet.hpp +57 -0
  119. data/ext/libsass/src/to_value.cpp +2 -2
  120. data/ext/libsass/src/to_value.hpp +1 -1
  121. data/ext/libsass/src/units.cpp +24 -22
  122. data/ext/libsass/src/units.hpp +8 -8
  123. data/ext/libsass/src/utf8_string.cpp +9 -10
  124. data/ext/libsass/src/utf8_string.hpp +7 -6
  125. data/ext/libsass/src/util.cpp +48 -50
  126. data/ext/libsass/src/util.hpp +20 -21
  127. data/ext/libsass/src/util_string.cpp +111 -61
  128. data/ext/libsass/src/util_string.hpp +62 -8
  129. data/ext/libsass/src/values.cpp +12 -12
  130. data/lib/sassc/engine.rb +5 -3
  131. data/lib/sassc/functions_handler.rb +8 -8
  132. data/lib/sassc/native.rb +4 -6
  133. data/lib/sassc/script.rb +4 -4
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/functions_test.rb +18 -1
  136. data/test/native_test.rb +4 -4
  137. metadata +29 -15
  138. data/ext/libsass/src/extend.cpp +0 -2132
  139. data/ext/libsass/src/extend.hpp +0 -86
  140. data/ext/libsass/src/node.cpp +0 -322
  141. data/ext/libsass/src/node.hpp +0 -118
  142. data/ext/libsass/src/paths.hpp +0 -71
  143. data/ext/libsass/src/sass_util.cpp +0 -152
  144. data/ext/libsass/src/sass_util.hpp +0 -256
  145. data/ext/libsass/src/subset_map.cpp +0 -58
  146. data/ext/libsass/src/subset_map.hpp +0 -76
  147. data/lib/sassc/native/lib_c.rb +0 -21
@@ -44,18 +44,18 @@ namespace Sass {
44
44
  if (!strcmp(our_version, "[na]")) return false;
45
45
 
46
46
  // find the position of the second dot
47
- size_t pos = std::string(our_version).find('.', 0);
48
- if (pos != std::string::npos) pos = std::string(our_version).find('.', pos + 1);
47
+ size_t pos = sass::string(our_version).find('.', 0);
48
+ if (pos != sass::string::npos) pos = sass::string(our_version).find('.', pos + 1);
49
49
 
50
50
  // if we do not have two dots we fallback to compare complete string
51
- if (pos == std::string::npos) { return strcmp(their_version, our_version) ? 0 : 1; }
51
+ if (pos == sass::string::npos) { return strcmp(their_version, our_version) ? 0 : 1; }
52
52
  // otherwise only compare up to the second dot (major versions)
53
53
  else { return strncmp(their_version, our_version, pos) ? 0 : 1; }
54
54
 
55
55
  }
56
56
 
57
57
  // load one specific plugin
58
- bool Plugins::load_plugin (const std::string& path)
58
+ bool Plugins::load_plugin (const sass::string& path)
59
59
  {
60
60
 
61
61
  typedef const char* (*__plugin_version__)(void);
@@ -112,7 +112,7 @@ namespace Sass {
112
112
 
113
113
  }
114
114
 
115
- size_t Plugins::load_plugins(const std::string& path)
115
+ size_t Plugins::load_plugins(const sass::string& path)
116
116
  {
117
117
 
118
118
  // count plugins
@@ -126,7 +126,7 @@ namespace Sass {
126
126
  // use wchar (utf16)
127
127
  WIN32_FIND_DATAW data;
128
128
  // trailing slash is guaranteed
129
- std::string globsrch(path + "*.dll");
129
+ sass::string globsrch(path + "*.dll");
130
130
  // convert to wide chars (utf16) for system call
131
131
  std::wstring wglobsrch(UTF_8::convert_to_utf16(globsrch));
132
132
  HANDLE hFile = FindFirstFileW(wglobsrch.c_str(), &data);
@@ -140,7 +140,7 @@ namespace Sass {
140
140
  try
141
141
  {
142
142
  // the system will report the filenames with wide chars (utf16)
143
- std::string entry = UTF_8::convert_from_utf16(data.cFileName);
143
+ sass::string entry = UTF_8::convert_from_utf16(data.cFileName);
144
144
  // check if file ending matches exactly
145
145
  if (!ends_with(entry, ".dll")) continue;
146
146
  // load the plugin and increase counter
@@ -36,19 +36,19 @@ namespace Sass {
36
36
 
37
37
  public: // methods
38
38
  // load one specific plugin
39
- bool load_plugin(const std::string& path);
39
+ bool load_plugin(const sass::string& path);
40
40
  // load all plugins from a directory
41
- size_t load_plugins(const std::string& path);
41
+ size_t load_plugins(const sass::string& path);
42
42
 
43
43
  public: // public accessors
44
- const std::vector<Sass_Importer_Entry> get_headers(void) { return headers; }
45
- const std::vector<Sass_Importer_Entry> get_importers(void) { return importers; }
46
- const std::vector<Sass_Function_Entry> get_functions(void) { return functions; }
44
+ const sass::vector<Sass_Importer_Entry> get_headers(void) { return headers; }
45
+ const sass::vector<Sass_Importer_Entry> get_importers(void) { return importers; }
46
+ const sass::vector<Sass_Function_Entry> get_functions(void) { return functions; }
47
47
 
48
48
  private: // private vars
49
- std::vector<Sass_Importer_Entry> headers;
50
- std::vector<Sass_Importer_Entry> importers;
51
- std::vector<Sass_Function_Entry> functions;
49
+ sass::vector<Sass_Importer_Entry> headers;
50
+ sass::vector<Sass_Importer_Entry> importers;
51
+ sass::vector<Sass_Function_Entry> functions;
52
52
 
53
53
  };
54
54
 
@@ -3,6 +3,7 @@
3
3
  #include "sass.hpp"
4
4
 
5
5
  #include "position.hpp"
6
+ #include "source.hpp"
6
7
 
7
8
  namespace Sass {
8
9
 
@@ -18,7 +19,7 @@ namespace Sass {
18
19
  *this = inc(string, string + strlen(string));
19
20
  }
20
21
 
21
- Offset::Offset(const std::string& text)
22
+ Offset::Offset(const sass::string& text)
22
23
  : line(0), column(0)
23
24
  {
24
25
  *this = inc(text.c_str(), text.c_str() + text.size());
@@ -56,7 +57,7 @@ namespace Sass {
56
57
  // skip over 10xxxxxx
57
58
  // is 1st bit not set
58
59
  if ((chr & 128) == 0) {
59
- // regular ascii char
60
+ // regular ASCII char
60
61
  column += 1;
61
62
  }
62
63
  // is 2nd bit not set
@@ -117,14 +118,11 @@ namespace Sass {
117
118
  : Offset(line, column), file(file) { }
118
119
 
119
120
 
120
- ParserState::ParserState(const char* path, const char* src, const size_t file)
121
- : Position(file, 0, 0), path(path), src(src), offset(0, 0), token() { }
121
+ SourceSpan::SourceSpan(const char* path)
122
+ : source(SASS_MEMORY_NEW(SynthFile, path)), position(0, 0), offset(0, 0) { }
122
123
 
123
- ParserState::ParserState(const char* path, const char* src, const Position& position, Offset offset)
124
- : Position(position), path(path), src(src), offset(offset), token() { }
125
-
126
- ParserState::ParserState(const char* path, const char* src, const Token& token, const Position& position, Offset offset)
127
- : Position(position), path(path), src(src), offset(offset), token(token) { }
124
+ SourceSpan::SourceSpan(SourceDataObj source, const Offset& position, const Offset& offset)
125
+ : source(source), position(position), offset(offset) { }
128
126
 
129
127
  Position Position::add(const char* begin, const char* end)
130
128
  {
@@ -164,21 +162,4 @@ namespace Sass {
164
162
  return Offset(line - off.line, off.line == line ? column - off.column : column);
165
163
  }
166
164
 
167
- /* not used anymore - remove?
168
- std::ostream& operator<<(std::ostream& strm, const Offset& off)
169
- {
170
- if (off.line == string::npos) strm << "-1:"; else strm << off.line << ":";
171
- if (off.column == string::npos) strm << "-1"; else strm << off.column;
172
- return strm;
173
- } */
174
-
175
- /* not used anymore - remove?
176
- std::ostream& operator<<(std::ostream& strm, const Position& pos)
177
- {
178
- if (pos.file != string::npos) strm << pos.file << ":";
179
- if (pos.line == string::npos) strm << "-1:"; else strm << pos.line << ":";
180
- if (pos.column == string::npos) strm << "-1"; else strm << pos.column;
181
- return strm;
182
- } */
183
-
184
165
  }
@@ -3,7 +3,8 @@
3
3
 
4
4
  #include <string>
5
5
  #include <cstring>
6
- // #include <iostream>
6
+ #include "source_data.hpp"
7
+ #include "ast_fwd_decl.hpp"
7
8
 
8
9
  namespace Sass {
9
10
 
@@ -13,7 +14,7 @@ namespace Sass {
13
14
  public: // c-tor
14
15
  Offset(const char chr);
15
16
  Offset(const char* string);
16
- Offset(const std::string& text);
17
+ Offset(const sass::string& text);
17
18
  Offset(const size_t line, const size_t column);
18
19
 
19
20
  // return new position, incremented by the given string
@@ -85,37 +86,59 @@ namespace Sass {
85
86
  : prefix(p), begin(b), end(e) { }
86
87
 
87
88
  size_t length() const { return end - begin; }
88
- std::string ws_before() const { return std::string(prefix, begin); }
89
- const std::string to_string() const { return std::string(begin, end); }
90
- std::string time_wspace() const {
91
- std::string str(to_string());
92
- std::string whitespaces(" \t\f\v\n\r");
89
+ sass::string ws_before() const { return sass::string(prefix, begin); }
90
+ sass::string to_string() const { return sass::string(begin, end); }
91
+ sass::string time_wspace() const {
92
+ sass::string str(to_string());
93
+ sass::string whitespaces(" \t\f\v\n\r");
93
94
  return str.erase(str.find_last_not_of(whitespaces)+1);
94
95
  }
95
96
 
96
97
  operator bool() { return begin && end && begin >= end; }
97
- operator std::string() { return to_string(); }
98
+ operator sass::string() { return to_string(); }
98
99
 
99
100
  bool operator==(Token t) { return to_string() == t.to_string(); }
100
101
  };
101
102
 
102
- class ParserState : public Position {
103
+ class SourceSpan {
103
104
 
104
- public: // c-tor
105
- ParserState(const char* path, const char* src = 0, const size_t file = std::string::npos);
106
- ParserState(const char* path, const char* src, const Position& position, Offset offset = Offset(0, 0));
107
- ParserState(const char* path, const char* src, const Token& token, const Position& position, Offset offset = Offset(0, 0));
105
+ public:
108
106
 
109
- public: // down casts
110
- Offset off() { return *this; }
111
- Position pos() { return *this; }
112
- ParserState pstate() { return *this; }
107
+ SourceSpan(const char* path);
113
108
 
114
- public:
115
- const char* path;
116
- const char* src;
109
+ SourceSpan(SourceDataObj source,
110
+ const Offset& position = Offset(0, 0),
111
+ const Offset& offset = Offset(0, 0));
112
+
113
+ const char* getPath() const {
114
+ return source->getPath();
115
+ }
116
+
117
+ const char* getRawData() const {
118
+ return source->getRawData();
119
+ }
120
+
121
+ Offset getPosition() const {
122
+ return position;
123
+ }
124
+
125
+ size_t getLine() const {
126
+ return position.line + 1;
127
+ }
128
+
129
+ size_t getColumn() const {
130
+ return position.column + 1;
131
+ }
132
+
133
+ size_t getSrcId() const {
134
+ return source == nullptr
135
+ ? std::string::npos
136
+ : source->getSrcId();
137
+ }
138
+
139
+ SourceDataObj source;
140
+ Offset position;
117
141
  Offset offset;
118
- Token token;
119
142
 
120
143
  };
121
144
 
@@ -2,10 +2,10 @@
2
2
  // __EXTENSIONS__ fix on Solaris.
3
3
  #include "sass.hpp"
4
4
 
5
- #include <cctype>
6
5
  #include <iostream>
7
6
  #include <iomanip>
8
7
  #include "util.hpp"
8
+ #include "util_string.hpp"
9
9
  #include "position.hpp"
10
10
  #include "prelexer.hpp"
11
11
  #include "constants.hpp"
@@ -336,7 +336,7 @@ namespace Sass {
336
336
  return alternatives<
337
337
  unicode_seq,
338
338
  alpha,
339
- unicode,
339
+ nonascii,
340
340
  exactly<'-'>,
341
341
  exactly<'_'>,
342
342
  NONASCII,
@@ -351,7 +351,7 @@ namespace Sass {
351
351
  return alternatives<
352
352
  unicode_seq,
353
353
  alnum,
354
- unicode,
354
+ nonascii,
355
355
  exactly<'-'>,
356
356
  exactly<'_'>,
357
357
  NONASCII,
@@ -385,7 +385,7 @@ namespace Sass {
385
385
  {
386
386
  return alternatives <
387
387
  alpha,
388
- unicode,
388
+ nonascii,
389
389
  escape_seq,
390
390
  exactly<'_'>
391
391
  >(src);
@@ -395,7 +395,7 @@ namespace Sass {
395
395
  {
396
396
  return alternatives <
397
397
  alnum,
398
- unicode,
398
+ nonascii,
399
399
  escape_seq,
400
400
  exactly<'_'>
401
401
  >(src);
@@ -1400,7 +1400,7 @@ namespace Sass {
1400
1400
  }*/
1401
1401
 
1402
1402
  const char* H(const char* src) {
1403
- return std::isxdigit(static_cast<unsigned char>(*src)) ? src+1 : 0;
1403
+ return Util::ascii_isxdigit(static_cast<unsigned char>(*src)) ? src+1 : 0;
1404
1404
  }
1405
1405
 
1406
1406
  const char* W(const char* src) {
@@ -1,11 +1,9 @@
1
1
  // sass.hpp must go before all system headers to get the
2
2
  // __EXTENSIONS__ fix on Solaris.
3
3
  #include "sass.hpp"
4
+ #include "ast.hpp"
4
5
 
5
6
  #include "remove_placeholders.hpp"
6
- #include "context.hpp"
7
- #include "inspect.hpp"
8
- #include <iostream>
9
7
 
10
8
  namespace Sass {
11
9
 
@@ -13,75 +11,76 @@ namespace Sass {
13
11
  { }
14
12
 
15
13
  void Remove_Placeholders::operator()(Block* b) {
16
- for (size_t i = 0, L = b->length(); i < L; ++i) {
17
- Statement* st = b->at(i);
18
- st->perform(this);
19
- }
14
+ for (size_t i = 0, L = b->length(); i < L; ++i) {
15
+ if (b->get(i)) b->get(i)->perform(this);
16
+ }
20
17
  }
21
18
 
22
- Selector_List* Remove_Placeholders::remove_placeholders(Selector_List* sl)
19
+ void Remove_Placeholders::remove_placeholders(SimpleSelector* simple)
23
20
  {
24
- Selector_List* new_sl = SASS_MEMORY_NEW(Selector_List, sl->pstate());
25
-
26
- for (size_t i = 0, L = sl->length(); i < L; ++i) {
27
- if (!sl->at(i)->contains_placeholder()) {
28
- new_sl->append(sl->at(i));
29
- }
21
+ if (PseudoSelector * pseudo = simple->getPseudoSelector()) {
22
+ if (pseudo->selector()) remove_placeholders(pseudo->selector());
30
23
  }
31
-
32
- return new_sl;
33
-
34
24
  }
35
25
 
26
+ void Remove_Placeholders::remove_placeholders(CompoundSelector* compound)
27
+ {
28
+ for (size_t i = 0, L = compound->length(); i < L; ++i) {
29
+ if (compound->get(i)) remove_placeholders(compound->get(i));
30
+ }
31
+ listEraseItemIf(compound->elements(), listIsEmpty<SimpleSelector>);
32
+ }
36
33
 
37
- void Remove_Placeholders::operator()(Ruleset* r) {
38
- // Create a new selector group without placeholders
39
- Selector_List_Obj sl = Cast<Selector_List>(r->selector());
40
-
41
- if (sl) {
42
- // Set the new placeholder selector list
43
- r->selector(remove_placeholders(sl));
44
- // Remove placeholders in wrapped selectors
45
- for (Complex_Selector_Obj cs : sl->elements()) {
46
- while (cs) {
47
- if (cs->head()) {
48
- for (Simple_Selector_Obj& ss : cs->head()->elements()) {
49
- if (Wrapped_Selector* ws = Cast<Wrapped_Selector>(ss)) {
50
- if (Selector_List* wsl = Cast<Selector_List>(ws->selector())) {
51
- Selector_List* clean = remove_placeholders(wsl);
52
- // also clean superflous parent selectors
53
- // probably not really the correct place
54
- clean->remove_parent_selectors();
55
- ws->selector(clean);
56
- }
57
- }
58
- }
59
- }
60
- cs = cs->tail();
61
- }
34
+ void Remove_Placeholders::remove_placeholders(ComplexSelector* complex)
35
+ {
36
+ if (complex->has_placeholder()) {
37
+ complex->clear(); // remove all
38
+ }
39
+ else {
40
+ for (size_t i = 0, L = complex->length(); i < L; ++i) {
41
+ if (CompoundSelector * compound = complex->get(i)->getCompound()) {
42
+ if (compound) remove_placeholders(compound);
62
43
  }
63
44
  }
45
+ listEraseItemIf(complex->elements(), listIsEmpty<SelectorComponent>);
46
+ }
47
+ }
64
48
 
65
- // Iterate into child blocks
66
- Block_Obj b = r->block();
49
+ SelectorList* Remove_Placeholders::remove_placeholders(SelectorList* sl)
50
+ {
51
+ for (size_t i = 0, L = sl->length(); i < L; ++i) {
52
+ if (sl->get(i)) remove_placeholders(sl->get(i));
53
+ }
54
+ listEraseItemIf(sl->elements(), listIsEmpty<ComplexSelector>);
55
+ return sl;
56
+ }
67
57
 
68
- for (size_t i = 0, L = b->length(); i < L; ++i) {
69
- if (b->at(i)) {
70
- Statement_Obj st = b->at(i);
71
- st->perform(this);
72
- }
73
- }
58
+ void Remove_Placeholders::operator()(CssMediaRule* rule)
59
+ {
60
+ if (rule->block()) operator()(rule->block());
74
61
  }
75
62
 
76
- void Remove_Placeholders::operator()(Media_Block* m) {
77
- operator()(m->block());
63
+ void Remove_Placeholders::operator()(StyleRule* r)
64
+ {
65
+ if (SelectorListObj sl = r->selector()) {
66
+ // Set the new placeholder selector list
67
+ r->selector((remove_placeholders(sl)));
68
+ }
69
+ // Iterate into child blocks
70
+ Block_Obj b = r->block();
71
+ for (size_t i = 0, L = b->length(); i < L; ++i) {
72
+ if (b->get(i)) { b->get(i)->perform(this); }
73
+ }
78
74
  }
79
- void Remove_Placeholders::operator()(Supports_Block* m) {
80
- operator()(m->block());
75
+
76
+ void Remove_Placeholders::operator()(SupportsRule* m)
77
+ {
78
+ if (m->block()) operator()(m->block());
81
79
  }
82
80
 
83
- void Remove_Placeholders::operator()(Directive* a) {
84
- if (a->block()) a->block()->perform(this);
81
+ void Remove_Placeholders::operator()(AtRule* a)
82
+ {
83
+ if (a->block()) a->block()->perform(this);
85
84
  }
86
85
 
87
86
  }
@@ -1,33 +1,36 @@
1
1
  #ifndef SASS_REMOVE_PLACEHOLDERS_H
2
2
  #define SASS_REMOVE_PLACEHOLDERS_H
3
3
 
4
- #pragma once
5
-
6
- #include "ast.hpp"
4
+ #include "ast_fwd_decl.hpp"
7
5
  #include "operation.hpp"
8
6
 
9
7
  namespace Sass {
10
8
 
9
+ class Remove_Placeholders : public Operation_CRTP<void, Remove_Placeholders> {
10
+
11
+ public:
12
+
13
+ SelectorList* remove_placeholders(SelectorList*);
14
+ void remove_placeholders(SimpleSelector* simple);
15
+ void remove_placeholders(CompoundSelector* complex);
16
+ void remove_placeholders(ComplexSelector* complex);
11
17
 
12
- class Remove_Placeholders : public Operation_CRTP<void, Remove_Placeholders> {
13
18
 
14
- public:
15
- Selector_List* remove_placeholders(Selector_List*);
19
+ public:
20
+ Remove_Placeholders();
21
+ ~Remove_Placeholders() { }
16
22
 
17
- public:
18
- Remove_Placeholders();
19
- ~Remove_Placeholders() { }
23
+ void operator()(Block*);
24
+ void operator()(StyleRule*);
25
+ void operator()(CssMediaRule*);
26
+ void operator()(SupportsRule*);
27
+ void operator()(AtRule*);
20
28
 
21
- void operator()(Block*);
22
- void operator()(Ruleset*);
23
- void operator()(Media_Block*);
24
- void operator()(Supports_Block*);
25
- void operator()(Directive*);
29
+ // ignore missed types
30
+ template <typename U>
31
+ void fallback(U x) {}
26
32
 
27
- // ignore missed types
28
- template <typename U>
29
- void fallback(U x) {}
30
- };
33
+ };
31
34
 
32
35
  }
33
36
 
@@ -17,9 +17,9 @@
17
17
  namespace Sass {
18
18
 
19
19
  // helper to convert string list to vector
20
- std::vector<std::string> list2vec(struct string_list* cur)
20
+ sass::vector<sass::string> list2vec(struct string_list* cur)
21
21
  {
22
- std::vector<std::string> list;
22
+ sass::vector<sass::string> list;
23
23
  while (cur) {
24
24
  list.push_back(cur->string);
25
25
  cur = cur->next;
@@ -46,6 +46,7 @@ extern "C" {
46
46
 
47
47
  char* ADDCALL sass_copy_c_string(const char* str)
48
48
  {
49
+ if (str == nullptr) return nullptr;
49
50
  size_t len = strlen(str) + 1;
50
51
  char* cpy = (char*) sass_alloc_memory(len);
51
52
  std::memcpy(cpy, str, len);
@@ -61,14 +62,14 @@ extern "C" {
61
62
  // caller must free the returned memory
62
63
  char* ADDCALL sass_string_quote (const char *str, const char quote_mark)
63
64
  {
64
- std::string quoted = quote(str, quote_mark);
65
+ sass::string quoted = quote(str, quote_mark);
65
66
  return sass_copy_c_string(quoted.c_str());
66
67
  }
67
68
 
68
69
  // caller must free the returned memory
69
70
  char* ADDCALL sass_string_unquote (const char *str)
70
71
  {
71
- std::string unquoted = unquote(str);
72
+ sass::string unquoted = unquote(str);
72
73
  return sass_copy_c_string(unquoted.c_str());
73
74
  }
74
75
 
@@ -76,13 +77,13 @@ extern "C" {
76
77
  {
77
78
  // get the last import entry to get current base directory
78
79
  Sass_Import_Entry import = sass_compiler_get_last_import(compiler);
79
- const std::vector<std::string>& incs = compiler->cpp_ctx->include_paths;
80
+ const sass::vector<sass::string>& incs = compiler->cpp_ctx->include_paths;
80
81
  // create the vector with paths to lookup
81
- std::vector<std::string> paths(1 + incs.size());
82
+ sass::vector<sass::string> paths(1 + incs.size());
82
83
  paths.push_back(File::dir_name(import->abs_path));
83
84
  paths.insert( paths.end(), incs.begin(), incs.end() );
84
85
  // now resolve the file path relative to lookup paths
85
- std::string resolved(File::find_include(file, paths));
86
+ sass::string resolved(File::find_include(file, paths));
86
87
  return sass_copy_c_string(resolved.c_str());
87
88
  }
88
89
 
@@ -90,13 +91,13 @@ extern "C" {
90
91
  {
91
92
  // get the last import entry to get current base directory
92
93
  Sass_Import_Entry import = sass_compiler_get_last_import(compiler);
93
- const std::vector<std::string>& incs = compiler->cpp_ctx->include_paths;
94
+ const sass::vector<sass::string>& incs = compiler->cpp_ctx->include_paths;
94
95
  // create the vector with paths to lookup
95
- std::vector<std::string> paths(1 + incs.size());
96
+ sass::vector<sass::string> paths(1 + incs.size());
96
97
  paths.push_back(File::dir_name(import->abs_path));
97
98
  paths.insert( paths.end(), incs.begin(), incs.end() );
98
99
  // now resolve the file path relative to lookup paths
99
- std::string resolved(File::find_file(file, paths));
100
+ sass::string resolved(File::find_file(file, paths));
100
101
  return sass_copy_c_string(resolved.c_str());
101
102
  }
102
103
 
@@ -105,8 +106,8 @@ extern "C" {
105
106
  // this has the original resolve logic for sass include
106
107
  char* ADDCALL sass_find_include (const char* file, struct Sass_Options* opt)
107
108
  {
108
- std::vector<std::string> vec(list2vec(opt->include_paths));
109
- std::string resolved(File::find_include(file, vec));
109
+ sass::vector<sass::string> vec(list2vec(opt->include_paths));
110
+ sass::string resolved(File::find_include(file, vec));
110
111
  return sass_copy_c_string(resolved.c_str());
111
112
  }
112
113
 
@@ -114,8 +115,8 @@ extern "C" {
114
115
  // Incs array has to be null terminated!
115
116
  char* ADDCALL sass_find_file (const char* file, struct Sass_Options* opt)
116
117
  {
117
- std::vector<std::string> vec(list2vec(opt->include_paths));
118
- std::string resolved(File::find_file(file, vec));
118
+ sass::vector<sass::string> vec(list2vec(opt->include_paths));
119
+ sass::string resolved(File::find_file(file, vec));
119
120
  return sass_copy_c_string(resolved.c_str());
120
121
  }
121
122
 
@@ -136,7 +137,7 @@ extern "C" {
136
137
  namespace Sass {
137
138
 
138
139
  // helper to aid dreaded MSVC debug mode
139
- char* sass_copy_string(std::string str)
140
+ char* sass_copy_string(sass::string str)
140
141
  {
141
142
  // In MSVC the following can lead to segfault:
142
143
  // sass_copy_c_string(stream.str().c_str());
@@ -11,7 +11,7 @@
11
11
  #pragma warning(disable : 4005)
12
12
  #endif
13
13
 
14
- // aplies to MSVC and MinGW
14
+ // applies to MSVC and MinGW
15
15
  #ifdef _WIN32
16
16
  // we do not want the ERROR macro
17
17
  # ifndef NOGDI
@@ -48,13 +48,17 @@
48
48
  #endif
49
49
 
50
50
 
51
- // include C-API header
51
+ // Include C-API header
52
52
  #include "sass/base.h"
53
53
 
54
+ // Include allocator
55
+ #include "memory.hpp"
56
+
54
57
  // For C++ helper
55
58
  #include <string>
59
+ #include <vector>
56
60
 
57
- // output behaviours
61
+ // output behavior
58
62
  namespace Sass {
59
63
 
60
64
  // create some C++ aliases for the most used options
@@ -65,14 +69,15 @@ namespace Sass {
65
69
  // only used internal to trigger ruby inspect behavior
66
70
  const static Sass_Output_Style INSPECT = SASS_STYLE_INSPECT;
67
71
  const static Sass_Output_Style TO_SASS = SASS_STYLE_TO_SASS;
72
+ const static Sass_Output_Style TO_CSS = SASS_STYLE_TO_CSS;
68
73
 
69
74
  // helper to aid dreaded MSVC debug mode
70
75
  // see implementation for more details
71
- char* sass_copy_string(std::string str);
76
+ char* sass_copy_string(sass::string str);
72
77
 
73
78
  }
74
79
 
75
- // input behaviours
80
+ // input behaviors
76
81
  enum Sass_Input_Style {
77
82
  SASS_CONTEXT_NULL,
78
83
  SASS_CONTEXT_FILE,