Re: ext/phpdoc commited
| From: | Olivier Courtin | Date: | Thu, 13 Dec 2001 08:40:46 +0000 |
| Subject: | Re: ext/phpdoc commited | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-3471@lists.php.net to get a copy of this message | ||
On Thu, 13 Dec 2001 09:07:11 +0100
Olivier Courtin <pnine@free.fr> wrote:
Ooups the attached files didn't pass...
so diff -u and phpdoc_checker ...
--- old_phpdoc.c Thu Dec 13 02:43:22 2001
+++ phpdoc.c Thu Dec 13 08:56:10 2001
@@ -266,10 +266,11 @@
}
-#define T_FUNCTION_PARAM INT_MAX-1
-#define T_FUNCTION_PARAM_DEFAULT INT_MAX-2
+#define T_FUNCTION_PARAM INT_MAX-1
+#define T_FUNCTION_PARAM_DEFAULT INT_MAX-2
#define T_FUNCTION_PARAM_LIST INT_MAX-3
-#define T_BLOCK INT_MAX-4
+#define T_BLOCK INT_MAX-4
+#define T_VAR_DEFAULT INT_MAX-5
typedef struct {
int *stack;
@@ -307,7 +308,7 @@
st.stack[0] = -1;
token.type = 0;
- while ((token_type=CG(lang_scanner).lex_scan(&token CLS_CC))) {
+ while ((token_type=lex_scan(&token CLS_CC))) {
if (debug)
zend_printf("// %s(%d)\n",zendtext, token_type);
@@ -343,13 +344,21 @@
case T_GLOBAL:
st.stack[st.pos++] = token_type;
break;
+ case T_STATIC:
+ st.stack[st.pos++] = token_type;
+ break;
case T_ML_COMMENT:
case T_COMMENT:
- PHPDOC_STRCAT(new_string, "<comment>");
-
- sprint_xml(new_string, zendtext);
-
- PHPDOC_STRCAT(new_string, "</comment>\n");
+ /* Don't know if it's the best way to do it ? */
+ if(!strncmp(zendtext, "/**", 3)){
+ PHPDOC_STRCAT(new_string, "<phpdoc>");
+ sprint_xml(new_string, zendtext);
+ PHPDOC_STRCAT(new_string, "</phpdoc>\n");
+ } else {
+ PHPDOC_STRCAT(new_string, "<comment>");
+ sprint_xml(new_string, zendtext);
+ PHPDOC_STRCAT(new_string, "</comment>\n");
+ }
break;
case T_EXTENDS:
switch(find_something(st.stack, st.pos)) {
@@ -367,7 +376,7 @@
zend_sprintf(buffer, " name=\"%s\"", zendtext);
PHPDOC_STRCAT(new_string, buffer);
break;
- case -T_FUNCTION:
+ case -T_FUNCTION:
st.stack[st.pos++] = token_type;
break;
case T_FUNCTION_PARAM_LIST:
@@ -379,6 +388,10 @@
zend_sprintf(buffer, "<global name=\"%s\"/>",zendtext);
PHPDOC_STRCAT(new_string, buffer);
break;
+ case T_STATIC:
+ zend_sprintf(buffer, "<static name=\"%s\"/>",zendtext);
+ PHPDOC_STRCAT(new_string, buffer);
+ break;
default:
break;
}
@@ -403,11 +416,18 @@
case T_REQUIRE_ONCE:
PHPDOC_STRCAT(new_string, zendtext);
break;
+ case T_FUNCTION_PARAM_DEFAULT:
+ case T_VAR_DEFAULT:
+ PHPDOC_STRCAT(new_string, zendtext);
+ PHPDOC_STRCAT(new_string, "\"");
+ st.pos--;
+ break;
}
break;
case T_DNUMBER:
switch(find_something(st.stack, st.pos)) {
case T_FUNCTION_PARAM_DEFAULT:
+ case T_VAR_DEFAULT:
PHPDOC_STRCAT(new_string, zendtext);
PHPDOC_STRCAT(new_string, "\"");
st.pos--;
@@ -419,6 +439,7 @@
case T_LNUMBER:
switch(find_something(st.stack, st.pos)) {
case T_FUNCTION_PARAM_DEFAULT:
+ case T_VAR_DEFAULT:
PHPDOC_STRCAT(new_string, zendtext);
PHPDOC_STRCAT(new_string, "\"");
st.pos--;
@@ -430,6 +451,7 @@
case '-':
switch(find_something(st.stack, st.pos)) {
case T_FUNCTION_PARAM_DEFAULT:
+ case T_VAR_DEFAULT:
/* a DNUMBER or LNUMBER will follow */
PHPDOC_STRCAT(new_string, zendtext);
@@ -500,9 +522,9 @@
case '=':
switch (find_something(st.stack, st.pos)) {
case T_VAR:
- zend_sprintf(buffer, ">");
+ zend_sprintf(buffer, " default=\"");
PHPDOC_STRCAT(new_string, buffer);
- st.stack[st.pos-1] = -st.stack[st.pos-1];
+ st.stack[st.pos++] = T_VAR_DEFAULT;
break;
case T_FUNCTION_PARAM:
zend_sprintf(buffer, " default=\"");
@@ -523,6 +545,7 @@
st.pos--;
break;
case T_GLOBAL:
+ case T_STATIC:
case T_VARIABLE:
st.pos--;
break;
@@ -554,6 +577,7 @@
sprint_xml(new_string, zendtext);
break;
case T_FUNCTION_PARAM_DEFAULT:
+ case T_VAR_DEFAULT:
sprint_xml(new_string, zendtext);
PHPDOC_STRCAT(new_string, "\"");
st.pos--;
@@ -627,7 +651,7 @@
convert_to_string_ex(arg);
- CG(lang_scanner).save_lexical_state(&original_lex_state CLS_CC);
+ save_lexical_state(&original_lex_state CLS_CC);
#ifndef ZTS
if (prepare_string_for_scanning(*arg, "dummy.php")==FAILURE) {
@@ -642,7 +666,7 @@
MAKE_STD_ZVAL(return_value);
ZVAL_EMPTY_STRING(return_value);
#endif
- CG(lang_scanner).restore_lexical_state(&original_lex_state CLS_CC);
+ restore_lexical_state(&original_lex_state CLS_CC);
#ifdef ZTS
delete input_stream;
#endif
#!/home/ol/bin/phpdoc -q
<?php
/*
* phpdoc_checker : debug / test tool
*
* Purpose : check on a dir if PECL/phpdoc is able to generate well
formed xml
* on php files
*
* Needs :
* - php 4.1.0 at least in standalone mode (to use the php -l options
* before and be sure to not fall on dummy parse error into php files)
*
* - working php with PECL/phpdoc install in standalone too (possible
not the
* same one as php -l) and you *must* call this script with it, so
modify
* path on first line... it work for me, surely not for you... ;)
*
* - backticks available and enough execution time
*
* - And also a working find command
*
*/
/* Begin Config */
// path to find input php files could be either a dir or a single file
$input_php_dir = $HOME."/lib/pear/"; //
// path to temporary dir where to put xml file before parsing
// all tmp files are automatically delete at the end of scripts
$tmp_dir = "/tmp";
// path to php binary with -l option working
$lint_bin_path = "phpdev";
// TRUE if you want to keep the xml files on errors, FALSE otherwise
$keep_wrong_xml_file = TRUE;
// path to keep the wrong xml files
// Don't forget the ending slash !
$keep_dir = $PWD."/wrong/";
// comment it if you don't really need it
set_time_limit(30);
/* end config */
require_once("XML/Parser.php");
// generate_xml_doc {{{
/*
* Generate in a temp file the xml doc from a php file
* No errors test at all on files manipulation... dirty...
*/
function generate_xml_doc($file_name, $tmp_dir="."){
$temp = "";
$fp = fopen($file_name, "r");
while(!feof($fp)){
$temp .= fgets($fp, filesize($file_name));
}
fclose($fp);
$xml = phpdoc_xml_from_string($temp);
$tmp_name = tempnam ($tmp_dir, "phpdoc");
$fp = fopen($tmp_name, "w");
fwrite($fp, $xml, strlen($xml));
fclose($fp);
return $tmp_name;
}
// }}}
// check_xml_well_formed {{{
/*
* Check if xml file is well formed
*/
function check_xml_well_formed($file_name){
$xml = new XML_Parser;
$fp = $xml -> setInputFile($file_name);
$xml -> setInput($fp);
$ret = $xml -> parse();
if(is_object($ret)){
return $ret->message;
} else {
return "Ok";
}
}
// }}}
/* begin Main Scipt */
// Get files list
$files = explode("\n",
find $input_php_dir -name "*.php");
unset($files[count($files) - 1]);
$report = array();
foreach($files as $file) {
// check parse error
if(substr($ret = $lint_bin_path -l $file, 0, 2) != "No"){
$report[$file] = "php parse error... ;)";
} else {
// begin real check
$tmp_file = generate_xml_doc($file, $tmp_dir);
$report[$file] = check_xml_well_formed($tmp_file);
if($report[$file] != "Ok" && $keep_wrong_xml_file){
copy($tmp_file, $keep_dir.str_replace("/", "_",
$file).".xml");
}
unlink($tmp_file);
}
}
// print report
print_r($report);
$res = array_count_values($report);
$nb_ok = isset($res["Ok"]) ? $res["Ok"] : 0;
printf("\n%s right parsing on %s files.\n", $nb_ok, count($report));
/*
* vim: ft=php
*/
?>