Current Version: 1.0.10
Project Name: csspp
compiler.h
Go to the documentation of this file.
1 #ifndef CSSPP_COMPILER_H
2 #define CSSPP_COMPILER_H
3 // CSS Preprocessor
4 // Copyright (C) 2015-2016 Made to Order Software Corp.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 #include "csspp/expression.h"
21 
22 namespace csspp
23 {
24 
25 class compiler
26 {
27 public:
28  compiler(bool validating = false);
29 
30  void set_root(node::pointer_t root);
31  node::pointer_t get_root() const;
32 
34 
35  void set_date_time_variables(time_t now);
36  void set_empty_on_undefined_variable(bool const empty_on_undefined_variable);
37  void set_no_logo(bool no_logo = true);
38 
39  void clear_paths();
40  void add_path(std::string const & path);
41 
42  void compile(bool bare);
43 
44  std::string find_file(std::string const & script_name);
45 
46 private:
47  friend class safe_parents_t;
48  friend class safe_compiler_state_t;
49 
50  typedef std::vector<std::string> string_vector_t;
51  typedef std::map<std::string, node::pointer_t> validator_script_vector_t;
52 
54  {
55  public:
56  void set_root(node::pointer_t root);
57  node::pointer_t get_root() const;
58 
59  void clear_paths();
60  void add_path(std::string const & path);
61  void set_paths(compiler_state_t const & state);
62 
63  void push_parent(node::pointer_t parent);
64  void pop_parent();
65  bool empty_parents() const;
67  void set_variable(node::pointer_t variable, node::pointer_t value, bool global) const;
68 
69  // implement the expression_variables_interface
70  virtual node::pointer_t get_variable(std::string const & variable_name, bool global_only = false) const;
72  void set_empty_on_undefined_variable(bool const empty_on_undefined_variable);
74 
75  std::string find_file(std::string const & script_name);
76 
77  private:
82  };
83 
84  void add_header_and_footer();
85 
86  void compile(node::pointer_t n);
92  node::pointer_t compile_expression(node::pointer_t n, bool skip_whitespace, bool list_of_expressions);
93 
94  void replace_import(node::pointer_t parent, node::pointer_t import, size_t & idx);
95  void replace_at_keyword(node::pointer_t parent, node::pointer_t n, size_t & idx);
97  void replace_if(node::pointer_t parent, node::pointer_t n, size_t idx);
98  void replace_else(node::pointer_t parent, node::pointer_t n, size_t idx);
100 
104  void replace_variable(node::pointer_t parent, node::pointer_t n, size_t & idx);
110  void expand_nested_declarations(std::string const & name, node::pointer_t parent, node::pointer_t & root, node::pointer_t n);
111 
112  bool selector_attribute_check(node::pointer_t parent, size_t & parent_pos, node::pointer_t n);
113  bool selector_simple_term(node::pointer_t n, size_t & pos);
114  bool selector_term(node::pointer_t n, size_t & pos);
115  bool selector_list(node::pointer_t n, size_t & pos);
117 
118  void set_validation_script(std::string const & script_name);
119  void add_validation_variable(std::string const & variable_name, node::pointer_t value);
120  bool run_validation(bool check_only);
121 
123 
125  node::pointer_t f_current_validation_script; // last script selected by set_validator_script()
127  bool f_compiler_validating = false;
128  bool f_no_logo = false;
129 };
130 
131 } // namespace csspp
132 #endif
133 // #ifndef CSSPP_COMPILER_H
134 
135 // Local Variables:
136 // mode: cpp
137 // indent-tabs-mode: nil
138 // c-basic-offset: 4
139 // tab-width: 4
140 // End:
141 
142 // vim: ts=4 sw=4 et
void prepare_function_arguments(node::pointer_t var)
Definition: compiler.cpp:2209
std::vector< std::string > string_vector_t
Definition: compiler.h:50
void replace_else(node::pointer_t parent, node::pointer_t n, size_t idx)
Definition: compiler.cpp:2454
void push_parent(node::pointer_t parent)
Definition: compiler.cpp:115
node::pointer_t get_previous_parent() const
Definition: compiler.cpp:130
void set_no_logo(bool no_logo=true)
Definition: compiler.cpp:499
void replace_if(node::pointer_t parent, node::pointer_t n, size_t idx)
Definition: compiler.cpp:2403
void expand_nested_components(node::pointer_t n)
Definition: compiler.cpp:3571
std::map< std::string, node::pointer_t > validator_script_vector_t
Definition: compiler.h:51
std::vector< node::pointer_t > node_vector_t
Definition: node.h:203
void expand_nested_rules(node::pointer_t parent, node::pointer_t root, node::pointer_t &last, node::pointer_t n)
Definition: compiler.cpp:3639
bool run_validation(bool check_only)
Definition: compiler.cpp:3528
std::shared_ptr< node > pointer_t
Definition: node.h:122
void set_variable(node::pointer_t n)
Definition: compiler.cpp:2088
node::pointer_t get_result() const
Definition: compiler.cpp:415
void compile_component_value(node::pointer_t n)
Definition: compiler.cpp:653
void add_path(std::string const &path)
Definition: compiler.cpp:509
void expand_nested_declarations(std::string const &name, node::pointer_t parent, node::pointer_t &root, node::pointer_t n)
Definition: compiler.cpp:3787
void compile_declaration_values(node::pointer_t declaration)
Definition: compiler.cpp:1084
bool selector_term(node::pointer_t n, size_t &pos)
Definition: compiler.cpp:3116
node::pointer_t compile_expression(node::pointer_t n, bool skip_whitespace, bool list_of_expressions)
void remove_empty_rules(node::pointer_t n)
Definition: compiler.cpp:1637
void compile(bool bare)
Definition: compiler.cpp:514
void set_validation_script(std::string const &script_name)
Definition: compiler.cpp:3439
virtual node::pointer_t execute_user_function(node::pointer_t func)
Definition: compiler.cpp:203
void set_root(node::pointer_t root)
Definition: compiler.cpp:405
void set_empty_on_undefined_variable(bool const empty_on_undefined_variable)
Definition: compiler.cpp:349
virtual node::pointer_t get_variable(std::string const &variable_name, bool global_only=false) const
Definition: compiler.cpp:171
void mark_selectors(node::pointer_t n)
Definition: compiler.cpp:1589
bool f_compiler_validating
Definition: compiler.h:127
void set_paths(compiler_state_t const &state)
Definition: compiler.cpp:109
void add_path(std::string const &path)
Definition: compiler.cpp:104
std::string find_file(std::string const &script_name)
Definition: compiler.cpp:359
void compile_declaration(node::pointer_t n)
Definition: compiler.cpp:864
bool selector_attribute_check(node::pointer_t parent, size_t &parent_pos, node::pointer_t n)
Definition: compiler.cpp:2684
node::pointer_t f_current_validation_script
Definition: compiler.h:125
node::pointer_t get_root() const
Definition: compiler.cpp:94
void replace_variables(node::pointer_t n)
Definition: compiler.cpp:1684
std::string find_file(std::string const &script_name)
Definition: compiler.cpp:3434
void set_root(node::pointer_t root)
Definition: compiler.cpp:88
void add_header_and_footer()
Definition: compiler.cpp:566
void replace_variable(node::pointer_t parent, node::pointer_t n, size_t &idx)
Definition: compiler.cpp:1802
validator_script_vector_t f_validator_scripts
Definition: compiler.h:124
bool selector_list(node::pointer_t n, size_t &pos)
Definition: compiler.cpp:3279
void set_empty_on_undefined_variable(bool const empty_on_undefined_variable)
Definition: compiler.cpp:494
bool get_empty_on_undefined_variable() const
Definition: compiler.cpp:354
node::pointer_t f_return_result
Definition: compiler.h:126
void compile_at_keyword(node::pointer_t n)
Definition: compiler.cpp:1149
node::pointer_t at_keyword_expression(node::pointer_t n)
Definition: compiler.cpp:2390
void replace_variables_in_comment(node::pointer_t n)
Definition: compiler.cpp:2582
void add_validation_variable(std::string const &variable_name, node::pointer_t value)
Definition: compiler.cpp:3512
void set_variable(node::pointer_t variable, node::pointer_t value, bool global) const
Definition: compiler.cpp:141
compiler(bool validating=false)
Definition: compiler.cpp:399
node::pointer_t get_root() const
Definition: compiler.cpp:410
void replace_import(node::pointer_t parent, node::pointer_t import, size_t &idx)
Definition: compiler.cpp:1351
void clear_paths()
Definition: compiler.cpp:504
void handle_mixin(node::pointer_t n)
Definition: compiler.cpp:1527
bool selector_simple_term(node::pointer_t n, size_t &pos)
Definition: compiler.cpp:2832
void replace_at_keyword(node::pointer_t parent, node::pointer_t n, size_t &idx)
Definition: compiler.cpp:2282
void compile_qualified_rule(node::pointer_t n)
Definition: compiler.cpp:796
compiler_state_t f_state
Definition: compiler.h:122
void set_date_time_variables(time_t now)
Definition: compiler.cpp:420
bool parse_selector(node::pointer_t n)
Definition: compiler.cpp:3361

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.