Current Version: 1.0.10
Project Name: csspp
expr_logical_and.cpp
Go to the documentation of this file.
1 // CSS Preprocessor
2 // Copyright (C) 2015-2016 Made to Order Software Corp.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
27 #include "csspp/expression.h"
28 
29 #include "csspp/exceptions.h"
30 #include "csspp/parser.h"
31 #include "csspp/unicode_range.h"
32 
33 #include <algorithm>
34 #include <cmath>
35 #include <iostream>
36 
37 namespace csspp
38 {
39 
57 {
58  boolean_t const result(n->to_boolean());
59  if(result == boolean_t::BOOLEAN_INVALID)
60  {
61  error::instance() << n->get_position()
62  << "a boolean expression was expected."
64  }
65  return result == boolean_t::BOOLEAN_TRUE;
66 }
67 
69 {
70  // logical_and: equality
71  // | logical_and IDENTIFIER (='and') equality
72  // | logical_and '&&' equality
73 
74  node::pointer_t result(equality());
75  if(!result)
76  {
77  return node::pointer_t();
78  }
79 
80  while((f_current->is(node_type_t::IDENTIFIER) && f_current->get_string() == "and")
82  {
83  position pos(f_current->get_position());
84 
85  // skip the AND
86  next();
87 
89  if(!rhs)
90  {
91  return node::pointer_t();
92  }
93 
94  // apply the AND
95  bool const lr(boolean(result));
96  bool const rr(boolean(rhs));
97  result.reset(new node(node_type_t::BOOLEAN, pos));
98  result->set_boolean(lr && rr);
99  }
100 
101  return result;
102 }
103 
104 } // namespace csspp
105 
106 // Local Variables:
107 // mode: cpp
108 // indent-tabs-mode: nil
109 // c-basic-offset: 4
110 // tab-width: 4
111 // End:
112 
113 // vim: ts=4 sw=4 et
node::pointer_t equality()
node::pointer_t logical_and()
std::shared_ptr< node > pointer_t
Definition: node.h:122
boolean_t
Definition: node.h:29
static bool boolean(node::pointer_t n)
Check whether a node represents true or false.
node::pointer_t f_current
Definition: expression.h:151
static error & instance()
Definition: error.cpp:78

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.