45 if(dimension ==
"rad")
50 else if(dimension ==
"deg"
54 return n *
M_PI / 180.0;
56 else if(dimension ==
"grad")
59 return n *
M_PI / 200.0;
61 else if(dimension ==
"turn")
64 return n *
M_PI * 2.0;
69 <<
"trigonometry functions expect an angle (deg, grad, rad, turn) as a parameter."
86 return g_unique_id_counter;
102 return arg->get_child(0);
150 number =
value->get_decimal_number();
179 number =
value->get_decimal_number();
185 number =
value->get_decimal_number();
248 number->set_integer(
labs(number->get_integer()));
252 number->set_decimal_number(
fabs(number->get_decimal_number()));
258 <<
"abs() expects a number as parameter."
276 number->set_decimal_number(
acos(
n));
277 number->set_string(
"rad");
282 <<
"acos() expects a number as parameter."
299 c.get_color(
r,
g,
b,
a);
306 <<
"alpha() expects a color as parameter."
324 number->set_decimal_number(
asin(
n));
325 number->set_string(
"rad");
330 <<
"asin() expects a number as parameter."
348 number->set_decimal_number(
atan(
n));
349 number->set_string(
"rad");
354 <<
"atan() expects a number as parameter."
371 c.get_color(
r,
g,
b,
a);
378 <<
"blue() expects a color as parameter."
393 number->set_decimal_number(
ceil(number->get_decimal_number()));
399 <<
"ceil() expects a number as parameter."
412 std::string
const dimension(number->get_string());
420 number->set_string(
"");
423 number->set_decimal_number(
cos(
n));
428 <<
"cos() expects an angle as parameter."
440 switch(
any->get_type())
449 number->set_decimal_number(
any->get_decimal_number());
456 number->set_decimal_number(
any->get_integer());
457 number->set_string(
any->get_string());
465 std::stringstream
ss;
466 ss <<
any->get_string();
471 number =
l.next_token();
473 switch(number->get_type())
481 result->set_decimal_number(number->get_decimal_number());
488 result->set_decimal_number(number->get_integer());
489 result->set_string(number->get_string());
499 <<
"decimal_number() expects a string parameter to represent a valid integer, decimal number, or percent value."
510 <<
"decimal_number() expects one value as parameter."
525 number->set_decimal_number(
floor(number->get_decimal_number()));
531 <<
"floor() expects a number as parameter."
550 c.get_color(
r,
g,
b,
a);
568 c.set_color(
r,
g,
b, 1.0);
576 <<
"frgb() expects exactly one color parameter or three numbers (Red, Green, Blue)."
616 c.set_color(
r,
g,
b,
a);
624 <<
"frgba() expects exactly one color parameter followed by one number (Color, Alpha), or four numbers (Red, Green, Blue, Alpha)."
635 if(
id && !
name.empty())
650 result->set_boolean(
true);
659 <<
"function_exists() expects a string or an identifier as parameter."
676 c.get_color(
r,
g,
b,
a);
683 <<
"green() expects a color as parameter."
694 if(
id && !
name.empty())
709 result->set_boolean(
true);
718 <<
"global_variable_exists() expects a string or an identifier as parameter."
739 h = dimension_to_radians(
func->get_position(),
h,
col1->get_string());
750 <<
"hsl() expects exactly three numbers: Hue (angle), Saturation (%), and Lightness (%)."
773 h = dimension_to_radians(
func->get_position(),
h,
col1->get_string());
784 <<
"hsla() expects exactly four numbers: Hue (angle), Saturation (%), Lightness (%), and Alpha (0.0 to 1.0)."
809 <<
"hue() expects a color as parameter."
821 switch(
any->get_type())
833 id->set_string(
any->to_string(0));
841 id->set_string(
any->get_string());
852 <<
"identifier() expects one value as parameter."
862 if(
arg1->size() != 1)
865 <<
"if() expects a boolean as its first argument."
877 bool const r(
boolean(
arg1->get_child(0)));
882 return result->get_child(0);
910 switch(
any->get_type())
919 number->set_integer(
any->get_decimal_number());
920 number->set_string(
any->get_string());
927 number->set_integer(
any->get_decimal_number());
935 std::stringstream
ss;
936 ss <<
any->get_string();
941 number =
l.next_token();
943 switch(number->get_type())
951 result->set_integer(number->get_decimal_number());
952 result->set_string(number->get_string());
959 result->set_integer(number->get_decimal_number());
969 <<
"decimal_number() expects a string parameter to represent a valid integer, decimal number, or percent value."
980 <<
"integer() expects one value as parameter."
1004 <<
"lightness() expects a color as parameter."
1017 if(!number->get_string().empty())
1020 <<
"log() expects a unit less number as parameter."
1028 <<
"log() expects a positive number as parameter."
1037 number->set_decimal_number(
log(
n));
1042 <<
"log() expects a number as parameter."
1065#pragma GCC diagnostic push
1066#pragma GCC diagnostic ignored "-Wrestrict"
1068#pragma GCC diagnostic pop
1090 <<
"max() expects all numbers to have the same dimension."
1103 <<
"max() expects any number of numbers."
1127#pragma GCC diagnostic push
1128#pragma GCC diagnostic ignored "-Wrestrict"
1130#pragma GCC diagnostic pop
1152 <<
"min() expects all numbers to have the same dimension."
1165 <<
"min() expects any number of numbers."
1176 if(
arg1->size() != 1)
1179 <<
"not() expects a boolean as its first argument."
1185 bool const r(
boolean(
arg1->get_child(0)));
1198 switch(
any->get_type())
1203 number->set_decimal_number(
any->get_decimal_number());
1214 number->set_decimal_number(
any->get_integer());
1222 std::stringstream
ss;
1223 ss <<
any->get_string();
1228 number =
l.next_token();
1230 switch(number->get_type())
1235 result->set_decimal_number(number->get_decimal_number());
1245 result->set_decimal_number(number->get_integer());
1255 <<
"percentage() expects a string parameter to represent a valid integer, decimal number, or percent value."
1266 <<
"percentage() expects one value as parameter."
1283 c.get_color(
r,
g,
b,
a);
1290 <<
"red() expects a color as parameter."
1309 c.get_color(
r,
g,
b,
a);
1327 c.set_color(
r / 255.0,
g / 255.0,
b / 255.0, 1.0);
1335 <<
"rgb() expects exactly one color parameter (Color) or three numbers (Red, Green, Blue)."
1375 c.set_color(
r / 255.0,
g / 255.0,
b / 255.0,
a);
1383 <<
"rgba() expects exactly one color parameter followed by alpha (Color, Alpha) or four numbers (Red, Green, Blue, Alpha)."
1409 number->set_decimal_number(
round(number->get_decimal_number()));
1415 <<
"round() expects a number as parameter."
1439 <<
"saturation() expects a color as parameter."
1454 number->set_integer(
n < 0.0 ? -1 : (
n > 0.0 ? 1 : 0));
1458 number->set_decimal_number(
n < 0.0 ? -1.0 : (
n > 0.0 ? 1.0 : 0.0));
1464 <<
"sign() expects a number as parameter."
1477 std::string
const dimension(number->get_string());
1485 number->set_string(
"");
1488 number->set_decimal_number(
sin(
n));
1493 <<
"sin() expects an angle as parameter."
1510 <<
"sqrt() expects zero or a positive number."
1515 std::string
dimension(number->get_string());
1526 && ((
divisor.size() & 1) == 0))
1585 <<
"sqrt() expects dimensions to be squarely defined (i.e. 'px * px')."
1595 number->set_decimal_number(
sqrt(
n));
1601 <<
"sqrt() expects a number as parameter."
1613 switch(
any->get_type())
1625 id->set_string(
any->to_string(0));
1633 id->set_string(
any->get_string());
1644 <<
"string() expects one value as parameter."
1660 for(
char const *
s(
copy.c_str()); *
s !=
'\0'; ++
s)
1662 if(
static_cast<unsigned char>(*
s) < 0x80
1663 ||
static_cast<unsigned char>(*s) >= 0xC0)
1673 <<
"str_length() expects one string as parameter."
1686 std::string
const dimension(number->get_string());
1694 number->set_string(
"");
1697 number->set_decimal_number(
tan(
n));
1702 <<
"tan() expects an angle as parameter."
1713 if(
func->size() == 1)
1719 <<
"unique_id() expects a string or an identifier as its optional parameter."
1727 id =
"_csspp_unique";
1732 ++g_unique_id_counter;
1734 id += std::to_string(g_unique_id_counter);
1737 identifier->set_string(
id);
1749 switch(
any->get_type())
1753 type->set_string(
"list");
1757 type->set_string(
"bool");
1761 type->set_string(
"color");
1766 type->set_string(
"number");
1770 type->set_string(
"identifier");
1774 type->set_string(
"integer");
1778 type->set_string(
"map");
1782 type->set_string(
"string");
1786 type->set_string(
"unicode-range");
1791 type->set_string(
"undefined");
1799 <<
"type_of() expects one value as a parameter."
1810 if(number !=
nullptr)
1815 unit->set_string(
"%");
1819 unit->set_string(number->get_string());
1825 <<
"unit() expects a number as parameter."
1836 if(
id && !
name.empty())
1851 result->set_boolean(
true);
1860 <<
"variable_exists() expects a string or an identifier as parameter."
1875 char const * f_name;
1962 "global_variable_exists",
2170 if(
id && !
name.empty())
2177 result->set_boolean(
true);
2190 <<
"() expects exactly "
2201 <<
"() expects between "
void set_hsl(color_component_t h, color_component_t s, color_component_t l, color_component_t alpha)
static error & instance()
virtual node::pointer_t get_variable(std::string const &variable_name, bool global_only=false) const =0
virtual node::pointer_t execute_user_function(node::pointer_t func)=0
node::pointer_t internal_function__atan(node::pointer_t func)
node::pointer_t internal_function__log(node::pointer_t func)
node::pointer_t internal_function__acos(node::pointer_t func)
node::pointer_t internal_function__floor(node::pointer_t func)
node::pointer_t internal_function__get_string_or_identifier(node::pointer_t func, size_t argn, std::string &str)
node::pointer_t internal_function__min(node::pointer_t func)
node::pointer_t internal_function__integer(node::pointer_t func)
node::pointer_t excecute_function(node::pointer_t func)
node::pointer_t f_current
node::pointer_t internal_function__max(node::pointer_t func)
node::pointer_t internal_function__type_of(node::pointer_t func)
node::pointer_t internal_function__variable_exists(node::pointer_t func)
node::pointer_t internal_function__blue(node::pointer_t func)
node::pointer_t internal_function__unique_id(node::pointer_t funct)
node::pointer_t internal_function__get_color(node::pointer_t func, size_t argn, color &col)
node::pointer_t internal_function__tan(node::pointer_t func)
node::pointer_t internal_function__if(node::pointer_t func)
node::pointer_t internal_function__hsla(node::pointer_t func)
node::pointer_t internal_function__asin(node::pointer_t func)
static void set_unique_id_counter(int counter)
node::pointer_t internal_function__identifier(node::pointer_t func)
node::pointer_t internal_function__rgb(node::pointer_t func)
node::pointer_t internal_function__get_number_or_percent(node::pointer_t func, size_t argn, decimal_number_t &number)
std::vector< std::string > dimension_vector_t
node::pointer_t internal_function__round(node::pointer_t func)
node::pointer_t internal_function__percentage(node::pointer_t func)
node::pointer_t internal_function__lightness(node::pointer_t func)
node::pointer_t internal_function__saturation(node::pointer_t func)
node::pointer_t internal_function__str_length(node::pointer_t func)
expression_variables_interface * f_variable_handler
node::pointer_t internal_function__abs(node::pointer_t func)
node::pointer_t internal_function__red(node::pointer_t func)
node::pointer_t internal_function__green(node::pointer_t func)
node::pointer_t internal_function__sin(node::pointer_t func)
node::pointer_t internal_function__frgb(node::pointer_t func)
node::pointer_t internal_function__inspect(node::pointer_t func)
node::pointer_t internal_function__decimal_number(node::pointer_t func)
node::pointer_t internal_function__random(node::pointer_t func)
node::pointer_t internal_function__global_variable_exists(node::pointer_t func)
std::string rebuild_dimension(dimension_vector_t const ÷nd, dimension_vector_t const &divisor)
node::pointer_t internal_function__get_number(node::pointer_t func, size_t argn, decimal_number_t &number)
node::pointer_t internal_function__not(node::pointer_t func)
node::pointer_t internal_function__hsl(node::pointer_t func)
node::pointer_t internal_function__rgba(node::pointer_t func)
static int get_unique_id_counter()
void dimensions_to_vectors(position const &pos, std::string const &dimension, dimension_vector_t ÷nd, dimension_vector_t &divisor)
node::pointer_t internal_function__function_exists(node::pointer_t func)
node::pointer_t internal_function__hue(node::pointer_t func)
node::pointer_t internal_function__frgba(node::pointer_t func)
node::pointer_t internal_function__get_string(node::pointer_t func, size_t argn, std::string &str)
node::pointer_t internal_function__string(node::pointer_t func)
node::pointer_t internal_function__sign(node::pointer_t func)
node::pointer_t internal_function__unit(node::pointer_t func)
node::pointer_t internal_function__sqrt(node::pointer_t func)
node::pointer_t internal_function__cos(node::pointer_t func)
node::pointer_t internal_function__get_any(node::pointer_t func, size_t argn)
node::pointer_t internal_function__ceil(node::pointer_t func)
node::pointer_t internal_function__alpha(node::pointer_t func)
static int const g_to_string_flag_show_quotes
std::shared_ptr< node > pointer_t
decimal_number_t dimension_to_radians(position const &pos, decimal_number_t n, std::string const &dimension)
The namespace of all the classes in the CSS Preprocessor.