Current Version: 1.0.33
Project Name: csspp
compiler.h
Go to the documentation of this file.
1// Copyright (c) 2015-2025 Made to Order Software Corp. All Rights Reserved
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation; either version 2 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License along
14// with this program; if not, write to the Free Software Foundation, Inc.,
15// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16#pragma once
17
18// self
19//
20#include "csspp/expression.h"
21
22namespace csspp
23{
24
26{
27public:
28 compiler(bool validating = false);
29
30 void set_root(node::pointer_t root);
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
46private:
47 friend class safe_parents_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);
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:
83 };
84
86
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
126 node::pointer_t f_current_validation_script = node::pointer_t(); // last script selected by set_validator_script()
129 bool f_no_logo = false;
130};
131
132} // namespace csspp
133// vim: ts=4 sw=4 et
void set_root(node::pointer_t root)
Definition compiler.cpp:102
void push_parent(node::pointer_t parent)
Definition compiler.cpp:129
bool get_empty_on_undefined_variable() const
Definition compiler.cpp:368
virtual node::pointer_t execute_user_function(node::pointer_t func)
Definition compiler.cpp:217
virtual node::pointer_t get_variable(std::string const &variable_name, bool global_only=false) const
Definition compiler.cpp:185
void add_path(std::string const &path)
Definition compiler.cpp:118
void set_variable(node::pointer_t variable, node::pointer_t value, bool global) const
Definition compiler.cpp:155
void set_paths(compiler_state_t const &state)
Definition compiler.cpp:123
void set_empty_on_undefined_variable(bool const empty_on_undefined_variable)
Definition compiler.cpp:363
node::pointer_t get_root() const
Definition compiler.cpp:108
node::pointer_t get_previous_parent() const
Definition compiler.cpp:144
std::string find_file(std::string const &script_name)
Definition compiler.cpp:373
void replace_else(node::pointer_t parent, node::pointer_t n, size_t idx)
void set_no_logo(bool no_logo=true)
Definition compiler.cpp:513
void replace_if(node::pointer_t parent, node::pointer_t n, size_t idx)
bool selector_term(node::pointer_t n, size_t &pos)
void handle_mixin(node::pointer_t n)
void compile_component_value(node::pointer_t n)
Definition compiler.cpp:677
void expand_nested_rules(node::pointer_t parent, node::pointer_t root, node::pointer_t &last, node::pointer_t n)
void replace_variables_in_comment(node::pointer_t n)
bool parse_selector(node::pointer_t n)
void compile_declaration(node::pointer_t n)
Definition compiler.cpp:888
void replace_variables(node::pointer_t n)
void add_header_and_footer()
Definition compiler.cpp:580
void replace_variable(node::pointer_t parent, node::pointer_t n, size_t &idx)
void add_path(std::string const &path)
Definition compiler.cpp:523
node::pointer_t get_result() const
Definition compiler.cpp:429
void expand_nested_declarations(std::string const &name, node::pointer_t parent, node::pointer_t &root, node::pointer_t n)
node::pointer_t compile_expression(node::pointer_t n, bool skip_whitespace, bool list_of_expressions)
void set_root(node::pointer_t root)
Definition compiler.cpp:419
void prepare_function_arguments(node::pointer_t var)
node::pointer_t at_keyword_expression(node::pointer_t n)
node::pointer_t f_return_result
Definition compiler.h:127
std::vector< std::string > string_vector_t
Definition compiler.h:50
validator_script_vector_t f_validator_scripts
Definition compiler.h:125
void compile_declaration_values(node::pointer_t declaration)
std::string find_file(std::string const &script_name)
std::map< std::string, node::pointer_t > validator_script_vector_t
Definition compiler.h:51
void compile_at_keyword(node::pointer_t n)
void replace_at_keyword(node::pointer_t parent, node::pointer_t n, size_t &idx)
void set_validation_script(std::string const &script_name)
bool selector_simple_term(node::pointer_t n, size_t &pos)
void set_empty_on_undefined_variable(bool const empty_on_undefined_variable)
Definition compiler.cpp:508
bool f_compiler_validating
Definition compiler.h:128
void replace_import(node::pointer_t parent, node::pointer_t import, size_t &idx)
void expand_nested_components(node::pointer_t n)
node::pointer_t f_current_validation_script
Definition compiler.h:126
bool run_validation(bool check_only)
compiler_state_t f_state
Definition compiler.h:123
bool selector_list(node::pointer_t n, size_t &pos)
node::pointer_t get_root() const
Definition compiler.cpp:424
void compile(bool bare)
Definition compiler.cpp:528
void mark_selectors(node::pointer_t n)
void set_date_time_variables(time_t now)
Definition compiler.cpp:434
void compile_qualified_rule(node::pointer_t n)
Definition compiler.cpp:820
void add_validation_variable(std::string const &variable_name, node::pointer_t value)
bool selector_attribute_check(node::pointer_t parent, size_t &parent_pos, node::pointer_t n)
void set_variable(node::pointer_t n)
void remove_empty_rules(node::pointer_t n)
std::shared_ptr< node > pointer_t
Definition node.h:132
The namespace of all the classes in the CSS Preprocessor.
Definition csspp.h:48
std::vector< node::pointer_t > node_vector_t
Definition node.h:214

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.