static function parseArguments($source = null, $fpos = 0) { $parser = new ArgumentLexer($source, $fpos); $result = array(); $current_buffer =& $result; $filter_buffer = array(); $tokens = $parser->parse(); foreach ($tokens as $token) { list($token, $data) = $token; if ($token == 'filter_start') { $filter_buffer = array(); $current_buffer =& $filter_buffer; } elseif ($token == 'filter_end') { if (count($filter_buffer)) { $i = count($result) - 1; if (is_array($result[$i])) { $result[$i]['filters'][] = $filter_buffer; } else { $result[$i] = array(0 => $result[$i], 'filters' => array($filter_buffer)); } } $current_buffer =& $result; } elseif ($token == 'boolean') { $current_buffer[] = $data === 'true' ? true : false; } elseif ($token == 'name') { $current_buffer[] = symbol($data); } elseif ($token == 'number' || $token == 'string') { $current_buffer[] = $data; } elseif ($token == 'named_argument') { $last = $current_buffer[count($current_buffer) - 1]; if (!is_array($last)) { $current_buffer[] = array(); } $namedArgs =& $current_buffer[count($current_buffer) - 1]; list($name, $value) = array_map('trim', explode(':', $data, 2)); # if argument value is variable mark it $value = self::parseArguments($value); $namedArgs[$name] = $value[0]; } elseif ($token == 'operator') { $current_buffer[] = array('operator' => $data); } } return $result; }
static function parseArguments($source = null, $fpos = 0) { $parser = new ArgumentLexer($source, $fpos); $result = array(); $current_buffer =& $result; $filter_buffer = array(); foreach ($parser->parse() as $token) { list($token, $data) = $token; if ($token == 'filter_start') { $filter_buffer = array(); $current_buffer =& $filter_buffer; } elseif ($token == 'filter_end') { if (count($filter_buffer)) { $result[] = $filter_buffer; } $current_buffer =& $result; } elseif ($token == 'name') { $current_buffer[] = symbol($data); } elseif ($token == 'number' || $token == 'string') { $current_buffer[] = $data; } elseif ($token == 'named_argument') { $last = $current_buffer[count($current_buffer) - 1]; if (!is_array($last)) { $current_buffer[] = array(); } $namedArgs =& $current_buffer[count($current_buffer) - 1]; list($name, $value) = array_map('trim', explode(':', $data, 2)); $namedArgs[$name] = $value; } elseif ($token == 'operator') { $current_buffer[] = array('operator' => $data); } } return $result; }