Current Version: 1.0.33
Project Name: csspp
expr_conditional.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
39{
40 // conditional: logical_or
41 // | conditional '?' conditional ':' logical_or
42
43 // note: we also support if(expr, expr, expr)
44
46 if(!result)
47 {
48 return node::pointer_t();
49 }
50
52 {
53 bool const r(boolean(result));
54
55 // skip the '?'
56 next();
57
58 // TODO: avoid calculating both sides.
59 if(r)
60 {
61 result = conditional();
62 if(!result)
63 {
64 return node::pointer_t();
65 }
66 }
67 else
68 {
69 // we will ignore this entry, so ignore the eventual errors
70 csspp::safe_error_t safe_errors;
71 std::stringstream ignore;
72 safe_error_stream_t safe_output(ignore);
73
74 static_cast<void>(conditional());
75 }
76
78 {
79 error::instance() << f_current->get_position()
80 << "a mandatory ':' was expected after a '?' first expression."
82 return node::pointer_t();
83 }
84
85 // skip the ':'
86 next();
87
88 if(!r)
89 {
90 result = conditional();
91 if(!result)
92 {
93 return node::pointer_t();
94 }
95 }
96 else
97 {
98 // we will ignore this entry, so ignore the eventual errors
99 csspp::safe_error_t safe_errors;
100 std::stringstream ignore;
101 safe_error_stream_t safe_output(ignore);
102
103 static_cast<void>(conditional());
104 }
105 }
106
107 return result;
108}
109
110} // namespace csspp
111
112// Local Variables:
113// mode: cpp
114// indent-tabs-mode: nil
115// c-basic-offset: 4
116// tab-width: 4
117// End:
118
119// vim: ts=4 sw=4 et
static error & instance()
Definition error.cpp:77
node::pointer_t conditional()
node::pointer_t f_current
Definition expression.h:155
node::pointer_t logical_or()
std::shared_ptr< node > pointer_t
Definition node.h:132
The namespace of all the classes in the CSS Preprocessor.
Definition csspp.h:48

Documentation of CSS Preprocessor.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.