function Smarty_Compiler::_parse_is_expr in Quiz 6.5
Same name and namespace in other branches
- 6.6 includes/moodle/lib/smarty/Smarty_Compiler.class.php \Smarty_Compiler::_parse_is_expr()
Parse is expression
Parameters
string $is_arg:
array $tokens:
Return value
array
1 call to Smarty_Compiler::_parse_is_expr()
- Smarty_Compiler::_compile_if_tag in includes/
moodle/ lib/ smarty/ Smarty_Compiler.class.php - Compile {if ...} tag
File
- includes/
moodle/ lib/ smarty/ Smarty_Compiler.class.php, line 1436
Class
- Smarty_Compiler
- Template compiling class @package Smarty
Code
function _parse_is_expr($is_arg, $tokens) {
$expr_end = 0;
$negate_expr = false;
if (($first_token = array_shift($tokens)) == 'not') {
$negate_expr = true;
$expr_type = array_shift($tokens);
}
else {
$expr_type = $first_token;
}
switch ($expr_type) {
case 'even':
if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') {
$expr_end++;
$expr_arg = $tokens[$expr_end++];
$expr = "!(1 & ({$is_arg} / " . $this
->_parse_var_props($expr_arg) . "))";
}
else {
$expr = "!(1 & {$is_arg})";
}
break;
case 'odd':
if (isset($tokens[$expr_end]) && $tokens[$expr_end] == 'by') {
$expr_end++;
$expr_arg = $tokens[$expr_end++];
$expr = "(1 & ({$is_arg} / " . $this
->_parse_var_props($expr_arg) . "))";
}
else {
$expr = "(1 & {$is_arg})";
}
break;
case 'div':
if (@$tokens[$expr_end] == 'by') {
$expr_end++;
$expr_arg = $tokens[$expr_end++];
$expr = "!({$is_arg} % " . $this
->_parse_var_props($expr_arg) . ")";
}
else {
$this
->_syntax_error("expecting 'by' after 'div'", E_USER_ERROR, __FILE__, __LINE__);
}
break;
default:
$this
->_syntax_error("unknown 'is' expression - '{$expr_type}'", E_USER_ERROR, __FILE__, __LINE__);
break;
}
if ($negate_expr) {
$expr = "!({$expr})";
}
array_splice($tokens, 0, $expr_end, $expr);
return $tokens;
}