1 && substr_count($value, "\n") > 1) { _parse_finish_one($objects, $last_doxygen, $state); } continue; } if ($type === T_FUNCTION) { $state = API_PARSE_AFTER_FUNCTION; continue; } if ($value === 'define') { $state = API_PARSE_AFTER_DEFINE; continue; } switch ($state) { case API_PARSE_BEGIN: if ($type === T_DOC_COMMENT) { $last_doxygen = parse_doxygen($value); $last_doxygen['start'] = $line; $state = API_PARSE_AFTER_DOXYGEN; } elseif (!empty($last_doxygen)) { _parse_finish_one($objects, $last_doxygen, $state); } break; case API_PARSE_AFTER_FUNCTION: $last_doxygen += array( 'type' => 'function', 'start' => $line, 'identifer' => $value, 'arguments' => '', ); $state = API_PARSE_FUNCTION_ARGUMENTS_BEFORE; break; case API_PARSE_FUNCTION_ARGUMENTS_BEFORE: if ($value == '(') { // Skipping the whitespace (automatically) and the first ( // by using this state. $state = API_PARSE_FUNCTION_ARGUMENTS; } else { // The previous character was a & $last_doxygen['identifer'] .= $value; } break; case API_PARSE_FUNCTION_ARGUMENTS: if ($value == '{') { // cut off the last ) $last_doxygen['arguments'] = substr($last_doxygen['arguments'], 0, -1); $state = API_PARSE_FUNCTION_BODY; $count = 1; } else { $last_doxygen['arguments'] .= $value; } case API_PARSE_AFTER_DEFINE: if ($type === T_CONSTANT_ENCAPSED_STRING) { $last_doxygen += array( 'type' => 'constant', 'start' => $line, 'identifer' => trim($value, "'\""), ); _parse_finish_one($objects, $last_doxygen, $state); } break; case API_PARSE_FUNCTION_BODY: if ($value == '{') { $count++; } if ($value == '}') { $count--; } if (!$count) { $last_doxygen['finish'] = $line; _parse_finish_one($objects, $last_doxygen, $state); } break; default: _parse_finish_one($objects, $last_doxygen, $state); break; } } return $objects; } function _parse_finish_one(&$objects, &$last_doxygen, &$state) { if ($last_doxygen) { $objects[] = $last_doxygen; $last_doxygen = array(); } $state = API_PARSE_BEGIN; } function parse_doxygen($doxygen) { $in_description = FALSE; $data = array('summary' => ''); $doxygen = substr($doxygen, 4, -2); $description = array(); $data['description'] = &$description; $needs_identifier = array(); foreach (explode("\n", $doxygen) as $line) { // Remove the spaces and the asterisk space from the beginning of the // line. $line = substr(trim($line), 2); if ($line[0] == '@') { // We do not handle these yet. if ($line[1] == '{' || $line[1] == '}') continue; list($command, $argument) = explode(' ', substr($line, 1), 2); switch ($command) { case 'file': case 'defgroup': case 'ingroup': case 'addgroup': case 'mainpage': list($argument, $summary) = explode(' ', $argument, 2); $data += array( 'type' => $command, 'identifer' => $argument, 'summary' => $summary, ); break; case 'see': $data['see'][] = $argument; break; case 'param': $description = implode(' ', $description); unset($description); $description = array(); $data['param'][$argument] = &$description; $in_description = TRUE; break; case 'return': $description = implode(' ', $description); unset($description); $description = array(); $data['return'] = array( 'return_type' => $summary, 'description' => &$description, ); $in_description = TRUE; break; } } else { $line = trim($line); if ($line) { if ($in_description) { $description[] = $line; } else { $data['summary'] = $line; $in_description = TRUE; } } } } $description = implode(' ', $description); return $data; } function test() { $teststring = <<<__END__