sassc 0.0.1

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 (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +24 -0
  8. data/Rakefile +21 -0
  9. data/ext/libsass/.editorconfig +15 -0
  10. data/ext/libsass/.gitattributes +2 -0
  11. data/ext/libsass/.gitignore +61 -0
  12. data/ext/libsass/.travis.yml +38 -0
  13. data/ext/libsass/COPYING +25 -0
  14. data/ext/libsass/INSTALL +1 -0
  15. data/ext/libsass/LICENSE +25 -0
  16. data/ext/libsass/Makefile +223 -0
  17. data/ext/libsass/Makefile.am +145 -0
  18. data/ext/libsass/Readme.md +93 -0
  19. data/ext/libsass/appveyor.yml +76 -0
  20. data/ext/libsass/ast.cpp +581 -0
  21. data/ext/libsass/ast.hpp +1949 -0
  22. data/ext/libsass/ast_def_macros.hpp +16 -0
  23. data/ext/libsass/ast_factory.hpp +87 -0
  24. data/ext/libsass/ast_fwd_decl.hpp +72 -0
  25. data/ext/libsass/b64/cencode.h +32 -0
  26. data/ext/libsass/b64/encode.h +77 -0
  27. data/ext/libsass/backtrace.hpp +81 -0
  28. data/ext/libsass/base64vlq.cpp +43 -0
  29. data/ext/libsass/base64vlq.hpp +28 -0
  30. data/ext/libsass/bind.cpp +187 -0
  31. data/ext/libsass/bind.hpp +18 -0
  32. data/ext/libsass/cencode.c +102 -0
  33. data/ext/libsass/color_names.hpp +324 -0
  34. data/ext/libsass/configure.ac +130 -0
  35. data/ext/libsass/constants.cpp +144 -0
  36. data/ext/libsass/constants.hpp +145 -0
  37. data/ext/libsass/context.cpp +507 -0
  38. data/ext/libsass/context.hpp +150 -0
  39. data/ext/libsass/contextualize.cpp +157 -0
  40. data/ext/libsass/contextualize.hpp +65 -0
  41. data/ext/libsass/copy_c_str.cpp +13 -0
  42. data/ext/libsass/copy_c_str.hpp +5 -0
  43. data/ext/libsass/debug.hpp +39 -0
  44. data/ext/libsass/environment.hpp +75 -0
  45. data/ext/libsass/error_handling.cpp +28 -0
  46. data/ext/libsass/error_handling.hpp +28 -0
  47. data/ext/libsass/eval.cpp +1149 -0
  48. data/ext/libsass/eval.hpp +80 -0
  49. data/ext/libsass/expand.cpp +430 -0
  50. data/ext/libsass/expand.hpp +77 -0
  51. data/ext/libsass/extconf.rb +6 -0
  52. data/ext/libsass/extend.cpp +1962 -0
  53. data/ext/libsass/extend.hpp +50 -0
  54. data/ext/libsass/file.cpp +291 -0
  55. data/ext/libsass/file.hpp +18 -0
  56. data/ext/libsass/functions.cpp +1565 -0
  57. data/ext/libsass/functions.hpp +187 -0
  58. data/ext/libsass/inspect.cpp +727 -0
  59. data/ext/libsass/inspect.hpp +108 -0
  60. data/ext/libsass/json.cpp +1411 -0
  61. data/ext/libsass/json.hpp +117 -0
  62. data/ext/libsass/kwd_arg_macros.hpp +23 -0
  63. data/ext/libsass/m4/.gitkeep +0 -0
  64. data/ext/libsass/mapping.hpp +17 -0
  65. data/ext/libsass/memory_manager.hpp +54 -0
  66. data/ext/libsass/node.cpp +251 -0
  67. data/ext/libsass/node.hpp +122 -0
  68. data/ext/libsass/operation.hpp +153 -0
  69. data/ext/libsass/output_compressed.cpp +401 -0
  70. data/ext/libsass/output_compressed.hpp +95 -0
  71. data/ext/libsass/output_nested.cpp +364 -0
  72. data/ext/libsass/output_nested.hpp +108 -0
  73. data/ext/libsass/parser.cpp +2016 -0
  74. data/ext/libsass/parser.hpp +264 -0
  75. data/ext/libsass/paths.hpp +69 -0
  76. data/ext/libsass/position.hpp +22 -0
  77. data/ext/libsass/posix/getopt.c +562 -0
  78. data/ext/libsass/posix/getopt.h +95 -0
  79. data/ext/libsass/prelexer.cpp +688 -0
  80. data/ext/libsass/prelexer.hpp +513 -0
  81. data/ext/libsass/remove_placeholders.cpp +59 -0
  82. data/ext/libsass/remove_placeholders.hpp +43 -0
  83. data/ext/libsass/res/resource.rc +35 -0
  84. data/ext/libsass/sass.cpp +33 -0
  85. data/ext/libsass/sass.h +60 -0
  86. data/ext/libsass/sass2scss.cpp +834 -0
  87. data/ext/libsass/sass2scss.h +110 -0
  88. data/ext/libsass/sass_context.cpp +709 -0
  89. data/ext/libsass/sass_context.h +120 -0
  90. data/ext/libsass/sass_functions.cpp +137 -0
  91. data/ext/libsass/sass_functions.h +90 -0
  92. data/ext/libsass/sass_interface.cpp +277 -0
  93. data/ext/libsass/sass_interface.h +97 -0
  94. data/ext/libsass/sass_util.cpp +136 -0
  95. data/ext/libsass/sass_util.hpp +259 -0
  96. data/ext/libsass/sass_values.cpp +337 -0
  97. data/ext/libsass/sass_values.h +124 -0
  98. data/ext/libsass/script/bootstrap +10 -0
  99. data/ext/libsass/script/branding +10 -0
  100. data/ext/libsass/script/ci-build-libsass +72 -0
  101. data/ext/libsass/script/ci-install-compiler +4 -0
  102. data/ext/libsass/script/ci-install-deps +19 -0
  103. data/ext/libsass/script/ci-report-coverage +25 -0
  104. data/ext/libsass/script/coveralls-debug +32 -0
  105. data/ext/libsass/script/spec +5 -0
  106. data/ext/libsass/script/tap-driver +652 -0
  107. data/ext/libsass/script/tap-runner +1 -0
  108. data/ext/libsass/source_map.cpp +133 -0
  109. data/ext/libsass/source_map.hpp +46 -0
  110. data/ext/libsass/subset_map.hpp +145 -0
  111. data/ext/libsass/support/libsass.pc.in +11 -0
  112. data/ext/libsass/test-driver +127 -0
  113. data/ext/libsass/test/test_node.cpp +98 -0
  114. data/ext/libsass/test/test_paths.cpp +29 -0
  115. data/ext/libsass/test/test_selector_difference.cpp +28 -0
  116. data/ext/libsass/test/test_specificity.cpp +28 -0
  117. data/ext/libsass/test/test_subset_map.cpp +472 -0
  118. data/ext/libsass/test/test_superselector.cpp +71 -0
  119. data/ext/libsass/test/test_unification.cpp +33 -0
  120. data/ext/libsass/to_c.cpp +61 -0
  121. data/ext/libsass/to_c.hpp +44 -0
  122. data/ext/libsass/to_string.cpp +29 -0
  123. data/ext/libsass/to_string.hpp +32 -0
  124. data/ext/libsass/token.hpp +32 -0
  125. data/ext/libsass/units.cpp +54 -0
  126. data/ext/libsass/units.hpp +10 -0
  127. data/ext/libsass/utf8.h +34 -0
  128. data/ext/libsass/utf8/checked.h +327 -0
  129. data/ext/libsass/utf8/core.h +329 -0
  130. data/ext/libsass/utf8/unchecked.h +228 -0
  131. data/ext/libsass/utf8_string.cpp +102 -0
  132. data/ext/libsass/utf8_string.hpp +36 -0
  133. data/ext/libsass/util.cpp +189 -0
  134. data/ext/libsass/util.hpp +26 -0
  135. data/ext/libsass/win/libsass.filters +291 -0
  136. data/ext/libsass/win/libsass.sln +28 -0
  137. data/ext/libsass/win/libsass.vcxproj +255 -0
  138. data/lib/sassc.rb +6 -0
  139. data/lib/sassc/engine.rb +13 -0
  140. data/lib/sassc/native.rb +44 -0
  141. data/lib/sassc/native/native_context_api.rb +140 -0
  142. data/lib/sassc/native/native_functions_api.rb +41 -0
  143. data/lib/sassc/native/sass_input_style.rb +11 -0
  144. data/lib/sassc/native/sass_output_style.rb +10 -0
  145. data/lib/sassc/native/sass_value.rb +95 -0
  146. data/lib/sassc/native/string_list.rb +8 -0
  147. data/lib/sassc/version.rb +3 -0
  148. data/sassc.gemspec +43 -0
  149. data/test/smoke_test.rb +171 -0
  150. data/test/test_helper.rb +4 -0
  151. metadata +281 -0
@@ -0,0 +1,16 @@
1
+ #define ATTACH_OPERATIONS()\
2
+ virtual void perform(Operation<void>* op) { (*op)(this); }\
3
+ virtual AST_Node* perform(Operation<AST_Node*>* op) { return (*op)(this); }\
4
+ virtual Statement* perform(Operation<Statement*>* op) { return (*op)(this); }\
5
+ virtual Expression* perform(Operation<Expression*>* op) { return (*op)(this); }\
6
+ virtual Selector* perform(Operation<Selector*>* op) { return (*op)(this); }\
7
+ virtual string perform(Operation<string>* op) { return (*op)(this); }\
8
+ virtual Sass_Value* perform(Operation<Sass_Value*>* op) { return (*op)(this); }
9
+
10
+ #define ADD_PROPERTY(type, name)\
11
+ protected:\
12
+ type name##_;\
13
+ public:\
14
+ type name() const { return name##_; }\
15
+ type name(type name##__) { return name##_ = name##__; }\
16
+ private:
@@ -0,0 +1,87 @@
1
+ #define SASS_AST_FACTORY
2
+
3
+ #include <vector>
4
+
5
+ #ifndef SASS_AST
6
+ #include "ast.hpp"
7
+ #endif
8
+
9
+ namespace Sass {
10
+ using namespace std;
11
+
12
+ class AST_Factory {
13
+ vector<AST_Node*> nodes;
14
+ public:
15
+ // statements
16
+ Block* new_Block(string p, size_t l, size_t s = 0, bool r = false);
17
+ Ruleset* new_Ruleset(string p, size_t l, Selector* s, Block* b);
18
+ Propset* new_Propset(string p, size_t l, String* pf, Block* b);
19
+ Feature_Query* new_Feature_Query(string p, size_t l, Feature_Query* f, Block* b);
20
+ Media_Query* new_Media_Query(string p, size_t l, List* q, Block* b);
21
+ At_Rule* new_At_Rule(string p, size_t l, string kwd, Selector* sel, Block* b);
22
+ Declaration* new_Declaration(string p, size_t l, String* prop, List* vals);
23
+ Assignment* new_Assignment(string p, size_t l, string var, Expression* val, bool guarded = false);
24
+ Import<Function_Call*>* new_CSS_Import(string p, size_t l, Function_Call* loc);
25
+ Import<String*>* new_SASS_Import(string p, size_t l, String* loc);
26
+ Warning* new_Warning(string p, size_t l, Expression* msg);
27
+ Error* new_Error(string p, size_t l, Expression* msg);
28
+ Debug* new_Debug(string p, size_t l, Expression* val);
29
+ Comment* new_Comment(string p, size_t l, String* txt);
30
+ If* new_If(string p, size_t l, Expression* pred, Block* con, Block* alt = 0);
31
+ For* new_For(string p, size_t l, string var, Expression* lo, Expression* hi, Block* b, bool inc);
32
+ Each* new_Each(string p, size_t l, vector<string> vars, Expression* lst, Block* b);
33
+ While* new_While(string p, size_t l, Expression* pred, Block* b);
34
+ Extension* new_Extension(string p, size_t l, Selector* s);
35
+ Definition<MIXIN>* new_Mixin_Definition(string p, size_t l, string n, Parameters* params, Block* b);
36
+ Definition<FUNCTION>* new_Function_Definition(string p, size_t l, string n, Parameters* params, Block* b);
37
+ Mixin_Call* new_Mixin_Call(string p, size_t l, string n, Arguments* args, Block* b = 0);
38
+ // expressions
39
+ List* new_List(string p, size_t l, size_t size = 0, List::Separator sep = List::space, bool argl = false);
40
+ Map* new_Map(string p, size_t l, size_t size = 0);
41
+ Binary_Expression<AND>* new_And(string p, size_t l, Expression* lhs, Expression* rhs);
42
+ Binary_Expression<OR>* new_Or(string p, size_t l, Expression* lhs, Expression* rhs);
43
+ Binary_Expression<EQ>* new_Eq(string p, size_t l, Expression* lhs, Expression* rhs);
44
+ Binary_Expression<NEQ>* new_Neq(string p, size_t l, Expression* lhs, Expression* rhs);
45
+ Binary_Expression<GT>* new_Gt(string p, size_t l, Expression* lhs, Expression* rhs);
46
+ Binary_Expression<GTE>* new_Gte(string p, size_t l, Expression* lhs, Expression* rhs);
47
+ Binary_Expression<LT>* new_Lt(string p, size_t l, Expression* lhs, Expression* rhs);
48
+ Binary_Expression<LTE>* new_Lte(string p, size_t l, Expression* lhs, Expression* rhs);
49
+ Binary_Expression<ADD>* new_Add(string p, size_t l, Expression* lhs, Expression* rhs);
50
+ Binary_Expression<SUB>* new_Sub(string p, size_t l, Expression* lhs, Expression* rhs);
51
+ Binary_Expression<MUL>* new_Mul(string p, size_t l, Expression* lhs, Expression* rhs);
52
+ Binary_Expression<DIV>* new_Div(string p, size_t l, Expression* lhs, Expression* rhs);
53
+ Negation* new_Negation(string p, size_t l, Expression* o);
54
+ Function_Call* new_Function_Call(string p, size_t l, String* n, Arguments* args);
55
+ Variable* new_Variable(string p, size_t l, string n);
56
+ Textual<NUMBER>* new_Textual_Number(string p, size_t l, string val);
57
+ Textual<PERCENTAGE>* new_Textual_Percentage(string p, size_t l, string val);
58
+ Textual<DIMENSION>* new_Textual_Dimension(string p, size_t l, string val);
59
+ Textual<HEX>* new_Textual_Hex(string p, size_t l, string val);
60
+ Number* new_Number(string p, size_t l, double val);
61
+ Percentage* new_Percentage(string p, size_t l, double val);
62
+ Dimension* new_Dimension(string p, size_t l, double val, string unit);
63
+ Color* new_Color(string p, size_t l, double r, double g, double b, double a = 1, string disp = "");
64
+ Boolean* new_Boolean(string p, size_t l, bool val);
65
+ String_Schema* new_String_Schema(string p, size_t l, size_t size = 0);
66
+ String_Constant* new_String_Constant(string p, size_t l, string val);
67
+ String_Constant* new_String_Constant(string p, size_t l, const char* beg);
68
+ String_Constant* new_String_Constant(string p, size_t l, const char* beg, const char* end);
69
+ Feature_Query_Condition* new_Feature_Query_Condition(string p, size_t l, String* f, Expression* v);
70
+ Media_Expression* new_Media_Expression(string p, size_t l, String* f, Expression* v);
71
+ // parameters and arguments
72
+ Parameter* new_Parameter(string p, size_t l, string n, Expression* def = 0, bool rest = false);
73
+ Parameters* new_Parameters(string p, size_t l);
74
+ Argument* new_Argument(string p, size_t l, Expression* val, string n = "", bool rest = false);
75
+ Arguments* new_Arguments(string p, size_t l);
76
+ // selectors
77
+ Selector_Schema* new_Selector_Schema(string p, size_t l, String* c);
78
+ Simple_Selector* new_Simple_Selector(string p, size_t l, string c);
79
+ Reference_Selector* new_Reference_Selector(string p, size_t l);
80
+ Placeholder_Selector* new_Placeholder_Selector(string p, size_t l, string n);
81
+ Pseudo_Selector* new_Pseudo_Selector(string p, size_t l, string n, Expression* expr = 0);
82
+ Wrapped_Selector* new_Wrapped_Selector(string p, size_t l, string n, Simple_Base* sel);
83
+ Compound_Selector* new_Compound_Selector(string p, size_t l, size_t s = 0);
84
+ Complex_Selector* new_Complex_Selector(string p, size_t l, Complex_Selector::Combinator c, Complex_Selector* ctx, Compound_Selector* sel);
85
+ Selector_List* new_Selector_List(string p, size_t l, size_t s = 0);
86
+ };
87
+ }
@@ -0,0 +1,72 @@
1
+ /////////////////////////////////////////////
2
+ // Forward declarations for the AST visitors.
3
+ /////////////////////////////////////////////
4
+ namespace Sass {
5
+
6
+ class AST_Node;
7
+ // statements
8
+ class Statement;
9
+ class Block;
10
+ class Ruleset;
11
+ class Propset;
12
+ class Media_Block;
13
+ class Feature_Block;
14
+ class At_Rule;
15
+ class Declaration;
16
+ class Assignment;
17
+ class Import;
18
+ class Import_Stub;
19
+ class Warning;
20
+ class Error;
21
+ class Debug;
22
+ class Comment;
23
+ class If;
24
+ class For;
25
+ class Each;
26
+ class While;
27
+ class Return;
28
+ class Content;
29
+ class Extension;
30
+ class Definition;
31
+ class Mixin_Call;
32
+ // expressions
33
+ class Expression;
34
+ class List;
35
+ class Map;
36
+ class Binary_Expression;
37
+ class Unary_Expression;
38
+ class Function_Call;
39
+ class Function_Call_Schema;
40
+ class Variable;
41
+ class Textual;
42
+ class Number;
43
+ class Color;
44
+ class Boolean;
45
+ class String_Schema;
46
+ class String;
47
+ class String_Constant;
48
+ class Media_Query;
49
+ class Media_Query_Expression;
50
+ class Feature_Query;
51
+ class Feature_Query_Condition;
52
+ class Null;
53
+ // parameters and arguments
54
+ class Parameter;
55
+ class Parameters;
56
+ class Argument;
57
+ class Arguments;
58
+ // selectors
59
+ class Selector;
60
+ class Selector_Schema;
61
+ class Selector_Reference;
62
+ class Selector_Placeholder;
63
+ class Type_Selector;
64
+ class Selector_Qualifier;
65
+ class Attribute_Selector;
66
+ class Pseudo_Selector;
67
+ class Wrapped_Selector;
68
+ class Compound_Selector;
69
+ class Complex_Selector;
70
+ class Selector_List;
71
+
72
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ cencode.h - c header for a base64 encoding algorithm
3
+
4
+ This is part of the libb64 project, and has been placed in the public domain.
5
+ For details, see http://sourceforge.net/projects/libb64
6
+ */
7
+
8
+ #ifndef BASE64_CENCODE_H
9
+ #define BASE64_CENCODE_H
10
+
11
+ typedef enum
12
+ {
13
+ step_A, step_B, step_C
14
+ } base64_encodestep;
15
+
16
+ typedef struct
17
+ {
18
+ base64_encodestep step;
19
+ char result;
20
+ int stepcount;
21
+ } base64_encodestate;
22
+
23
+ void base64_init_encodestate(base64_encodestate* state_in);
24
+
25
+ char base64_encode_value(char value_in);
26
+
27
+ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
28
+
29
+ int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
30
+
31
+ #endif /* BASE64_CENCODE_H */
32
+
@@ -0,0 +1,77 @@
1
+ // :mode=c++:
2
+ /*
3
+ encode.h - c++ wrapper for a base64 encoding algorithm
4
+
5
+ This is part of the libb64 project, and has been placed in the public domain.
6
+ For details, see http://sourceforge.net/projects/libb64
7
+ */
8
+ #ifndef BASE64_ENCODE_H
9
+ #define BASE64_ENCODE_H
10
+
11
+ #include <iostream>
12
+
13
+ namespace base64
14
+ {
15
+ extern "C"
16
+ {
17
+ #include "cencode.h"
18
+ }
19
+
20
+ struct encoder
21
+ {
22
+ base64_encodestate _state;
23
+ int _buffersize;
24
+
25
+ encoder(int buffersize_in = BUFFERSIZE)
26
+ : _buffersize(buffersize_in)
27
+ {}
28
+
29
+ int encode(char value_in)
30
+ {
31
+ return base64_encode_value(value_in);
32
+ }
33
+
34
+ int encode(const char* code_in, const int length_in, char* plaintext_out)
35
+ {
36
+ return base64_encode_block(code_in, length_in, plaintext_out, &_state);
37
+ }
38
+
39
+ int encode_end(char* plaintext_out)
40
+ {
41
+ return base64_encode_blockend(plaintext_out, &_state);
42
+ }
43
+
44
+ void encode(std::istream& istream_in, std::ostream& ostream_in)
45
+ {
46
+ base64_init_encodestate(&_state);
47
+ //
48
+ const int N = _buffersize;
49
+ char* plaintext = new char[N];
50
+ char* code = new char[2*N];
51
+ int plainlength;
52
+ int codelength;
53
+
54
+ do
55
+ {
56
+ istream_in.read(plaintext, N);
57
+ plainlength = istream_in.gcount();
58
+ //
59
+ codelength = encode(plaintext, plainlength, code);
60
+ ostream_in.write(code, codelength);
61
+ }
62
+ while (istream_in.good() && plainlength > 0);
63
+
64
+ codelength = encode_end(code);
65
+ ostream_in.write(code, codelength);
66
+ //
67
+ base64_init_encodestate(&_state);
68
+
69
+ delete [] code;
70
+ delete [] plaintext;
71
+ }
72
+ };
73
+
74
+ } // namespace base64
75
+
76
+ #endif // BASE64_ENCODE_H
77
+
@@ -0,0 +1,81 @@
1
+ #define SASS_BACKTRACE
2
+
3
+ #include <sstream>
4
+
5
+ #ifndef SASS_POSITION
6
+ #include "position.hpp"
7
+ #endif
8
+
9
+ #ifndef SASS_FILE
10
+ #include "file.hpp"
11
+ #endif
12
+
13
+ namespace Sass {
14
+
15
+ using namespace std;
16
+
17
+ struct Backtrace {
18
+
19
+ Backtrace* parent;
20
+ string path;
21
+ Position position;
22
+ string caller;
23
+
24
+ Backtrace(Backtrace* prn, string pth, Position position, string c)
25
+ : parent(prn),
26
+ path(pth),
27
+ position(position),
28
+ caller(c)
29
+ { }
30
+
31
+ string to_string(bool warning = false)
32
+ {
33
+ size_t i = -1;
34
+ stringstream ss;
35
+ string cwd(Sass::File::get_cwd());
36
+ Backtrace* this_point = this;
37
+
38
+ if (!warning) ss << endl << "Backtrace:";
39
+ // the first tracepoint (which is parent-less) is an empty placeholder
40
+ while (this_point->parent) {
41
+
42
+ // make path relative to the current directory
43
+ string rel_path(Sass::File::resolve_relative_path(this_point->path, cwd, cwd));
44
+
45
+ if (warning) {
46
+ ss << endl
47
+ << "\t"
48
+ << (++i == 0 ? "on" : "from")
49
+ << " line "
50
+ << this_point->position.line
51
+ << " of "
52
+ << rel_path;
53
+ } else {
54
+ ss << endl
55
+ << "\t"
56
+ << rel_path
57
+ << ":"
58
+ << this_point->position.line
59
+ << this_point->parent->caller;
60
+ }
61
+
62
+ this_point = this_point->parent;
63
+ }
64
+
65
+ return ss.str();
66
+ }
67
+
68
+ size_t depth()
69
+ {
70
+ size_t d = 0;
71
+ Backtrace* p = parent;
72
+ while (p) {
73
+ ++d;
74
+ p = p->parent;
75
+ }
76
+ return d-1;
77
+ }
78
+
79
+ };
80
+
81
+ }
@@ -0,0 +1,43 @@
1
+ #include "base64vlq.hpp"
2
+
3
+ namespace Sass {
4
+
5
+ string Base64VLQ::encode(const int number) const
6
+ {
7
+ string encoded = "";
8
+
9
+ int vlq = to_vlq_signed(number);
10
+
11
+ do {
12
+ int digit = vlq & VLQ_BASE_MASK;
13
+ vlq >>= VLQ_BASE_SHIFT;
14
+ if (vlq > 0) {
15
+ digit |= VLQ_CONTINUATION_BIT;
16
+ }
17
+ encoded += base64_encode(digit);
18
+ } while (vlq > 0);
19
+
20
+ return encoded;
21
+ }
22
+
23
+ char Base64VLQ::base64_encode(const int number) const
24
+ {
25
+ int index = number;
26
+ if (index < 0) index = 0;
27
+ if (index > 63) index = 63;
28
+ return CHARACTERS[index];
29
+ }
30
+
31
+ int Base64VLQ::to_vlq_signed(const int number) const
32
+ {
33
+ return (number < 0) ? ((-number) << 1) + 1 : (number << 1) + 0;
34
+ }
35
+
36
+ const char* Base64VLQ::CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
37
+
38
+ const int Base64VLQ::VLQ_BASE_SHIFT = 5;
39
+ const int Base64VLQ::VLQ_BASE = 1 << VLQ_BASE_SHIFT;
40
+ const int Base64VLQ::VLQ_BASE_MASK = VLQ_BASE - 1;
41
+ const int Base64VLQ::VLQ_CONTINUATION_BIT = VLQ_BASE;
42
+
43
+ }
@@ -0,0 +1,28 @@
1
+ #define SASS_BASE64VLQ
2
+
3
+ #include <string>
4
+
5
+ namespace Sass {
6
+ using std::string;
7
+
8
+ class Base64VLQ {
9
+
10
+ public:
11
+
12
+ string encode(const int number) const;
13
+
14
+ private:
15
+
16
+ char base64_encode(const int number) const;
17
+
18
+ int to_vlq_signed(const int number) const;
19
+
20
+ static const char* CHARACTERS;
21
+
22
+ static const int VLQ_BASE_SHIFT;
23
+ static const int VLQ_BASE;
24
+ static const int VLQ_BASE_MASK;
25
+ static const int VLQ_CONTINUATION_BIT;
26
+ };
27
+
28
+ }
@@ -0,0 +1,187 @@
1
+ #include "bind.hpp"
2
+ #include "ast.hpp"
3
+ #include "context.hpp"
4
+ #include "eval.hpp"
5
+ #include <map>
6
+ #include <iostream>
7
+ #include <sstream>
8
+ #include "to_string.hpp"
9
+
10
+ namespace Sass {
11
+ using namespace std;
12
+
13
+ void bind(string callee, Parameters* ps, Arguments* as, Context& ctx, Env* env, Eval* eval)
14
+ {
15
+ map<string, Parameter*> param_map;
16
+
17
+ // Set up a map to ensure named arguments refer to actual parameters. Also
18
+ // eval each default value left-to-right, wrt env, populating env as we go.
19
+ for (size_t i = 0, L = ps->length(); i < L; ++i) {
20
+ Parameter* p = (*ps)[i];
21
+ param_map[p->name()] = p;
22
+ // if (p->default_value()) {
23
+ // env->current_frame()[p->name()] = p->default_value()->perform(eval->with(env));
24
+ // }
25
+ }
26
+
27
+ // plug in all args; if we have leftover params, deal with it later
28
+ size_t ip = 0, LP = ps->length();
29
+ size_t ia = 0, LA = as->length();
30
+ while (ia < LA) {
31
+ if (ip >= LP) {
32
+ stringstream msg;
33
+ msg << callee << " only takes " << LP << " arguments; "
34
+ << "given " << LA;
35
+ error(msg.str(), as->path(), as->position());
36
+ }
37
+ Parameter* p = (*ps)[ip];
38
+ Argument* a = (*as)[ia];
39
+
40
+ // If the current parameter is the rest parameter, process and break the loop
41
+ if (p->is_rest_parameter()) {
42
+ if (a->is_rest_argument()) {
43
+ // rest param and rest arg -- just add one to the other
44
+ if (env->current_frame_has(p->name())) {
45
+ *static_cast<List*>(env->current_frame()[p->name()])
46
+ += static_cast<List*>(a->value());
47
+ }
48
+ else {
49
+ env->current_frame()[p->name()] = a->value();
50
+ }
51
+ } else {
52
+
53
+ // copy all remaining arguments into the rest parameter, preserving names
54
+ List* arglist = new (ctx.mem) List(p->path(),
55
+ p->position(),
56
+ 0,
57
+ List::COMMA,
58
+ true);
59
+ env->current_frame()[p->name()] = arglist;
60
+ while (ia < LA) {
61
+ a = (*as)[ia];
62
+ (*arglist) << new (ctx.mem) Argument(a->path(),
63
+ a->position(),
64
+ a->value(),
65
+ a->name(),
66
+ false);
67
+ ++ia;
68
+ }
69
+ }
70
+ ++ip;
71
+ break;
72
+ }
73
+
74
+ // If the current argument is the rest argument, extract a value for processing
75
+ else if (a->is_rest_argument()) {
76
+ // normal param and rest arg
77
+ List* arglist = static_cast<List*>(a->value());
78
+ // empty rest arg - treat all args as default values
79
+ if (!arglist->length()) {
80
+ break;
81
+ }
82
+ // otherwise move one of the rest args into the param, converting to argument if necessary
83
+ if (arglist->is_arglist()) {
84
+ a = static_cast<Argument*>((*arglist)[0]);
85
+ } else {
86
+ Expression* a_to_convert = (*arglist)[0];
87
+ a = new (ctx.mem) Argument(a_to_convert->path(), a_to_convert->position(), a_to_convert, "", false);
88
+ }
89
+ arglist->elements().erase(arglist->elements().begin());
90
+ if (!arglist->length() || (!arglist->is_arglist() && ip + 1 == LP)) {
91
+ ++ia;
92
+ }
93
+ } else if (a->is_keyword_argument()) {
94
+ Map* argmap = static_cast<Map*>(a->value());
95
+
96
+ for (auto key : argmap->keys()) {
97
+ string name = "$" + unquote(static_cast<String_Constant*>(key)->value());
98
+
99
+ if (!param_map.count(name)) {
100
+ stringstream msg;
101
+ msg << callee << " has no parameter named " << name;
102
+ error(msg.str(), a->path(), a->position());
103
+ }
104
+ env->current_frame()[name] = argmap->at(key);
105
+ }
106
+ ++ia;
107
+ continue;
108
+ } else {
109
+ ++ia;
110
+ }
111
+
112
+ if (a->name().empty()) {
113
+ if (env->current_frame_has(p->name())) {
114
+ stringstream msg;
115
+ msg << "parameter " << p->name()
116
+ << " provided more than once in call to " << callee;
117
+ error(msg.str(), a->path(), a->position());
118
+ }
119
+ // ordinal arg -- bind it to the next param
120
+ env->current_frame()[p->name()] = a->value();
121
+ ++ip;
122
+ }
123
+ else {
124
+ // named arg -- bind it to the appropriately named param
125
+ if (!param_map.count(a->name())) {
126
+ stringstream msg;
127
+ msg << callee << " has no parameter named " << a->name();
128
+ error(msg.str(), a->path(), a->position());
129
+ }
130
+ if (param_map[a->name()]->is_rest_parameter()) {
131
+ stringstream msg;
132
+ msg << "argument " << a->name() << " of " << callee
133
+ << "cannot be used as named argument";
134
+ error(msg.str(), a->path(), a->position());
135
+ }
136
+ if (env->current_frame_has(a->name())) {
137
+ stringstream msg;
138
+ msg << "parameter " << p->name()
139
+ << "provided more than once in call to " << callee;
140
+ error(msg.str(), a->path(), a->position());
141
+ }
142
+ env->current_frame()[a->name()] = a->value();
143
+ }
144
+ }
145
+
146
+ // If we make it here, we're out of args but may have leftover params.
147
+ // That's only okay if they have default values, or were already bound by
148
+ // named arguments, or if it's a single rest-param.
149
+ for (size_t i = ip; i < LP; ++i) {
150
+ To_String to_string;
151
+ Parameter* leftover = (*ps)[i];
152
+ // cerr << "env for default params:" << endl;
153
+ // env->print();
154
+ // cerr << "********" << endl;
155
+ if (!env->current_frame_has(leftover->name())) {
156
+ if (leftover->is_rest_parameter()) {
157
+ env->current_frame()[leftover->name()] = new (ctx.mem) List(leftover->path(),
158
+ leftover->position(),
159
+ 0,
160
+ List::COMMA,
161
+ true);
162
+ }
163
+ else if (leftover->default_value()) {
164
+ // make sure to eval the default value in the env that we've been populating
165
+ Env* old_env = eval->env;
166
+ Backtrace* old_bt = eval->backtrace;
167
+ Expression* dv = leftover->default_value()->perform(eval->with(env, eval->backtrace));
168
+ eval->env = old_env;
169
+ eval->backtrace = old_bt;
170
+ // dv->perform(&to_string);
171
+ env->current_frame()[leftover->name()] = dv;
172
+ }
173
+ else {
174
+ // param is unbound and has no default value -- error
175
+ stringstream msg;
176
+ msg << "required parameter " << leftover->name()
177
+ << " is missing in call to " << callee;
178
+ error(msg.str(), as->path(), as->position());
179
+ }
180
+ }
181
+ }
182
+
183
+ return;
184
+ }
185
+
186
+
187
+ }