Current Version: 1.0.20
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-2018 Made to Order Software Corp. All Rights Reserved
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 
55  {
56  public:
57  void set_root(node::pointer_t root);
58  node::pointer_t get_root() const;
59 
60  void clear_paths();
61  void add_path(std::string const & path);
62  void set_paths(compiler_state_t const & state);
63 
64  void push_parent(node::pointer_t parent);
65  void pop_parent();
66  bool empty_parents() const;
68  void set_variable(node::pointer_t variable, node::pointer_t value, bool global) const;
69 
70  // implement the expression_variables_interface
71  virtual node::pointer_t get_variable(std::string const & variable_name, bool global_only = false) const;
73  void set_empty_on_undefined_variable(bool const empty_on_undefined_variable);
75 
76  std::string find_file(std::string const & script_name);
77 
78  private:
79  string_vector_t f_paths = string_vector_t();
83  };
84 
85  void add_header_and_footer();
86 
87  void compile(node::pointer_t n);
93  node::pointer_t compile_expression(node::pointer_t n, bool skip_whitespace, bool list_of_expressions);
94 
95  void replace_import(node::pointer_t parent, node::pointer_t import, size_t & idx);
96  void replace_at_keyword(node::pointer_t parent, node::pointer_t n, size_t & idx);
98  void replace_if(node::pointer_t parent, node::pointer_t n, size_t idx);
99  void replace_else(node::pointer_t parent, node::pointer_t n, size_t idx);
101 
105  void replace_variable(node::pointer_t parent, node::pointer_t n, size_t & idx);
111  void expand_nested_declarations(std::string const & name, node::pointer_t parent, node::pointer_t & root, node::pointer_t n);
112 
113  bool selector_attribute_check(node::pointer_t parent, size_t & parent_pos, node::pointer_t n);
114  bool selector_simple_term(node::pointer_t n, size_t & pos);
115  bool selector_term(node::pointer_t n, size_t & pos);
116  bool selector_list(node::pointer_t n, size_t & pos);
118 
119  void set_validation_script(std::string const & script_name);
120  void add_validation_variable(std::string const & variable_name, node::pointer_t value);
121  bool run_validation(bool check_only);
122 
124 
125  validator_script_vector_t f_validator_scripts = validator_script_vector_t(); // caching scripts
126  node::pointer_t f_current_validation_script = node::pointer_t(); // last script selected by set_validator_script()
128  bool f_compiler_validating = false;
129  bool f_no_logo = false;
130 };
131 
132 } // namespace csspp
133 #endif
134 // #ifndef CSSPP_COMPILER_H
135 
136 // Local Variables:
137 // mode: cpp
138 // indent-tabs-mode: nil
139 // c-basic-offset: 4
140 // tab-width: 4
141 // End:
142 
143 // vim: ts=4 sw=4 et
void prepare_function_arguments(node::pointer_t var)
Definition: compiler.cpp:2473
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:2718
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:2667
void expand_nested_components(node::pointer_t n)
Definition: compiler.cpp:3843
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:210
void expand_nested_rules(node::pointer_t parent, node::pointer_t root, node::pointer_t &last, node::pointer_t n)
Definition: compiler.cpp:3911
bool run_validation(bool check_only)
Definition: compiler.cpp:3800
std::shared_ptr< node > pointer_t
Definition: node.h:128
node::pointer_t get_result() const
Definition: compiler.cpp:415
The namespace of all the classes in the CSS Preprocessor.
Definition: assembler.cpp:40
void compile_component_value(node::pointer_t n)
Definition: compiler.cpp:663
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:4059
void compile_declaration_values(node::pointer_t declaration)
Definition: compiler.cpp:1094
bool selector_term(node::pointer_t n, size_t &pos)
Definition: compiler.cpp:3380
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:1901
void compile(bool bare)
Definition: compiler.cpp:514
void set_validation_script(std::string const &script_name)
Definition: compiler.cpp:3711
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:1853
bool f_compiler_validating
Definition: compiler.h:128
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:874
bool selector_attribute_check(node::pointer_t parent, size_t &parent_pos, node::pointer_t n)
Definition: compiler.cpp:2948
node::pointer_t f_current_validation_script
Definition: compiler.h:126
node::pointer_t get_root() const
Definition: compiler.cpp:94
void replace_variables(node::pointer_t n)
Definition: compiler.cpp:1948
std::string find_file(std::string const &script_name)
Definition: compiler.cpp:3706
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:2066
validator_script_vector_t f_validator_scripts
Definition: compiler.h:125
bool selector_list(node::pointer_t n, size_t &pos)
Definition: compiler.cpp:3543
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:127
void compile_at_keyword(node::pointer_t n)
Definition: compiler.cpp:1159
node::pointer_t at_keyword_expression(node::pointer_t n)
Definition: compiler.cpp:2654
void replace_variables_in_comment(node::pointer_t n)
Definition: compiler.cpp:2846
void add_validation_variable(std::string const &variable_name, node::pointer_t value)
Definition: compiler.cpp:3784
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:1615
void clear_paths()
Definition: compiler.cpp:504
void handle_mixin(node::pointer_t n)
Definition: compiler.cpp:1791
bool selector_simple_term(node::pointer_t n, size_t &pos)
Definition: compiler.cpp:3096
void replace_at_keyword(node::pointer_t parent, node::pointer_t n, size_t &idx)
Definition: compiler.cpp:2546
void compile_qualified_rule(node::pointer_t n)
Definition: compiler.cpp:806
compiler_state_t f_state
Definition: compiler.h:123
void set_date_time_variables(time_t now)
Definition: compiler.cpp:420
bool parse_selector(node::pointer_t n)
Definition: compiler.cpp:3625

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.