purplefish32/sublime-text-2-wordpress — pull request #3 by ericandrewlewis (2012-04-05 04:20:28+00:00)
Title: Fresh scrape of WordPress, including all function parameters.

I did a fresh scape of WP for all PHP functions, and replaced everything in the auto-generated file with the new results. I'm assuming everything in the auto-generated file was WP PHP functions, right?

If anyone's interested, here's the code for scraping WP for a functions list and creating the Sublime Text JSON:

```php
function tokenizeme() {

// get each entry
$stack[] = rtrim(ABSPATH, "/");
while ($stack) {
$thisdir = array_pop($stack);
if ($dircont = scandir($thisdir)) {
$i=0;
while (isset($dircont[$i])) {
if ($dircont[$i] !== '.' && $dircont[$i] !== '..' && $dircont[$i] != "wp-content" ) {
$current_file = "{$thisdir}/{$dircont[$i]}";
if (is_file($current_file) &&strpos($dircont[$i], '.php') ) {
$path[] = "{$thisdir}/{$dircont[$i]}";
} elseif (is_dir($current_file) && $dircont[$i] != ".svn" ) {
$path[] = "{$thisdir}/{$dircont[$i]}";
$stack[] = $current_file;
}
}
$i++;
}
}
}
// echo '

';
$debug = false;
$in_function = false;
$in_class = false;
$in_function_params = false;
$function_params = '';
foreach ( $path as $path_key => $file ) :
if ( ! is_file($file) )
continue;
$source = file_get_contents($file);
$tokens = token_get_all($source);
$parenthesis_depth = 0;
$braces_depth = 0;
$in_function_params = false;

foreach($tokens as $key => $token) :
if ( is_array($token) ) {
if($debug):
if(token_name($token[0]) != "T_WHITESPACE")
echo token_name($token[0]) . ' ' . (($in_class)?'yes':'no') . '
';
endif;
//switch the token name
switch( token_name($token[0]) ) {
case 'T_CURLY_OPEN' :
$braces_depth++;
break;
case 'T_CLASS' :
$in_class = true;
$brace_depth = 0;
break;
case 'T_FUNCTION' :
$in_function = true;
$got_function_name = false;
break;
case 'T_STRING' :
if ( $in_function && !$got_function_name ) :
$current_function = $token[1];
$got_function_name = true;
$in_function_params = true;
continue 2;
endif;
case '' :
break;
}
if( $in_function_params ) {
$function_params .= $token[1];
}
} else {
if( $in_function_params ) {
if($debug) echo $token . '
';
switch($token) {
case '(' :
$parenthesis_depth++;
continue 2;
break;
case ')' :
if($parenthesis_depth)
$parenthesis_depth--;
if($parenthesis_depth)
continue 2;
$functions[] = array($current_function, trim($function_params), $in_class, $file );
if($debug) var_dump(array($current_function, trim($function_params), $in_class, $file ) );
$current_function = NULL;
$function_params = NULL;
$in_function_params = false;
continue 2;
break;
}
$function_params .= $token;
} else {
switch($token) {
case '{' :
$braces_depth++;
continue 2;
case '}' :
$braces_depth--;
if(!$braces_depth)
$in_class = false;
continue 2;
}
}
}

endforeach;
$tokens = NULL;

endforeach;

foreach ( $functions as $key => $function ) {
if($function[2]) {
unset($functions[$key]);
continue;
}
$args = array();
if(!empty($function[1])) :
$args = split(',', $function[1]);
foreach($args as $key => $arg) {
$new_arg_text = trim($arg, "\n\r\t ");
$new_arg_text = str_replace('"', "'", $new_arg_text);
$new_arg_text = str_replace('$', '\\\$', $new_arg_text);
$args[$key] = '${' . ($key+1) . ':' . $new_arg_text . '}';
}
endif;
?>{"trigger": "", "contents": "()" },