Current Version: 1.0.33
Project Name: csspp
expr_logical_and.cpp
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
26#include "csspp/expression.h"
27
28#include "csspp/parser.h"
29#include "csspp/unicode_range.h"
30
31#include <algorithm>
32#include <cmath>
33#include <iostream>
34
35namespace csspp
36{
37
55{
56 boolean_t const result(n->to_boolean());
57 if(result == boolean_t::BOOLEAN_INVALID)
58 {
59 error::instance() << n->get_position()
60 << "a boolean expression was expected."
62 }
63 return result == boolean_t::BOOLEAN_TRUE;
64}
65
67{
68 // logical_and: equality
69 // | logical_and IDENTIFIER (='and') equality
70 // | logical_and '&&' equality
71
72 node::pointer_t result(equality());
73 if(!result)
74 {
75 return node::pointer_t();
76 }
77
78 while((f_current->is(node_type_t::IDENTIFIER) && f_current->get_string() == "and")
80 {
81 position pos(f_current->get_position());
82
83 // skip the AND
84 next();
85
87 if(!rhs)
88 {
89 return node::pointer_t();
90 }
91
92 // apply the AND
93 bool const lr(boolean(result));
94 bool const rr(boolean(rhs));
95 result.reset(new node(node_type_t::BOOLEAN, pos));
96 result->set_boolean(lr && rr);
97 }
98
99 return result;
100}
101
102} // namespace csspp
103
104// Local Variables:
105// mode: cpp
106// indent-tabs-mode: nil
107// c-basic-offset: 4
108// tab-width: 4
109// End:
110
111// vim: ts=4 sw=4 et
static error & instance()
Definition error.cpp:77
node::pointer_t equality()
node::pointer_t logical_and()
node::pointer_t f_current
Definition expression.h:155
static bool boolean(node::pointer_t n)
Check whether a node represents true or false.
std::shared_ptr< node > pointer_t
Definition node.h:132
The namespace of all the classes in the CSS Preprocessor.
Definition csspp.h:48
boolean_t
Definition node.h:34
@ BOOLEAN_TRUE
Definition node.h:37
@ BOOLEAN_INVALID
Definition node.h:35

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.