sassc 2.1.0.pre3 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +24 -0
  4. data/Rakefile +2 -4
  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.hpp +12 -0
  81. data/ext/libsass/src/memory/allocator.cpp +48 -0
  82. data/ext/libsass/src/memory/allocator.hpp +138 -0
  83. data/ext/libsass/src/memory/config.hpp +20 -0
  84. data/ext/libsass/src/memory/memory_pool.hpp +186 -0
  85. data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
  86. data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
  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 +11 -13
  132. data/lib/sassc/native.rb +9 -7
  133. data/lib/sassc/script.rb +4 -6
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/functions_test.rb +38 -1
  136. data/test/native_test.rb +4 -4
  137. metadata +31 -18
  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
@@ -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,
@@ -467,7 +467,7 @@ namespace Sass
467
467
  // right trim input
468
468
  sass = rtrim(sass);
469
469
 
470
- // get postion of first meaningfull character in string
470
+ // get position of first meaningfull character in string
471
471
  size_t pos_left = sass.find_first_not_of(SASS2SCSS_FIND_WHITESPACE);
472
472
 
473
473
  // special case for final run
@@ -557,7 +557,7 @@ namespace Sass
557
557
  // default to a selector
558
558
  // change back if property found
559
559
  converter.selector = true;
560
- // get postion of first whitespace char
560
+ // get position of first whitespace char
561
561
  size_t pos_wspace = sass.find_first_of(SASS2SCSS_FIND_WHITESPACE, pos_left);
562
562
  // assertion check for valid result
563
563
  if (pos_wspace != std::string::npos)
@@ -580,7 +580,7 @@ namespace Sass
580
580
  // assertion for valid result
581
581
  if (pos_colon != std::string::npos)
582
582
  {
583
- // ... after the first word (skip begining colons)
583
+ // ... after the first word (skip beginning colons)
584
584
  pos_colon = sass.find_first_of(":", pos_colon);
585
585
  // it is a selector if there was no colon found
586
586
  converter.selector = pos_colon == std::string::npos;
@@ -758,7 +758,7 @@ namespace Sass
758
758
  scss += flush(sass, converter);
759
759
  }
760
760
 
761
- // get postion of last meaningfull char
761
+ // get position of last meaningfull char
762
762
  size_t pos_right = sass.find_last_not_of(SASS2SCSS_FIND_WHITESPACE);
763
763
 
764
764
  // check for invalid result
@@ -1,44 +1,49 @@
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
-
5
- #include <cstring>
6
- #include <stdexcept>
7
- #include <sstream>
8
- #include <string>
9
- #include <vector>
10
-
11
- #include "sass.h"
12
4
  #include "ast.hpp"
13
- #include "file.hpp"
14
- #include "json.hpp"
15
- #include "util.hpp"
16
- #include "context.hpp"
17
- #include "sass_context.hpp"
5
+
18
6
  #include "sass_functions.hpp"
19
- #include "ast_fwd_decl.hpp"
20
- #include "error_handling.hpp"
7
+ #include "json.hpp"
21
8
 
22
9
  #define LFEED "\n"
23
10
 
24
11
  // C++ helper
25
12
  namespace Sass {
26
- // see sass_copy_c_string(std::string str)
27
- static inline JsonNode* json_mkstream(const std::stringstream& stream)
13
+ // see sass_copy_c_string(sass::string str)
14
+ static inline JsonNode* json_mkstream(const sass::ostream& stream)
28
15
  {
29
16
  // hold on to string on stack!
30
- std::string str(stream.str());
17
+ sass::string str(stream.str());
31
18
  return json_mkstring(str.c_str());
32
19
  }
33
20
 
21
+ static void handle_string_error(Sass_Context* c_ctx, const sass::string& msg, int severety)
22
+ {
23
+ sass::ostream msg_stream;
24
+ JsonNode* json_err = json_mkobject();
25
+ msg_stream << "Internal Error: " << msg << std::endl;
26
+ json_append_member(json_err, "status", json_mknumber(severety));
27
+ json_append_member(json_err, "message", json_mkstring(msg.c_str()));
28
+ json_append_member(json_err, "formatted", json_mkstream(msg_stream));
29
+ try { c_ctx->error_json = json_stringify(json_err, " "); }
30
+ catch (...) {}
31
+ c_ctx->error_message = sass_copy_string(msg_stream.str());
32
+ c_ctx->error_text = sass_copy_c_string(msg.c_str());
33
+ c_ctx->error_status = severety;
34
+ c_ctx->output_string = 0;
35
+ c_ctx->source_map_string = 0;
36
+ json_delete(json_err);
37
+ }
38
+
34
39
  static int handle_error(Sass_Context* c_ctx) {
35
40
  try {
36
41
  throw;
37
42
  }
38
43
  catch (Exception::Base& e) {
39
- std::stringstream msg_stream;
40
- std::string cwd(Sass::File::get_cwd());
41
- std::string msg_prefix(e.errtype());
44
+ sass::ostream msg_stream;
45
+ sass::string cwd(Sass::File::get_cwd());
46
+ sass::string msg_prefix(e.errtype());
42
47
  bool got_newline = false;
43
48
  msg_stream << msg_prefix << ": ";
44
49
  const char* msg = e.what();
@@ -50,7 +55,7 @@ namespace Sass {
50
55
  got_newline = true;
51
56
  }
52
57
  else if (got_newline) {
53
- msg_stream << std::string(msg_prefix.size() + 2, ' ');
58
+ msg_stream << sass::string(msg_prefix.size() + 2, ' ');
54
59
  got_newline = false;
55
60
  }
56
61
  msg_stream << *msg;
@@ -60,24 +65,25 @@ namespace Sass {
60
65
 
61
66
  if (e.traces.empty()) {
62
67
  // we normally should have some traces, still here as a fallback
63
- std::string rel_path(Sass::File::abs2rel(e.pstate.path, cwd, cwd));
64
- msg_stream << std::string(msg_prefix.size() + 2, ' ');
65
- msg_stream << " on line " << e.pstate.line + 1 << " of " << rel_path << "\n";
68
+ sass::string rel_path(Sass::File::abs2rel(e.pstate.getPath(), cwd, cwd));
69
+ msg_stream << sass::string(msg_prefix.size() + 2, ' ');
70
+ msg_stream << " on line " << e.pstate.getLine() << " of " << rel_path << "\n";
66
71
  }
67
72
  else {
68
- std::string rel_path(Sass::File::abs2rel(e.pstate.path, cwd, cwd));
73
+ sass::string rel_path(Sass::File::abs2rel(e.pstate.getPath(), cwd, cwd));
69
74
  msg_stream << traces_to_string(e.traces, " ");
70
75
  }
71
76
 
72
77
  // now create the code trace (ToDo: maybe have util functions?)
73
- if (e.pstate.line != std::string::npos &&
74
- e.pstate.column != std::string::npos &&
75
- e.pstate.src != nullptr) {
76
- size_t lines = e.pstate.line;
78
+ if (e.pstate.position.line != sass::string::npos &&
79
+ e.pstate.position.column != sass::string::npos &&
80
+ e.pstate.source != nullptr) {
81
+ Offset offset(e.pstate.position);
82
+ size_t lines = offset.line;
77
83
  // scan through src until target line
78
84
  // move line_beg pointer to line start
79
85
  const char* line_beg;
80
- for (line_beg = e.pstate.src; *line_beg != '\0'; ++line_beg) {
86
+ for (line_beg = e.pstate.getRawData(); *line_beg != '\0'; ++line_beg) {
81
87
  if (lines == 0) break;
82
88
  if (*line_beg == '\n') --lines;
83
89
  }
@@ -91,12 +97,12 @@ namespace Sass {
91
97
  size_t move_in = 0; size_t shorten = 0;
92
98
  size_t left_chars = 42; size_t max_chars = 76;
93
99
  // reported excerpt should not exceed `max_chars` chars
94
- if (e.pstate.column > line_len) left_chars = e.pstate.column;
95
- if (e.pstate.column > left_chars) move_in = e.pstate.column - left_chars;
100
+ if (offset.column > line_len) left_chars = offset.column;
101
+ if (offset.column > left_chars) move_in = offset.column - left_chars;
96
102
  if (line_len > max_chars + move_in) shorten = line_len - move_in - max_chars;
97
103
  utf8::advance(line_beg, move_in, line_end);
98
104
  utf8::retreat(line_end, shorten, line_beg);
99
- std::string sanitized; std::string marker(e.pstate.column - move_in, '-');
105
+ sass::string sanitized; sass::string marker(offset.column - move_in, '-');
100
106
  utf8::replace_invalid(line_beg, line_end, std::back_inserter(sanitized));
101
107
  msg_stream << ">> " << sanitized << "\n";
102
108
  msg_stream << " " << marker << "^\n";
@@ -104,102 +110,40 @@ namespace Sass {
104
110
 
105
111
  JsonNode* json_err = json_mkobject();
106
112
  json_append_member(json_err, "status", json_mknumber(1));
107
- json_append_member(json_err, "file", json_mkstring(e.pstate.path));
108
- json_append_member(json_err, "line", json_mknumber((double)(e.pstate.line + 1)));
109
- json_append_member(json_err, "column", json_mknumber((double)(e.pstate.column + 1)));
113
+ json_append_member(json_err, "file", json_mkstring(e.pstate.getPath()));
114
+ json_append_member(json_err, "line", json_mknumber((double)(e.pstate.getLine())));
115
+ json_append_member(json_err, "column", json_mknumber((double)(e.pstate.getColumn())));
110
116
  json_append_member(json_err, "message", json_mkstring(e.what()));
111
117
  json_append_member(json_err, "formatted", json_mkstream(msg_stream));
112
118
  try { c_ctx->error_json = json_stringify(json_err, " "); }
113
- catch (...) {}
119
+ catch (...) {} // silently ignore this error?
114
120
  c_ctx->error_message = sass_copy_string(msg_stream.str());
115
121
  c_ctx->error_text = sass_copy_c_string(e.what());
116
122
  c_ctx->error_status = 1;
117
- c_ctx->error_file = sass_copy_c_string(e.pstate.path);
118
- c_ctx->error_line = e.pstate.line + 1;
119
- c_ctx->error_column = e.pstate.column + 1;
120
- c_ctx->error_src = e.pstate.src;
123
+ c_ctx->error_file = sass_copy_c_string(e.pstate.getPath());
124
+ c_ctx->error_line = e.pstate.getLine();
125
+ c_ctx->error_column = e.pstate.getColumn();
126
+ c_ctx->error_src = sass_copy_c_string(e.pstate.getRawData());
121
127
  c_ctx->output_string = 0;
122
128
  c_ctx->source_map_string = 0;
123
129
  json_delete(json_err);
124
130
  }
125
131
  catch (std::bad_alloc& ba) {
126
- std::stringstream msg_stream;
127
- JsonNode* json_err = json_mkobject();
128
- msg_stream << "Unable to allocate memory: " << ba.what() << std::endl;
129
- json_append_member(json_err, "status", json_mknumber(2));
130
- json_append_member(json_err, "message", json_mkstring(ba.what()));
131
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
132
- try { c_ctx->error_json = json_stringify(json_err, " "); }
133
- catch (...) {}
134
- c_ctx->error_message = sass_copy_string(msg_stream.str());
135
- c_ctx->error_text = sass_copy_c_string(ba.what());
136
- c_ctx->error_status = 2;
137
- c_ctx->output_string = 0;
138
- c_ctx->source_map_string = 0;
139
- json_delete(json_err);
132
+ sass::ostream msg_stream;
133
+ msg_stream << "Unable to allocate memory: " << ba.what();
134
+ handle_string_error(c_ctx, msg_stream.str(), 2);
140
135
  }
141
136
  catch (std::exception& e) {
142
- std::stringstream msg_stream;
143
- JsonNode* json_err = json_mkobject();
144
- msg_stream << "Internal Error: " << e.what() << std::endl;
145
- json_append_member(json_err, "status", json_mknumber(3));
146
- json_append_member(json_err, "message", json_mkstring(e.what()));
147
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
148
- try { c_ctx->error_json = json_stringify(json_err, " "); }
149
- catch (...) {}
150
- c_ctx->error_message = sass_copy_string(msg_stream.str());
151
- c_ctx->error_text = sass_copy_c_string(e.what());
152
- c_ctx->error_status = 3;
153
- c_ctx->output_string = 0;
154
- c_ctx->source_map_string = 0;
155
- json_delete(json_err);
137
+ handle_string_error(c_ctx, e.what(), 3);
156
138
  }
157
- catch (std::string& e) {
158
- std::stringstream msg_stream;
159
- JsonNode* json_err = json_mkobject();
160
- msg_stream << "Internal Error: " << e << std::endl;
161
- json_append_member(json_err, "status", json_mknumber(4));
162
- json_append_member(json_err, "message", json_mkstring(e.c_str()));
163
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
164
- try { c_ctx->error_json = json_stringify(json_err, " "); }
165
- catch (...) {}
166
- c_ctx->error_message = sass_copy_string(msg_stream.str());
167
- c_ctx->error_text = sass_copy_c_string(e.c_str());
168
- c_ctx->error_status = 4;
169
- c_ctx->output_string = 0;
170
- c_ctx->source_map_string = 0;
171
- json_delete(json_err);
139
+ catch (sass::string& e) {
140
+ handle_string_error(c_ctx, e, 4);
172
141
  }
173
142
  catch (const char* e) {
174
- std::stringstream msg_stream;
175
- JsonNode* json_err = json_mkobject();
176
- msg_stream << "Internal Error: " << e << std::endl;
177
- json_append_member(json_err, "status", json_mknumber(4));
178
- json_append_member(json_err, "message", json_mkstring(e));
179
- json_append_member(json_err, "formatted", json_mkstream(msg_stream));
180
- try { c_ctx->error_json = json_stringify(json_err, " "); }
181
- catch (...) {}
182
- c_ctx->error_message = sass_copy_string(msg_stream.str());
183
- c_ctx->error_text = sass_copy_c_string(e);
184
- c_ctx->error_status = 4;
185
- c_ctx->output_string = 0;
186
- c_ctx->source_map_string = 0;
187
- json_delete(json_err);
143
+ handle_string_error(c_ctx, e, 4);
188
144
  }
189
145
  catch (...) {
190
- std::stringstream msg_stream;
191
- JsonNode* json_err = json_mkobject();
192
- msg_stream << "Unknown error occurred" << std::endl;
193
- json_append_member(json_err, "status", json_mknumber(5));
194
- json_append_member(json_err, "message", json_mkstring("unknown"));
195
- try { c_ctx->error_json = json_stringify(json_err, " "); }
196
- catch (...) {}
197
- c_ctx->error_message = sass_copy_string(msg_stream.str());
198
- c_ctx->error_text = sass_copy_c_string("unknown");
199
- c_ctx->error_status = 5;
200
- c_ctx->output_string = 0;
201
- c_ctx->source_map_string = 0;
202
- json_delete(json_err);
146
+ handle_string_error(c_ctx, "unknown", 5);
203
147
  }
204
148
  return c_ctx->error_status;
205
149
  }
@@ -226,8 +170,8 @@ namespace Sass {
226
170
  try {
227
171
 
228
172
  // get input/output path from options
229
- std::string input_path = safe_str(c_ctx->input_path);
230
- std::string output_path = safe_str(c_ctx->output_path);
173
+ sass::string input_path = safe_str(c_ctx->input_path);
174
+ sass::string output_path = safe_str(c_ctx->output_path);
231
175
 
232
176
  // maybe skip some entries of included files
233
177
  // we do not include stdin for data contexts
@@ -334,10 +278,10 @@ extern "C" {
334
278
  c_ctx->error_message = 0;
335
279
  c_ctx->error_status = 0;
336
280
  // reset error position
337
- c_ctx->error_src = 0;
338
281
  c_ctx->error_file = 0;
339
- c_ctx->error_line = std::string::npos;
340
- c_ctx->error_column = std::string::npos;
282
+ c_ctx->error_src = 0;
283
+ c_ctx->error_line = sass::string::npos;
284
+ c_ctx->error_column = sass::string::npos;
341
285
 
342
286
  // allocate a new compiler instance
343
287
  void* ctxmem = calloc(1, sizeof(struct Sass_Compiler));
@@ -399,7 +343,9 @@ extern "C" {
399
343
 
400
344
  Sass_File_Context* ADDCALL sass_make_file_context(const char* input_path)
401
345
  {
402
- SharedObj::setTaint(true); // needed for static colors
346
+ #ifdef DEBUG_SHARED_PTR
347
+ SharedObj::setTaint(true);
348
+ #endif
403
349
  struct Sass_File_Context* ctx = (struct Sass_File_Context*) calloc(1, sizeof(struct Sass_File_Context));
404
350
  if (ctx == 0) { std::cerr << "Error allocating memory for file context" << std::endl; return 0; }
405
351
  ctx->type = SASS_CONTEXT_FILE;
@@ -416,6 +362,9 @@ extern "C" {
416
362
 
417
363
  Sass_Data_Context* ADDCALL sass_make_data_context(char* source_string)
418
364
  {
365
+ #ifdef DEBUG_SHARED_PTR
366
+ SharedObj::setTaint(true);
367
+ #endif
419
368
  struct Sass_Data_Context* ctx = (struct Sass_Data_Context*) calloc(1, sizeof(struct Sass_Data_Context));
420
369
  if (ctx == 0) { std::cerr << "Error allocating memory for data context" << std::endl; return 0; }
421
370
  ctx->type = SASS_CONTEXT_DATA;
@@ -451,7 +400,7 @@ extern "C" {
451
400
  return data_ctx->error_status;
452
401
  try {
453
402
  if (data_ctx->source_string == 0) { throw(std::runtime_error("Data context has no source string")); }
454
- // empty source string is a valid case, even if not really usefull (different than with file context)
403
+ // empty source string is a valid case, even if not really useful (different than with file context)
455
404
  // if (*data_ctx->source_string == 0) { throw(std::runtime_error("Data context has empty source string")); }
456
405
  }
457
406
  catch (...) { return handle_errors(data_ctx) | 1; }
@@ -533,7 +482,7 @@ extern "C" {
533
482
  static void sass_clear_options (struct Sass_Options* options)
534
483
  {
535
484
  if (options == 0) return;
536
- // Deallocate custom functions, headers and importes
485
+ // Deallocate custom functions, headers and imports
537
486
  sass_delete_function_list(options->c_functions);
538
487
  sass_delete_importer_list(options->c_importers);
539
488
  sass_delete_importer_list(options->c_headers);
@@ -594,6 +543,7 @@ extern "C" {
594
543
  if (ctx->error_text) free(ctx->error_text);
595
544
  if (ctx->error_json) free(ctx->error_json);
596
545
  if (ctx->error_file) free(ctx->error_file);
546
+ if (ctx->error_src) free(ctx->error_src);
597
547
  free_string_array(ctx->included_files);
598
548
  // play safe and reset properties
599
549
  ctx->output_string = 0;
@@ -602,6 +552,7 @@ extern "C" {
602
552
  ctx->error_text = 0;
603
553
  ctx->error_json = 0;
604
554
  ctx->error_file = 0;
555
+ ctx->error_src = 0;
605
556
  ctx->included_files = 0;
606
557
  // debug leaked memory
607
558
  #ifdef DEBUG_SHARED_PTR
@@ -656,7 +607,7 @@ extern "C" {
656
607
  void ADDCALL sass_file_context_set_options (struct Sass_File_Context* ctx, struct Sass_Options* opt) { copy_options(ctx, opt); }
657
608
  void ADDCALL sass_data_context_set_options (struct Sass_Data_Context* ctx, struct Sass_Options* opt) { copy_options(ctx, opt); }
658
609
 
659
- // Getters for Sass_Compiler options (get conected sass context)
610
+ // Getters for Sass_Compiler options (get connected sass context)
660
611
  enum Sass_Compiler_State ADDCALL sass_compiler_get_state(struct Sass_Compiler* compiler) { return compiler->state; }
661
612
  struct Sass_Context* ADDCALL sass_compiler_get_context(struct Sass_Compiler* compiler) { return compiler->c_ctx; }
662
613
  struct Sass_Options* ADDCALL sass_compiler_get_options(struct Sass_Compiler* compiler) { return compiler->c_ctx; }
@@ -700,9 +651,9 @@ extern "C" {
700
651
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_message);
701
652
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_text);
702
653
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_file);
654
+ IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_src);
703
655
  IMPLEMENT_SASS_CONTEXT_GETTER(size_t, error_line);
704
656
  IMPLEMENT_SASS_CONTEXT_GETTER(size_t, error_column);
705
- IMPLEMENT_SASS_CONTEXT_GETTER(const char*, error_src);
706
657
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, output_string);
707
658
  IMPLEMENT_SASS_CONTEXT_GETTER(const char*, source_map_string);
708
659
  IMPLEMENT_SASS_CONTEXT_GETTER(char**, included_files);
@@ -712,6 +663,7 @@ extern "C" {
712
663
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_message);
713
664
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_text);
714
665
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_file);
666
+ IMPLEMENT_SASS_CONTEXT_TAKER(char*, error_src);
715
667
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, output_string);
716
668
  IMPLEMENT_SASS_CONTEXT_TAKER(char*, source_map_string);
717
669
  IMPLEMENT_SASS_CONTEXT_TAKER(char**, included_files);
@@ -751,6 +703,23 @@ extern "C" {
751
703
  return cur->string;
752
704
  }
753
705
 
706
+ // Push function for plugin paths (no manipulation support for now)
707
+ size_t ADDCALL sass_option_get_plugin_path_size(struct Sass_Options* options)
708
+ {
709
+ size_t len = 0;
710
+ struct string_list* cur = options->plugin_paths;
711
+ while (cur) { len++; cur = cur->next; }
712
+ return len;
713
+ }
714
+
715
+ // Push function for plugin paths (no manipulation support for now)
716
+ const char* ADDCALL sass_option_get_plugin_path(struct Sass_Options* options, size_t i)
717
+ {
718
+ struct string_list* cur = options->plugin_paths;
719
+ while (i) { i--; cur = cur->next; }
720
+ return cur->string;
721
+ }
722
+
754
723
  // Push function for plugin paths (no manipulation support for now)
755
724
  void ADDCALL sass_option_push_plugin_path(struct Sass_Options* options, const char* path)
756
725
  {