+++ /dev/null
-<?php\r
-/**\r
- * tokenizer extension-based lexer for PHP code\r
- * \r
- * phpDocumentor :: automatic documentation generator\r
- * \r
- * PHP versions 4 and 5\r
- *\r
- * Copyright (c) 2002-2006 Gregory Beaver\r
- * \r
- * LICENSE:\r
- * \r
- * This library is free software; you can redistribute it\r
- * and/or modify it under the terms of the GNU Lesser General\r
- * Public License as published by the Free Software Foundation;\r
- * either version 2.1 of the License, or (at your option) any\r
- * later version.\r
- * \r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Lesser General Public License for more details.\r
- * \r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with this library; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * @category ToolsAndUtilities\r
- * @package phpDocumentor\r
- * @subpackage Parsers\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @copyright 2002-2007 Gregory Beaver\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version CVS: $Id: phpDocumentorTWordParser.inc,v 1.8 2007/11/16 11:53:06 ashnazg Exp $\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @since 1.2\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- * @todo CS cleanup - PHPCS needs to ignore CVS Id length\r
- */\r
-\r
-/**\r
- * Like WordParser, but expects an array of tokens from the tokenizer \r
- * instead of a string.\r
- *\r
- * @category ToolsAndUtilities\r
- * @package phpDocumentor\r
- * @subpackage WordParsers\r
- * @author Gregory Beaver <cellog@php.net>\r
- * @copyright 2002-2007 Gregory Beaver\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version Release: 1.4.1\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @since 1.2\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- * @todo CS cleanup - change classname to PhpDocumentor_*\r
- */\r
-class phpDocumentorTWordParser extends WordParser\r
-{\r
- /**#@+\r
- * @access private\r
- */\r
- /**\r
- * tokenized array from {@link token_get_all()}\r
- * @var array\r
- */\r
- var $_all;\r
- /**\r
- * List of tokens that can contain a newline\r
- * @var array\r
- */\r
- var $_nl_check = array(\r
- T_WHITESPACE,\r
- T_ENCAPSED_AND_WHITESPACE,\r
- T_CONSTANT_ENCAPSED_STRING,\r
- T_COMMENT,\r
- T_DOC_COMMENT,\r
- T_OPEN_TAG,\r
- T_CLOSE_TAG,\r
- T_INLINE_HTML);\r
- /**\r
- * @var array\r
- */\r
- var $_global_search;\r
- /**\r
- * current source line number (relative)\r
- * @var integer\r
- */\r
- var $_sourceline;\r
- /**\r
- * Source of the entire file, parsed into arrays of tokens on each line\r
- * @var array\r
- */\r
- var $_file_source = array();\r
- /**\r
- * Line number the last comment was on\r
- * @var integer\r
- */\r
- var $_docblock_linenum;\r
- /**#@-*/\r
- \r
- /**\r
- * Uses {@link token_get_all()} to tokenize the source code.\r
- * {@internal\r
- * Also, it divides the source tokens into separate lines for use by\r
- * the @filesource tag.\r
- *\r
- * {@source}}}\r
- *\r
- * @param string &$input source code\r
- *\r
- * @return void\r
- */\r
- function setup(&$input)\r
- {\r
- $input = rtrim(ltrim($input, "\r\n"));\r
- $this->data = &$input;\r
- // fix php warnings on invalid source code\r
- $this->_all = @token_get_all($input);\r
- $this->_file_source = array();\r
- $this->addFileSource($this->_all);\r
- $this->_sourceline = 0;\r
- $this->pos = 0;\r
- $this->linenum = 0;\r
- }\r
- \r
- /**\r
- * loads up next set of source code\r
- *\r
- * @return array source code array\r
- */\r
- function getSource()\r
- {\r
- $source = $this->source;\r
- $this->source = array();\r
- $this->getsource = false;\r
- return $source;\r
- }\r
- \r
- /**\r
- * gets the source code tokens\r
- *\r
- * @return array source code tokens split up by line number\r
- */\r
- function getFileSource()\r
- {\r
- return $this->_file_source;\r
- }\r
- \r
- /**\r
- * Begin retrieving source code\r
- *\r
- * @param string $word word to add the beginning of source code\r
- *\r
- * @return void\r
- * @access private\r
- * @todo CS cleanup - rename to retrieveSource for camelCase rule\r
- */\r
- function retrievesource($word = '')\r
- {\r
- $this->source = array(array($word));\r
- $this->_sourceline = 0;\r
- $this->getsource = true;\r
- }\r
-\r
- /**\r
- * Utility function to determine whether two tokens from the tokenizer are equal\r
- *\r
- * @param mixed $a first token\r
- * @param mixed $b second token\r
- *\r
- * @return bool whether or not the tokens are equal\r
- * @static\r
- */\r
- function tokenEquals($a, $b)\r
- {\r
- if (is_array($a)) $a = $a[1];\r
- if (is_array($b)) $b = $b[1];\r
- return $a == $b;\r
- }\r
- \r
- /**\r
- * Utility function to convert a series of tokens into a string\r
- *\r
- * @param array $a array of tokens\r
- *\r
- * @return string the resulting string\r
- * @static\r
- */\r
- function concatTokens($a)\r
- {\r
- $b = '';\r
- foreach ($a as $c) {\r
- if (is_array($c)) {\r
- $c = $c[1];\r
- }\r
- $b .= $c;\r
- }\r
- return $b;\r
- }\r
- \r
- /**\r
- * Retrieve a token for the phpDocumentorTParser\r
- * {@internal\r
- * This method adds source code to the array for a function to be returned\r
- * to a {@}source} tag, and will return the token unless it is T_WHITESPACE\r
- * and {@link $returnWhiteSpace} is false.\r
- *\r
- * The global variable search is more complicated than it is in the\r
- * WordParser, as we have to compare an array of tokens to each other, and\r
- * that is what this code does}}\r
- *\r
- * @return string|array token from tokenizer\r
- */\r
- function getWord()\r
- {\r
- if (!isset($this->_all[$this->pos])) {\r
- return false;\r
- }\r
-\r
- $oldlinenum = $this->linenum;\r
- $word = $this->_all[$this->pos++];\r
-\r
- // if we're looking for a global variable declaration, then this section\r
- // will search the upcoming tokens to see if they match the tokens\r
- // that define the global variable\r
- if (isset($this->_global_search)) {\r
- $pos = $this->pos;\r
- $gpos = 0;\r
- $found = false;\r
- if ($this->tokenEquals($word, $this->_global_search[$gpos++])) {\r
- $found = true;\r
- for (;$gpos<count($this->_global_search);$gpos++, $pos++) {\r
- if (isset($this->_all[$pos]) &&\r
- !$this->tokenEquals($this->_global_search[$gpos], \r
- $this->_all[$pos])\r
- ) {\r
- $found = false;\r
- }\r
- }\r
- }\r
- if ($found) {\r
- $a = $this->concatTokens($this->_global_search);\r
- $this->pos += count($this->_global_search) - 1;\r
- unset($this->_global_search);\r
- return $a;\r
- }\r
- }\r
- if ($this->getsource) {\r
- $this->addSource($word);\r
- }\r
- if (is_array($word)) {\r
- if (in_array($word[0], $this->_nl_check)) {\r
- $this->linenum += substr_count($word[1], "\n");\r
- }\r
- if ($word[0] == T_WHITESPACE && !$this->returnWhiteSpace) {\r
- return $this->getWord();\r
- }\r
- // seeing if we can get line numbers out of the beast\r
- }\r
- if (is_array($word) && $word[0] == T_COMMENT) {\r
- $this->_docblock_linenum = $oldlinenum;\r
- }\r
- return $word;\r
- }\r
- \r
- /**\r
- * Wrapper for {@link addSource()} used to retrieve the entire source code\r
- * organized by line number in setup()\r
- *\r
- * @param array $word full file source code\r
- *\r
- * @return void\r
- */\r
- function addFileSource($word)\r
- {\r
- $this->_sourceline = 0;\r
- foreach ($word as $token) {\r
- $this->addSource($token, true);\r
- }\r
- // var_dump($this->_file_source);\r
- }\r
- \r
- /**\r
- * Generate source token arrays organized by line number\r
- *\r
- * This code will split up tokens that contain "\n" and add them to the\r
- * source code as separate tokens on different lines.\r
- *\r
- * @param array|string $word token to add\r
- * @param bool $file true if this should be added \r
- * to {@link $_file_source}\r
- *\r
- * @return void\r
- * @uses _set_sars()\r
- */\r
- function addSource($word, $file = false)\r
- {\r
- if (is_array($word)) {\r
- $lines = str_replace("\r", '', explode("\n", $word[1]));\r
- foreach ($lines as $i => $line) {\r
- $this->_set_sars($file, array($word[0], $line));\r
- if ($i < count($lines) - 1) {\r
- // increment sourceline\r
- $this->_sourceline++;\r
- }\r
- }\r
- } else {\r
- $this->_set_sars($file, $word);\r
- }\r
- }\r
- \r
- /**\r
- * Add tokens to source code\r
- *\r
- * {@source}\r
- *\r
- * @param bool $type true if this is file source,\r
- * otherwise it is function source\r
- * @param string|array $word token to add\r
- *\r
- * @return void\r
- * @access private\r
- * @todo CS cleanup - rename to _setSars for camelCasing rule\r
- */\r
- function _set_sars($type, $word)\r
- {\r
- if ($type) {\r
- $this->_file_source[$this->_sourceline][] = $word;\r
- } else {\r
- $this->source[$this->_sourceline][] = $word;\r
- }\r
- }\r
- \r
- /**\r
- * Tell the phpDocumentorTWordParser to return the entire global variable\r
- * if it is found.\r
- *\r
- * @param array $tokens tokens that represent the global variable definition\r
- *\r
- * @return void\r
- * @uses $_global_search\r
- */\r
- function findGlobal($tokens)\r
- {\r
- if (!$tokens) {\r
- unset($this->_global_search);\r
- } else {\r
- $this->_global_search = $tokens;\r
- }\r
- }\r
- \r
- /**\r
- * backs the parser up to the previous position\r
- *\r
- * @return int|void can return a word\r
- */\r
- function backupPos()\r
- {\r
- $this->pos--;\r
- $word = $this->_all[$this->pos];\r
- if ($this->getsource) {\r
- unset($this->source[$this->_sourceline]\r
- [count($this->source[$this->_sourceline]) - 1]);\r
- if (empty($this->source[$this->_sourceline])) {\r
- unset($this->source[$this->_sourceline]);\r
- } else {\r
- $this->source[$this->_sourceline] \r
- = array_values($this->source[$this->_sourceline]);\r
- }\r
- }\r
- if (is_array($word)) {\r
- if ($word[0] == T_WHITESPACE && !$this->returnWhiteSpace) {\r
- return $this->getWord();\r
- }\r
- // seeing if we can get line numbers out of the beast\r
- if (in_array($word[0], $this->_nl_check)) {\r
- $this->linenum -= substr_count($word[1], "\n");\r
- }\r
- }\r
- }\r
-}\r
-?>\r