Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 161 lines (145 sloc) 4.346 kb
33c5ecd Aaron Leung Bam! Variable substitution works!
akhleung authored
1 #include <map>
3238f08 Aaron Leung Evaluator is mostly working. Ironing out some intermittent bugs.
akhleung authored
2
3 #ifndef SASS_NODE_INCLUDED
0418884 Aaron Leung More C++ stuff. Don't try to compile the Node stuff yet.
akhleung authored
4 #include "node.hpp"
3238f08 Aaron Leung Evaluator is mostly working. Ironing out some intermittent bugs.
akhleung authored
5 #endif
6
e202133 Aaron Leung Getting the pegs to fit into the holes.
akhleung authored
7 #include "prelexer.hpp"
d235ff2 Aaron Leung Working on handling imports.
akhleung authored
8 #include "context.hpp"
0418884 Aaron Leung More C++ stuff. Don't try to compile the Node stuff yet.
akhleung authored
9
10 namespace Sass {
193110d Aaron Leung Changing the way nodes are stored at the root level. Makes for easier tr...
akhleung authored
11 using std::string;
cefe1e2 Aaron Leung Fleshing out the classes for documents, nodes, and tokens.
akhleung authored
12 using std::vector;
33c5ecd Aaron Leung Bam! Variable substitution works!
akhleung authored
13 using std::map;
a9c4149 Aaron Leung Bam! Robust tokenizing!
akhleung authored
14 using namespace Prelexer;
cefe1e2 Aaron Leung Fleshing out the classes for documents, nodes, and tokens.
akhleung authored
15
0418884 Aaron Leung More C++ stuff. Don't try to compile the Node stuff yet.
akhleung authored
16 struct Document {
a6ae423 Aaron Leung Gah, finally got parsing of comma-separated groups of simple selectors w...
akhleung authored
17 enum CSS_Style { nested, expanded, compact, compressed, echo };
1e47664 Aaron Leung Moving the parsing functions into their own file. Also adding emitter dr...
akhleung authored
18
193110d Aaron Leung Changing the way nodes are stored at the root level. Makes for easier tr...
akhleung authored
19 string path;
0418884 Aaron Leung More C++ stuff. Don't try to compile the Node stuff yet.
akhleung authored
20 char* source;
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
21 const char* position;
5eac82d Aaron Leung Allowing the parser to parse an arbitrary interval rather than all the w...
akhleung authored
22 const char* end;
71c3136 Aaron Leung Improving the node struct, and working on new parsing functionaity.
akhleung authored
23 size_t line_number;
d235ff2 Aaron Leung Working on handling imports.
akhleung authored
24 bool own_source;
8360fd9 Aaron Leung Shelving singleton selector optimization for now. Will pick it back up i...
akhleung authored
25
d235ff2 Aaron Leung Working on handling imports.
akhleung authored
26 Context& context;
33c5ecd Aaron Leung Bam! Variable substitution works!
akhleung authored
27
193110d Aaron Leung Changing the way nodes are stored at the root level. Makes for easier tr...
akhleung authored
28 Node root;
5020e4b Aaron Leung More thorough parsing.
akhleung authored
29 Token lexed;
159728a Aaron Leung Refactoring the Document constructors. Don't try to compile them yet.
akhleung authored
30
31 private:
32 // force the use of the "make_from_..." factory funtions
33 Document(Context& ctx);
bbd5032 Aaron Leung Adding a unit test and fixing some bugs.
akhleung authored
34 ~Document();
159728a Aaron Leung Refactoring the Document constructors. Don't try to compile them yet.
akhleung authored
35 public:
e202133 Aaron Leung Getting the pegs to fit into the holes.
akhleung authored
36 Document(const Document& doc);
159728a Aaron Leung Refactoring the Document constructors. Don't try to compile them yet.
akhleung authored
37
38 static Document make_from_file(Context& ctx, string path);
39 static Document make_from_source_chars(Context& ctx, char* src, string path = "");
40 static Document make_from_token(Context& ctx, Token t, string path = "", size_t line_number = 1);
41
71c3136 Aaron Leung Improving the node struct, and working on new parsing functionaity.
akhleung authored
42 template <prelexer mx>
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
43 const char* peek(const char* start = 0)
5020e4b Aaron Leung More thorough parsing.
akhleung authored
44 {
45 if (!start) start = position;
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
46 const char* after_whitespace;
5020e4b Aaron Leung More thorough parsing.
akhleung authored
47 if (mx == block_comment) {
d544004 Aaron Leung Trying out a different comment scanning method in anticipation of implem...
akhleung authored
48 after_whitespace = // start;
5020e4b Aaron Leung More thorough parsing.
akhleung authored
49 zero_plus< alternatives<spaces, line_comment> >(start);
50 }
3825b29 Aaron Leung Holy crap, the new lookahead functions are working. The parser essential...
akhleung authored
51 else if (/*mx == ancestor_of ||*/ mx == no_spaces) {
a5080f4 Aaron Leung Handling class/id selectors, as well as simple selector sequences consis...
akhleung authored
52 after_whitespace = position;
53 }
3825b29 Aaron Leung Holy crap, the new lookahead functions are working. The parser essential...
akhleung authored
54 else if (mx == spaces || mx == ancestor_of) {
55 after_whitespace = mx(start);
5020e4b Aaron Leung More thorough parsing.
akhleung authored
56 if (after_whitespace) {
57 return after_whitespace;
58 }
59 else {
60 return 0;
61 }
62 }
63 else if (mx == optional_spaces) {
64 after_whitespace = optional_spaces(start);
65 }
66 else {
67 after_whitespace = spaces_and_comments(start);
68 }
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
69 const char* after_token = mx(after_whitespace);
5020e4b Aaron Leung More thorough parsing.
akhleung authored
70 if (after_token) {
71 return after_token;
72 }
73 else {
74 return 0;
75 }
76 }
77
a9c4149 Aaron Leung Bam! Robust tokenizing!
akhleung authored
78 template <prelexer mx>
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
79 const char* lex()
5020e4b Aaron Leung More thorough parsing.
akhleung authored
80 {
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
81 const char* after_whitespace;
3945804 Aaron Leung Better whitespace handling.
akhleung authored
82 if (mx == block_comment) {
d544004 Aaron Leung Trying out a different comment scanning method in anticipation of implem...
akhleung authored
83 after_whitespace = // position;
adf590f Aaron Leung Corrected the whitespace handling when consuming a block comment.
akhleung authored
84 zero_plus< alternatives<spaces, line_comment> >(position);
3945804 Aaron Leung Better whitespace handling.
akhleung authored
85 }
a5080f4 Aaron Leung Handling class/id selectors, as well as simple selector sequences consis...
akhleung authored
86 else if (mx == ancestor_of || mx == no_spaces) {
b9cfc22 Aaron Leung Properly handling selector combinators. Had to account for some subtleti...
akhleung authored
87 after_whitespace = position;
88 }
89 else if (mx == spaces) {
3945804 Aaron Leung Better whitespace handling.
akhleung authored
90 after_whitespace = spaces(position);
91 if (after_whitespace) {
92 line_number += count_interval<'\n'>(position, after_whitespace);
9e8b930 Aaron Leung Finished the node refactor. Required more debugging than I expected.
akhleung authored
93 lexed = Token::make(position, after_whitespace);
5020e4b Aaron Leung More thorough parsing.
akhleung authored
94 return position = after_whitespace;
3945804 Aaron Leung Better whitespace handling.
akhleung authored
95 }
96 else {
5020e4b Aaron Leung More thorough parsing.
akhleung authored
97 return 0;
3945804 Aaron Leung Better whitespace handling.
akhleung authored
98 }
99 }
b47fadb Aaron Leung Successfully parsing and saving statement-level comments. More to come.
akhleung authored
100 else if (mx == optional_spaces) {
101 after_whitespace = optional_spaces(position);
102 }
3945804 Aaron Leung Better whitespace handling.
akhleung authored
103 else {
104 after_whitespace = spaces_and_comments(position);
105 }
c15503a Aaron Leung Trying to get imports to work correctly. Cross-file variables not workin...
akhleung authored
106 const char* after_token = mx(after_whitespace);
a9c4149 Aaron Leung Bam! Robust tokenizing!
akhleung authored
107 if (after_token) {
5020e4b Aaron Leung More thorough parsing.
akhleung authored
108 line_number += count_interval<'\n'>(position, after_token);
9e8b930 Aaron Leung Finished the node refactor. Required more debugging than I expected.
akhleung authored
109 lexed = Token::make(after_whitespace, after_token);
5020e4b Aaron Leung More thorough parsing.
akhleung authored
110 return position = after_token;
a9c4149 Aaron Leung Bam! Robust tokenizing!
akhleung authored
111 }
6c01258 Aaron Leung Tweaks.
akhleung authored
112 else {
5020e4b Aaron Leung More thorough parsing.
akhleung authored
113 return 0;
6c01258 Aaron Leung Tweaks.
akhleung authored
114 }
b47fadb Aaron Leung Successfully parsing and saving statement-level comments. More to come.
akhleung authored
115 }
116
f529037 Aaron Leung Minor tweaks.
akhleung authored
117 void parse_scss();
118 Node parse_import();
c8b9364 Aaron Leung Rolling back to before I started the delayed-evaluation stuff. Didn't ch...
akhleung authored
119 Node parse_include();
a536575 Aaron Leung Adapting the old mixin parsing functions for the new parsing & expansion...
akhleung authored
120 Node parse_mixin_definition();
121 Node parse_mixin_parameters();
de9f259 Aaron Leung Getting things to compile again.
akhleung authored
122 Node parse_parameter();
a536575 Aaron Leung Adapting the old mixin parsing functions for the new parsing & expansion...
akhleung authored
123 Node parse_mixin_call();
c60e12c Aaron Leung Parsing function calls.
akhleung authored
124 Node parse_arguments();
a536575 Aaron Leung Adapting the old mixin parsing functions for the new parsing & expansion...
akhleung authored
125 Node parse_argument();
12ff626 Aaron Leung No longer doing single-pass parsing/expansion. Building up a queue of pe...
akhleung authored
126 Node parse_assignment();
3663a72 Aaron Leung Working on namespaced properties. Still trying to get them to emit corre...
akhleung authored
127 Node parse_propset();
a536575 Aaron Leung Adapting the old mixin parsing functions for the new parsing & expansion...
akhleung authored
128 Node parse_ruleset(bool definition = false);
5020e4b Aaron Leung More thorough parsing.
akhleung authored
129 Node parse_selector_group();
2e42425 Aaron Leung Putting parsing functions in place. Don't try to compile yet.
akhleung authored
130 Node parse_selector();
8360fd9 Aaron Leung Shelving singleton selector optimization for now. Will pick it back up i...
akhleung authored
131 Node parse_selector_combinator();
b9cfc22 Aaron Leung Properly handling selector combinators. Had to account for some subtleti...
akhleung authored
132 Node parse_simple_selector_sequence();
a5080f4 Aaron Leung Handling class/id selectors, as well as simple selector sequences consis...
akhleung authored
133 Node parse_simple_selector();
b8630d7 Aaron Leung Handling pseudo-class and pseudo-elements.
akhleung authored
134 Node parse_pseudo();
7d2dd60 Aaron Leung Working on parsing attribute selectors.
akhleung authored
135 Node parse_attribute_selector();
a536575 Aaron Leung Adapting the old mixin parsing functions for the new parsing & expansion...
akhleung authored
136 Node parse_block(bool definition = false);
c8b9364 Aaron Leung Rolling back to before I started the delayed-evaluation stuff. Didn't ch...
akhleung authored
137 Node parse_rule();
d3b2584 Aaron Leung Parsing and echoing works.
akhleung authored
138 Node parse_values();
c8b9364 Aaron Leung Rolling back to before I started the delayed-evaluation stuff. Didn't ch...
akhleung authored
139 Node parse_list();
140 Node parse_comma_list();
141 Node parse_space_list();
e2c130b Aaron Leung Got logical operators working.
akhleung authored
142 Node parse_disjunction();
143 Node parse_conjunction();
c6394df Aaron Leung Comparison operators.
akhleung authored
144 Node parse_relation();
c8b9364 Aaron Leung Rolling back to before I started the delayed-evaluation stuff. Didn't ch...
akhleung authored
145 Node parse_expression();
146 Node parse_term();
147 Node parse_factor();
148 Node parse_value();
c60e12c Aaron Leung Parsing function calls.
akhleung authored
149 Node parse_function_call();
15b9258 Aaron Leung Shelving the string interpolation stuff. Don't use it.
akhleung authored
150 Node parse_string();
b158033 Aaron Leung Still working on interpolation. Don't try it yet.
akhleung authored
151 Node parse_value_schema();
1e47664 Aaron Leung Moving the parsing functions into their own file. Also adding emitter dr...
akhleung authored
152
3b0663f Aaron Leung More flexible lookahead; provides better compatibility with Sass, and is...
akhleung authored
153 const char* lookahead_for_selector(const char* start = 0);
154
e202133 Aaron Leung Getting the pegs to fit into the holes.
akhleung authored
155 void throw_syntax_error(string message, size_t ln = 0);
156 void throw_read_error(string message, size_t ln = 0);
43ae0e6 Aaron Leung Starting to add error handling.
akhleung authored
157
1e47664 Aaron Leung Moving the parsing functions into their own file. Also adding emitter dr...
akhleung authored
158 string emit_css(CSS_Style style);
193110d Aaron Leung Changing the way nodes are stored at the root level. Makes for easier tr...
akhleung authored
159
0418884 Aaron Leung More C++ stuff. Don't try to compile the Node stuff yet.
akhleung authored
160 };
161 }
Something went wrong with that request. Please try again.