Source
xxxxxxxxxx
private static function parseConstant(string $source, int &$pos, array &$tokens, array $options, int $depth): bool {
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
class CExpressionParser extends CParser {
// For parsing of expressions.
private const STATE_AFTER_OPEN_BRACE = 1;
private const STATE_AFTER_BINARY_OPERATOR = 2;
private const STATE_AFTER_LOGICAL_OPERATOR = 3;
private const STATE_AFTER_NOT_OPERATOR = 4;
private const STATE_AFTER_UNARY_MINUS = 5;
private const STATE_AFTER_CLOSE_BRACE = 6;
private const STATE_AFTER_CONSTANT = 7;
// For parsing of math function parameters.
private const STATE_NEW = 1;
private const STATE_END = 2;
private const STATE_END_OF_PARAMS = 3;
private const MAX_MATH_FUNCTION_DEPTH = 32;
/**
* An error message if trigger expression is not valid
*
* @var string
*/
private $error = '';
/**
* An options array.
*
* Supported options:
* 'usermacros' => false Enable user macros usage in expression.
* 'lldmacros' => false Enable low-level discovery macros usage in expression.
* 'collapsed_expression' => false Short trigger expression.
* For example: {439} > {$MAX_THRESHOLD} or {439} < {$MIN_THRESHOLD}
* 'calculated' => false Parse calculated item formula instead of trigger expression.
* 'host_macro' => false Allow {HOST.HOST} macro as host name part in the query.
* 'host_macro_n' => false Allow {HOST.HOST} and {HOST.HOST<1-9>} macros as host name part in the query.
* 'empty_host' => false Allow empty hostname in the query string.
* 'escape_backslashes' => true Disable backslash escaping in history function parameters prior to v7.0.
* 'macros_n' => [] Array of strings having supported reference macros.
*
* @var array
*/
private $options = [
'usermacros' => false,
'lldmacros' => false,
'collapsed_expression' => false,
'calculated' => false,