sassc 1.7.1 → 1.8.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/ext/libsass/.gitignore +10 -6
  4. data/ext/libsass/.travis.yml +4 -1
  5. data/ext/libsass/GNUmakefile.am +88 -0
  6. data/ext/libsass/Makefile +157 -76
  7. data/ext/libsass/Makefile.conf +47 -0
  8. data/ext/libsass/Readme.md +13 -14
  9. data/ext/libsass/appveyor.yml +25 -41
  10. data/ext/libsass/configure.ac +20 -7
  11. data/ext/libsass/contrib/plugin.cpp +1 -1
  12. data/ext/libsass/include/sass.h +15 -0
  13. data/ext/libsass/{sass.h → include/sass/base.h} +17 -9
  14. data/ext/libsass/{sass_context.h → include/sass/context.h} +3 -1
  15. data/ext/libsass/{sass_functions.h → include/sass/functions.h} +4 -4
  16. data/ext/libsass/{sass_interface.h → include/sass/interface.h} +5 -2
  17. data/ext/libsass/{sass_values.h → include/sass/values.h} +15 -1
  18. data/ext/libsass/{sass_version.h → include/sass/version.h} +0 -0
  19. data/ext/libsass/{sass_version.h.in → include/sass/version.h.in} +0 -0
  20. data/ext/libsass/{sass2scss.h → include/sass2scss.h} +6 -7
  21. data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +167 -0
  22. data/ext/libsass/script/ci-build-libsass +67 -23
  23. data/ext/libsass/src/GNUmakefile.am +54 -0
  24. data/ext/libsass/src/ast.cpp +2029 -0
  25. data/ext/libsass/{ast.hpp → src/ast.hpp} +832 -660
  26. data/ext/libsass/src/ast_def_macros.hpp +47 -0
  27. data/ext/libsass/src/ast_factory.hpp +93 -0
  28. data/ext/libsass/{ast_fwd_decl.hpp → src/ast_fwd_decl.hpp} +9 -4
  29. data/ext/libsass/{b64 → src/b64}/cencode.h +1 -1
  30. data/ext/libsass/{b64 → src/b64}/encode.h +0 -0
  31. data/ext/libsass/{backtrace.hpp → src/backtrace.hpp} +9 -10
  32. data/ext/libsass/{base64vlq.cpp → src/base64vlq.cpp} +2 -2
  33. data/ext/libsass/{base64vlq.hpp → src/base64vlq.hpp} +1 -2
  34. data/ext/libsass/{bind.cpp → src/bind.cpp} +96 -59
  35. data/ext/libsass/{bind.hpp → src/bind.hpp} +1 -1
  36. data/ext/libsass/src/c99func.c +54 -0
  37. data/ext/libsass/{cencode.c → src/cencode.c} +5 -5
  38. data/ext/libsass/src/color_maps.cpp +643 -0
  39. data/ext/libsass/src/color_maps.hpp +333 -0
  40. data/ext/libsass/{constants.cpp → src/constants.cpp} +10 -1
  41. data/ext/libsass/{constants.hpp → src/constants.hpp} +7 -0
  42. data/ext/libsass/{context.cpp → src/context.cpp} +152 -122
  43. data/ext/libsass/src/context.hpp +150 -0
  44. data/ext/libsass/{cssize.cpp → src/cssize.cpp} +123 -109
  45. data/ext/libsass/{cssize.hpp → src/cssize.hpp} +9 -13
  46. data/ext/libsass/{debug.hpp → src/debug.hpp} +9 -9
  47. data/ext/libsass/src/debugger.hpp +683 -0
  48. data/ext/libsass/{emitter.cpp → src/emitter.cpp} +13 -13
  49. data/ext/libsass/{emitter.hpp → src/emitter.hpp} +10 -11
  50. data/ext/libsass/src/environment.cpp +184 -0
  51. data/ext/libsass/src/environment.hpp +92 -0
  52. data/ext/libsass/src/error_handling.cpp +46 -0
  53. data/ext/libsass/src/error_handling.hpp +34 -0
  54. data/ext/libsass/src/eval.cpp +1462 -0
  55. data/ext/libsass/src/eval.hpp +107 -0
  56. data/ext/libsass/src/expand.cpp +653 -0
  57. data/ext/libsass/{expand.hpp → src/expand.hpp} +17 -16
  58. data/ext/libsass/{extend.cpp → src/extend.cpp} +198 -139
  59. data/ext/libsass/{extend.hpp → src/extend.hpp} +7 -8
  60. data/ext/libsass/{file.cpp → src/file.cpp} +103 -57
  61. data/ext/libsass/{file.hpp → src/file.hpp} +23 -14
  62. data/ext/libsass/{functions.cpp → src/functions.cpp} +642 -333
  63. data/ext/libsass/{functions.hpp → src/functions.hpp} +17 -4
  64. data/ext/libsass/{inspect.cpp → src/inspect.cpp} +147 -260
  65. data/ext/libsass/{inspect.hpp → src/inspect.hpp} +7 -7
  66. data/ext/libsass/{json.cpp → src/json.cpp} +33 -43
  67. data/ext/libsass/{json.hpp → src/json.hpp} +1 -1
  68. data/ext/libsass/{kwd_arg_macros.hpp → src/kwd_arg_macros.hpp} +0 -0
  69. data/ext/libsass/{lexer.cpp → src/lexer.cpp} +28 -0
  70. data/ext/libsass/{lexer.hpp → src/lexer.hpp} +25 -10
  71. data/ext/libsass/{listize.cpp → src/listize.cpp} +17 -13
  72. data/ext/libsass/{listize.hpp → src/listize.hpp} +0 -2
  73. data/ext/libsass/{mapping.hpp → src/mapping.hpp} +0 -0
  74. data/ext/libsass/src/memory_manager.cpp +76 -0
  75. data/ext/libsass/src/memory_manager.hpp +48 -0
  76. data/ext/libsass/{node.cpp → src/node.cpp} +89 -18
  77. data/ext/libsass/{node.hpp → src/node.hpp} +5 -6
  78. data/ext/libsass/{operation.hpp → src/operation.hpp} +18 -12
  79. data/ext/libsass/{output.cpp → src/output.cpp} +47 -55
  80. data/ext/libsass/{output.hpp → src/output.hpp} +5 -4
  81. data/ext/libsass/src/parser.cpp +2529 -0
  82. data/ext/libsass/{parser.hpp → src/parser.hpp} +84 -60
  83. data/ext/libsass/{paths.hpp → src/paths.hpp} +10 -13
  84. data/ext/libsass/{plugins.cpp → src/plugins.cpp} +14 -17
  85. data/ext/libsass/{plugins.hpp → src/plugins.hpp} +10 -11
  86. data/ext/libsass/{position.cpp → src/position.cpp} +5 -6
  87. data/ext/libsass/{position.hpp → src/position.hpp} +19 -22
  88. data/ext/libsass/{prelexer.cpp → src/prelexer.cpp} +401 -53
  89. data/ext/libsass/{prelexer.hpp → src/prelexer.hpp} +50 -10
  90. data/ext/libsass/{remove_placeholders.cpp → src/remove_placeholders.cpp} +12 -16
  91. data/ext/libsass/{remove_placeholders.hpp → src/remove_placeholders.hpp} +1 -7
  92. data/ext/libsass/{sass.cpp → src/sass.cpp} +3 -5
  93. data/ext/libsass/{sass2scss.cpp → src/sass2scss.cpp} +51 -46
  94. data/ext/libsass/{sass_context.cpp → src/sass_context.cpp} +114 -112
  95. data/ext/libsass/{sass_functions.cpp → src/sass_functions.cpp} +11 -18
  96. data/ext/libsass/{sass_interface.cpp → src/sass_interface.cpp} +44 -81
  97. data/ext/libsass/{sass_util.cpp → src/sass_util.cpp} +26 -8
  98. data/ext/libsass/{sass_util.hpp → src/sass_util.hpp} +14 -18
  99. data/ext/libsass/{sass_values.cpp → src/sass_values.cpp} +91 -20
  100. data/ext/libsass/{source_map.cpp → src/source_map.cpp} +13 -13
  101. data/ext/libsass/{source_map.hpp → src/source_map.hpp} +9 -9
  102. data/ext/libsass/{subset_map.hpp → src/subset_map.hpp} +29 -31
  103. data/ext/libsass/{support → src/support}/libsass.pc.in +0 -0
  104. data/ext/libsass/src/to_c.cpp +73 -0
  105. data/ext/libsass/src/to_c.hpp +41 -0
  106. data/ext/libsass/src/to_string.cpp +47 -0
  107. data/ext/libsass/{to_string.hpp → src/to_string.hpp} +9 -7
  108. data/ext/libsass/src/to_value.cpp +109 -0
  109. data/ext/libsass/src/to_value.hpp +50 -0
  110. data/ext/libsass/{units.cpp → src/units.cpp} +56 -51
  111. data/ext/libsass/{units.hpp → src/units.hpp} +8 -9
  112. data/ext/libsass/{utf8.h → src/utf8.h} +0 -0
  113. data/ext/libsass/{utf8 → src/utf8}/checked.h +0 -0
  114. data/ext/libsass/{utf8 → src/utf8}/core.h +12 -12
  115. data/ext/libsass/{utf8 → src/utf8}/unchecked.h +0 -0
  116. data/ext/libsass/{utf8_string.cpp → src/utf8_string.cpp} +0 -0
  117. data/ext/libsass/{utf8_string.hpp → src/utf8_string.hpp} +6 -6
  118. data/ext/libsass/{util.cpp → src/util.cpp} +144 -86
  119. data/ext/libsass/src/util.hpp +59 -0
  120. data/ext/libsass/src/values.cpp +137 -0
  121. data/ext/libsass/src/values.hpp +12 -0
  122. data/ext/libsass/test/test_node.cpp +33 -33
  123. data/ext/libsass/test/test_paths.cpp +5 -6
  124. data/ext/libsass/test/test_selector_difference.cpp +4 -5
  125. data/ext/libsass/test/test_specificity.cpp +4 -5
  126. data/ext/libsass/test/test_subset_map.cpp +91 -91
  127. data/ext/libsass/test/test_superselector.cpp +11 -11
  128. data/ext/libsass/test/test_unification.cpp +4 -4
  129. data/ext/libsass/win/libsass.targets +101 -0
  130. data/ext/libsass/win/libsass.vcxproj +45 -127
  131. data/ext/libsass/win/libsass.vcxproj.filters +303 -0
  132. data/lib/sassc/import_handler.rb +1 -1
  133. data/lib/sassc/native/native_functions_api.rb +3 -3
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/custom_importer_test.rb +1 -4
  136. data/test/functions_test.rb +3 -2
  137. data/test/native_test.rb +4 -3
  138. metadata +117 -110
  139. data/ext/libsass/Makefile.am +0 -146
  140. data/ext/libsass/ast.cpp +0 -945
  141. data/ext/libsass/ast_def_macros.hpp +0 -21
  142. data/ext/libsass/ast_factory.hpp +0 -92
  143. data/ext/libsass/color_names.hpp +0 -327
  144. data/ext/libsass/context.hpp +0 -157
  145. data/ext/libsass/contextualize.cpp +0 -148
  146. data/ext/libsass/contextualize.hpp +0 -46
  147. data/ext/libsass/contextualize_eval.cpp +0 -93
  148. data/ext/libsass/contextualize_eval.hpp +0 -44
  149. data/ext/libsass/debugger.hpp +0 -558
  150. data/ext/libsass/environment.hpp +0 -163
  151. data/ext/libsass/error_handling.cpp +0 -35
  152. data/ext/libsass/error_handling.hpp +0 -32
  153. data/ext/libsass/eval.cpp +0 -1392
  154. data/ext/libsass/eval.hpp +0 -88
  155. data/ext/libsass/expand.cpp +0 -575
  156. data/ext/libsass/memory_manager.hpp +0 -57
  157. data/ext/libsass/parser.cpp +0 -2403
  158. data/ext/libsass/posix/getopt.c +0 -562
  159. data/ext/libsass/posix/getopt.h +0 -95
  160. data/ext/libsass/to_c.cpp +0 -61
  161. data/ext/libsass/to_c.hpp +0 -44
  162. data/ext/libsass/to_string.cpp +0 -34
  163. data/ext/libsass/util.hpp +0 -54
  164. data/ext/libsass/win/libsass.filters +0 -312
@@ -11,15 +11,14 @@
11
11
  #include "source_map.hpp"
12
12
 
13
13
  namespace Sass {
14
- using std::ptrdiff_t;
15
14
  SourceMap::SourceMap() : current_position(0, 0, 0), file("stdin") { }
16
- SourceMap::SourceMap(const string& file) : current_position(0, 0, 0), file(file) { }
15
+ SourceMap::SourceMap(const std::string& file) : current_position(0, 0, 0), file(file) { }
17
16
 
18
- string SourceMap::generate_source_map(Context &ctx) {
17
+ std::string SourceMap::generate_source_map(Context &ctx) {
19
18
 
20
19
  const bool include_sources = ctx.source_map_contents;
21
- const vector<string> includes = ctx.include_links;
22
- const vector<const char*> sources = ctx.sources;
20
+ const std::vector<std::string> includes = ctx.include_links;
21
+ const std::vector<char*> sources = ctx.sources;
23
22
 
24
23
  JsonNode* json_srcmap = json_mkobject();
25
24
 
@@ -43,17 +42,18 @@ namespace Sass {
43
42
  }
44
43
  json_append_member(json_srcmap, "sources", json_includes);
45
44
 
46
- JsonNode *json_contents = json_mkarray();
47
45
  if (include_sources) {
46
+ JsonNode *json_contents = json_mkarray();
48
47
  for (size_t i = 0; i < source_index.size(); ++i) {
49
48
  const char *content = sources[source_index[i]];
50
49
  JsonNode *json_content = json_mkstring(content);
51
50
  json_append_element(json_contents, json_content);
52
51
  }
52
+ if (json_contents->children.head)
53
+ json_append_member(json_srcmap, "sourcesContent", json_contents);
53
54
  }
54
- json_append_member(json_srcmap, "sourcesContent", json_contents);
55
55
 
56
- string mappings = serialize_mappings();
56
+ std::string mappings = serialize_mappings();
57
57
  JsonNode *json_mappings = json_mkstring(mappings.c_str());
58
58
  json_append_member(json_srcmap, "mappings", json_mappings);
59
59
 
@@ -63,14 +63,14 @@ namespace Sass {
63
63
  json_append_member(json_srcmap, "names", json_names);
64
64
 
65
65
  char *str = json_stringify(json_srcmap, "\t");
66
- string result = string(str);
66
+ std::string result = std::string(str);
67
67
  free(str);
68
68
  json_delete(json_srcmap);
69
69
  return result;
70
70
  }
71
71
 
72
- string SourceMap::serialize_mappings() {
73
- string result = "";
72
+ std::string SourceMap::serialize_mappings() {
73
+ std::string result = "";
74
74
 
75
75
  size_t previous_generated_line = 0;
76
76
  size_t previous_generated_column = 0;
@@ -117,11 +117,11 @@ namespace Sass {
117
117
  Offset size(out.smap.current_position);
118
118
  for (Mapping mapping : out.smap.mappings) {
119
119
  if (mapping.generated_position.line > size.line) {
120
- throw(runtime_error("prepend sourcemap has illegal line"));
120
+ throw(std::runtime_error("prepend sourcemap has illegal line"));
121
121
  }
122
122
  if (mapping.generated_position.line == size.line) {
123
123
  if (mapping.generated_position.column > size.column) {
124
- throw(runtime_error("prepend sourcemap has illegal column"));
124
+ throw(std::runtime_error("prepend sourcemap has illegal column"));
125
125
  }
126
126
  }
127
127
  }
@@ -1,6 +1,7 @@
1
1
  #ifndef SASS_SOURCE_MAP_H
2
2
  #define SASS_SOURCE_MAP_H
3
3
 
4
+ #include <string>
4
5
  #include <vector>
5
6
 
6
7
  #include "ast_fwd_decl.hpp"
@@ -12,7 +13,6 @@
12
13
  #define VECTOR_UNSHIFT(vec, ins) vec.insert(vec.begin(), ins.begin(), ins.end())
13
14
 
14
15
  namespace Sass {
15
- using std::vector;
16
16
 
17
17
  class Context;
18
18
  class OutputBuffer;
@@ -20,11 +20,11 @@ namespace Sass {
20
20
  class SourceMap {
21
21
 
22
22
  public:
23
- vector<size_t> source_index;
23
+ std::vector<size_t> source_index;
24
24
  SourceMap();
25
- SourceMap(const string& file);
25
+ SourceMap(const std::string& file);
26
26
 
27
- void setFile(const string& str) {
27
+ void setFile(const std::string& str) {
28
28
  file = str;
29
29
  }
30
30
  void append(const Offset& offset);
@@ -34,17 +34,17 @@ namespace Sass {
34
34
  void add_open_mapping(AST_Node* node);
35
35
  void add_close_mapping(AST_Node* node);
36
36
 
37
- string generate_source_map(Context &ctx);
37
+ std::string generate_source_map(Context &ctx);
38
38
  ParserState remap(const ParserState& pstate);
39
39
 
40
40
  private:
41
41
 
42
- string serialize_mappings();
42
+ std::string serialize_mappings();
43
43
 
44
- vector<Mapping> mappings;
44
+ std::vector<Mapping> mappings;
45
45
  Position current_position;
46
46
  public:
47
- string file;
47
+ std::string file;
48
48
  private:
49
49
  Base64VLQ base64vlq;
50
50
  };
@@ -56,7 +56,7 @@ private:
56
56
  smap()
57
57
  { }
58
58
  public:
59
- string buffer;
59
+ std::string buffer;
60
60
  SourceMap smap;
61
61
  };
62
62
 
@@ -6,15 +6,14 @@
6
6
  #include <vector>
7
7
  #include <algorithm>
8
8
  #include <iterator>
9
- #include <iostream>
10
- #include <sstream>
11
9
 
12
- // using namespace std;
13
10
 
11
+ // #include <iostream>
12
+ // #include <sstream>
14
13
  // template<typename T>
15
- // string vector_to_string(vector<T> v)
14
+ // std::string vector_to_string(std::vector<T> v)
16
15
  // {
17
- // stringstream buffer;
16
+ // std::stringstream buffer;
18
17
  // buffer << "[";
19
18
 
20
19
  // if (!v.empty())
@@ -34,11 +33,11 @@
34
33
  // }
35
34
 
36
35
  // template<typename T>
37
- // string set_to_string(set<T> v)
36
+ // std::string set_to_string(set<T> v)
38
37
  // {
39
- // stringstream buffer;
38
+ // std::stringstream buffer;
40
39
  // buffer << "[";
41
- // typename set<T>::iterator i = v.begin();
40
+ // typename std::set<T>::iterator i = v.begin();
42
41
  // if (!v.empty())
43
42
  // { buffer << *i; }
44
43
  // else
@@ -56,7 +55,6 @@
56
55
  // }
57
56
 
58
57
  namespace Sass {
59
- using namespace std;
60
58
 
61
59
  template<typename F, typename S, typename T>
62
60
  struct triple {
@@ -74,24 +72,24 @@ namespace Sass {
74
72
  template<typename K, typename V>
75
73
  class Subset_Map {
76
74
  private:
77
- vector<V> values_;
78
- map<K, vector<triple<vector<K>, set<K>, size_t> > > hash_;
75
+ std::vector<V> values_;
76
+ std::map<K, std::vector<triple<std::vector<K>, std::set<K>, size_t> > > hash_;
79
77
  public:
80
- void put(const vector<K>& s, const V& value);
81
- vector<pair<V, vector<K> > > get_kv(const vector<K>& s);
82
- vector<V> get_v(const vector<K>& s);
78
+ void put(const std::vector<K>& s, const V& value);
79
+ std::vector<std::pair<V, std::vector<K> > > get_kv(const std::vector<K>& s);
80
+ std::vector<V> get_v(const std::vector<K>& s);
83
81
  bool empty() { return values_.empty(); }
84
82
  void clear() { values_.clear(); hash_.clear(); }
85
- const vector<V> values(void) { return values_; }
83
+ const std::vector<V> values(void) { return values_; }
86
84
  };
87
85
 
88
86
  template<typename K, typename V>
89
- void Subset_Map<K, V>::put(const vector<K>& s, const V& value)
87
+ void Subset_Map<K, V>::put(const std::vector<K>& s, const V& value)
90
88
  {
91
89
  if (s.empty()) throw "internal error: subset map keys may not be empty";
92
90
  size_t index = values_.size();
93
91
  values_.push_back(value);
94
- set<K> ss;
92
+ std::set<K> ss;
95
93
  for (size_t i = 0, S = s.size(); i < S; ++i)
96
94
  { ss.insert(s[i]); }
97
95
  for (size_t i = 0, S = s.size(); i < S; ++i)
@@ -102,42 +100,42 @@ namespace Sass {
102
100
  }
103
101
 
104
102
  template<typename K, typename V>
105
- vector<pair<V, vector<K> > > Subset_Map<K, V>::get_kv(const vector<K>& s)
103
+ std::vector<std::pair<V, std::vector<K> > > Subset_Map<K, V>::get_kv(const std::vector<K>& s)
106
104
  {
107
- vector<K> sorted = s;
105
+ std::vector<K> sorted = s;
108
106
  sort(sorted.begin(), sorted.end());
109
- vector<pair<size_t, vector<K> > > indices;
107
+ std::vector<std::pair<size_t, std::vector<K> > > indices;
110
108
  for (size_t i = 0, S = s.size(); i < S; ++i) {
111
109
  if (!hash_.count(s[i])) {
112
110
  continue;
113
111
  }
114
- vector<triple<vector<K>, set<K>, size_t> > subsets = hash_[s[i]];
115
- // cerr << "length of subsets: " << subsets.size() << endl;
112
+ std::vector<triple<std::vector<K>, std::set<K>, size_t> > subsets = hash_[s[i]];
113
+ // std::cerr << "length of subsets: " << subsets.size() << std::endl;
116
114
  for (size_t j = 0, T = subsets.size(); j < T; ++j) {
117
115
  if (!includes(sorted.begin(), sorted.end(), subsets[j].second.begin(), subsets[j].second.end())) {
118
- // cout << vector_to_string(s) << " doesn't include " << set_to_string(subsets[j].second) << endl;
116
+ // std::cout << vector_to_string(s) << " doesn't include " << set_to_string(subsets[j].second) << std::endl;
119
117
  continue;
120
118
  }
121
- indices.push_back(make_pair(subsets[j].third, subsets[j].first));
122
- // cerr << "pushed " << subsets[j].third << " and " << vector_to_string(subsets[j].first) << " onto indices" << endl;
119
+ indices.push_back(std::make_pair(subsets[j].third, subsets[j].first));
120
+ // std::cerr << "pushed " << subsets[j].third << " and " << vector_to_string(subsets[j].first) << " onto indices" << std::endl;
123
121
  }
124
122
  }
125
123
  sort(indices.begin(), indices.end());
126
- typename vector<pair<size_t, vector<K> > >::iterator indices_end = unique(indices.begin(), indices.end());
124
+ typename std::vector<std::pair<size_t, std::vector<K> > >::iterator indices_end = unique(indices.begin(), indices.end());
127
125
  indices.resize(distance(indices.begin(), indices_end));
128
126
 
129
- vector<pair<V, vector<K> > > results;
127
+ std::vector<std::pair<V, std::vector<K> > > results;
130
128
  for (size_t i = 0, S = indices.size(); i < S; ++i) {
131
- results.push_back(make_pair(values_[indices[i].first], indices[i].second));
129
+ results.push_back(std::make_pair(values_[indices[i].first], indices[i].second));
132
130
  }
133
131
  return results;
134
132
  }
135
133
 
136
134
  template<typename K, typename V>
137
- vector<V> Subset_Map<K, V>::get_v(const vector<K>& s)
135
+ std::vector<V> Subset_Map<K, V>::get_v(const std::vector<K>& s)
138
136
  {
139
- vector<pair<V, vector<K> > > kvs = get_kv(s);
140
- vector<V> results;
137
+ std::vector<std::pair<V, std::vector<K> > > kvs = get_kv(s);
138
+ std::vector<V> results;
141
139
  for (size_t i = 0, S = kvs.size(); i < S; ++i) results.push_back(kvs[i].first);
142
140
  return results;
143
141
  }
@@ -0,0 +1,73 @@
1
+ #include "to_c.hpp"
2
+ #include "ast.hpp"
3
+
4
+ namespace Sass {
5
+
6
+ union Sass_Value* To_C::fallback_impl(AST_Node* n)
7
+ { return sass_make_error("unknown type for C-API"); }
8
+
9
+ union Sass_Value* To_C::operator()(Boolean* b)
10
+ { return sass_make_boolean(b->value()); }
11
+
12
+ union Sass_Value* To_C::operator()(Number* n)
13
+ { return sass_make_number(n->value(), n->unit().c_str()); }
14
+
15
+ union Sass_Value* To_C::operator()(Custom_Warning* w)
16
+ { return sass_make_warning(w->message().c_str()); }
17
+
18
+ union Sass_Value* To_C::operator()(Custom_Error* e)
19
+ { return sass_make_error(e->message().c_str()); }
20
+
21
+ union Sass_Value* To_C::operator()(Color* c)
22
+ { return sass_make_color(c->r(), c->g(), c->b(), c->a()); }
23
+
24
+ union Sass_Value* To_C::operator()(String_Constant* s)
25
+ {
26
+ if (s->quote_mark()) {
27
+ return sass_make_qstring(s->value().c_str());
28
+ } else {
29
+ return sass_make_string(s->value().c_str());
30
+ }
31
+ }
32
+
33
+ union Sass_Value* To_C::operator()(String_Quoted* s)
34
+ { return sass_make_qstring(s->value().c_str()); }
35
+
36
+ union Sass_Value* To_C::operator()(List* l)
37
+ {
38
+ union Sass_Value* v = sass_make_list(l->length(), l->separator());
39
+ for (size_t i = 0, L = l->length(); i < L; ++i) {
40
+ sass_list_set_value(v, i, (*l)[i]->perform(this));
41
+ }
42
+ return v;
43
+ }
44
+
45
+ union Sass_Value* To_C::operator()(Map* m)
46
+ {
47
+ union Sass_Value* v = sass_make_map(m->length());
48
+ int i = 0;
49
+ for (auto key : m->keys()) {
50
+ sass_map_set_key(v, i, key->perform(this));
51
+ sass_map_set_value(v, i, m->at(key)->perform(this));
52
+ i++;
53
+ }
54
+ return v;
55
+ }
56
+
57
+ union Sass_Value* To_C::operator()(Arguments* a)
58
+ {
59
+ union Sass_Value* v = sass_make_list(a->length(), SASS_COMMA);
60
+ for (size_t i = 0, L = a->length(); i < L; ++i) {
61
+ sass_list_set_value(v, i, (*a)[i]->perform(this));
62
+ }
63
+ return v;
64
+ }
65
+
66
+ union Sass_Value* To_C::operator()(Argument* a)
67
+ { return a->value()->perform(this); }
68
+
69
+ // not strictly necessary because of the fallback
70
+ union Sass_Value* To_C::operator()(Null* n)
71
+ { return sass_make_null(); }
72
+
73
+ };
@@ -0,0 +1,41 @@
1
+ #ifndef SASS_TO_C_H
2
+ #define SASS_TO_C_H
3
+
4
+ #include "ast_fwd_decl.hpp"
5
+ #include "operation.hpp"
6
+ #include "sass/values.h"
7
+
8
+ namespace Sass {
9
+
10
+ class To_C : public Operation_CRTP<union Sass_Value*, To_C> {
11
+ // import all the class-specific methods and override as desired
12
+ using Operation<union Sass_Value*>::operator();
13
+ // override this to define a catch-all
14
+ union Sass_Value* fallback_impl(AST_Node* n);
15
+
16
+ public:
17
+
18
+ To_C() { }
19
+ virtual ~To_C() { }
20
+
21
+ union Sass_Value* operator()(Boolean*);
22
+ union Sass_Value* operator()(Number*);
23
+ union Sass_Value* operator()(Color*);
24
+ union Sass_Value* operator()(String_Constant*);
25
+ union Sass_Value* operator()(String_Quoted*);
26
+ union Sass_Value* operator()(Custom_Warning*);
27
+ union Sass_Value* operator()(Custom_Error*);
28
+ union Sass_Value* operator()(List*);
29
+ union Sass_Value* operator()(Map*);
30
+ union Sass_Value* operator()(Null*);
31
+ union Sass_Value* operator()(Arguments*);
32
+ union Sass_Value* operator()(Argument*);
33
+
34
+ // dispatch to fallback implementation
35
+ union Sass_Value* fallback(AST_Node* x)
36
+ { return fallback_impl(x); }
37
+ };
38
+
39
+ }
40
+
41
+ #endif
@@ -0,0 +1,47 @@
1
+ #include <cmath>
2
+ #include <sstream>
3
+ #include <iomanip>
4
+ #include <iostream>
5
+
6
+ #include "ast.hpp"
7
+ #include "inspect.hpp"
8
+ #include "context.hpp"
9
+ #include "to_string.hpp"
10
+
11
+ namespace Sass {
12
+
13
+ To_String::To_String(Context* ctx, bool in_declaration)
14
+ : ctx(ctx), in_declaration(in_declaration) { }
15
+ To_String::~To_String() { }
16
+
17
+ inline std::string To_String::fallback_impl(AST_Node* n)
18
+ {
19
+ Emitter emitter(ctx);
20
+ Inspect i(emitter);
21
+ i.in_declaration = in_declaration;
22
+ if (n) n->perform(&i);
23
+ return i.get_buffer();
24
+ }
25
+
26
+ inline std::string To_String::operator()(String_Schema* s)
27
+ {
28
+ std::string acc("");
29
+ for (size_t i = 0, L = s->length(); i < L; ++i) {
30
+ acc += s->elements()[i]->perform(this);
31
+ }
32
+ return acc;
33
+ }
34
+
35
+ inline std::string To_String::operator()(String_Quoted* s)
36
+ {
37
+ return s->value();
38
+ }
39
+
40
+ inline std::string To_String::operator()(String_Constant* s)
41
+ {
42
+ return s->value();
43
+ }
44
+
45
+ inline std::string To_String::operator()(Null* n)
46
+ { return ""; }
47
+ }
@@ -6,29 +6,31 @@
6
6
  #include "operation.hpp"
7
7
 
8
8
  namespace Sass {
9
- using namespace std;
10
9
 
11
10
  class Context;
12
11
  class Null;
13
12
 
14
- class To_String : public Operation_CRTP<string, To_String> {
13
+ class To_String : public Operation_CRTP<std::string, To_String> {
15
14
  // import all the class-specific methods and override as desired
16
- using Operation<string>::operator();
15
+ using Operation<std::string>::operator();
17
16
  // override this to define a catch-all
18
- string fallback_impl(AST_Node* n);
17
+ std::string fallback_impl(AST_Node* n);
19
18
 
20
19
  Context* ctx;
21
20
  bool in_declaration;
22
21
 
23
22
  public:
23
+
24
24
  To_String(Context* ctx = 0, bool in_declaration = true);
25
25
  virtual ~To_String();
26
26
 
27
- string operator()(Null* n);
28
- string operator()(String_Constant*);
27
+ std::string operator()(Null* n);
28
+ std::string operator()(String_Schema*);
29
+ std::string operator()(String_Quoted*);
30
+ std::string operator()(String_Constant*);
29
31
 
30
32
  template <typename U>
31
- string fallback(U n) { return fallback_impl(n); }
33
+ std::string fallback(U n) { return fallback_impl(n); }
32
34
  };
33
35
  }
34
36