Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / src / emitter.hpp
1 #ifndef SASS_EMITTER_H
2 #define SASS_EMITTER_H
3
4 #include <string>
5 #include "sass.hpp"
6 #include "sass/base.h"
7 #include "source_map.hpp"
8 #include "ast_fwd_decl.hpp"
9
10 namespace Sass {
11   class Context;
12
13   class Emitter {
14
15     public:
16       Emitter(struct Sass_Output_Options& opt);
17       virtual ~Emitter() { }
18
19     protected:
20       OutputBuffer wbuf;
21     public:
22       const std::string& buffer(void) { return wbuf.buffer; }
23       const SourceMap smap(void) { return wbuf.smap; }
24       const OutputBuffer output(void) { return wbuf; }
25       // proxy methods for source maps
26       void add_source_index(size_t idx);
27       void set_filename(const std::string& str);
28       void add_open_mapping(const AST_Node_Ptr node);
29       void add_close_mapping(const AST_Node_Ptr node);
30       void schedule_mapping(const AST_Node_Ptr node);
31       std::string render_srcmap(Context &ctx);
32       ParserState remap(const ParserState& pstate);
33
34     public:
35       struct Sass_Output_Options& opt;
36       size_t indentation;
37       size_t scheduled_space;
38       size_t scheduled_linefeed;
39       bool scheduled_delimiter;
40       AST_Node_Ptr scheduled_mapping;
41
42     public:
43       // output strings different in comments
44       bool in_comment;
45       // selector list does not get linefeeds
46       bool in_wrapped;
47       // lists always get a space after delimiter
48       bool in_media_block;
49       // nested list must not have parentheses
50       bool in_declaration;
51       // nested lists need parentheses
52       bool in_space_array;
53       bool in_comma_array;
54
55     public:
56       // return buffer as std::string
57       std::string get_buffer(void);
58       // flush scheduled space/linefeed
59       Sass_Output_Style output_style(void) const;
60       // add outstanding linefeed
61       void finalize(bool final = true);
62       // flush scheduled space/linefeed
63       void flush_schedules(void);
64       // prepend some text or token to the buffer
65       void prepend_string(const std::string& text);
66       void prepend_output(const OutputBuffer& out);
67       // append some text or token to the buffer
68       void append_string(const std::string& text);
69       // append some white-space only text
70       void append_wspace(const std::string& text);
71       // append some text or token to the buffer
72       // this adds source-mappings for node start and end
73       void append_token(const std::string& text, const AST_Node_Ptr node);
74
75     public: // syntax sugar
76       void append_indentation();
77       void append_optional_space(void);
78       void append_mandatory_space(void);
79       void append_special_linefeed(void);
80       void append_optional_linefeed(void);
81       void append_mandatory_linefeed(void);
82       void append_scope_opener(AST_Node_Ptr node = 0);
83       void append_scope_closer(AST_Node_Ptr node = 0);
84       void append_comma_separator(void);
85       void append_colon_separator(void);
86       void append_delimiter(void);
87
88   };
89
90 }
91
92 #endif