Source for file phpDocumentorTWordParser.inc
Documentation is available at phpDocumentorTWordParser.inc
* tokenizer extension-based lexer for PHP code
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2002-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @copyright 2002-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: phpDocumentorTWordParser.inc,v 1.5 2006/04/30 22:18:14 cellog Exp $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* Like WordParser, but expects an array of tokens from the tokenizer instead
* @subpackage WordParsers
* tokenized array from {@link token_get_all()}
* List of tokens that can contain a newline
T_ENCAPSED_AND_WHITESPACE,
T_CONSTANT_ENCAPSED_STRING,
* current source line number (relative)
* Source of the entire file, parsed into arrays of tokens on each line
var $_file_source = array();
* Line number the last comment was on
* Uses {@link token_get_all()} to tokenize the source code.
* Also, it divides the source tokens into separate lines for use by
* @var string source code
// fix php warnings on invalid source code
$this->_file_source = array();
$this->getsource = false;
* @return array source code tokens split up by line number
return $this->_file_source;
* Begin retrieving source code
* @param string word to add the beginning of source code
function retrievesource($word = '')
$this->source = array(array($word));
* Utility function to determine whether two tokens from the tokenizer are equal
* Utility function to convert a series of tokens into a string
* Retrieve a token for the phpDocumentorTParser
* This method adds source code to the array for a function to be returned
* to a {@}source} tag, and will return the token unless it is T_WHITESPACE
* and {@link $returnWhiteSpace} is false.
* The global variable search is more complicated than it is in the
* WordParser, as we have to compare an array of tokens to each other, and
* that is what this code does}}}
* @return string|arraytoken from tokenizer
if (!isset ($this->_all[$this->pos])) return false;
$oldlinenum = $this->linenum;
$word = $this->_all[$this->pos++ ];
// if we're looking for a global variable declaration, then this section
// will search the upcoming tokens to see if they match the tokens
// that define the global variable
if (isset ($this->_global_search))
if ($this->tokenEquals($word,$this->_global_search[$gpos++ ]))
for(;$gpos< count($this->_global_search);$gpos++ ,$pos++ )
if (!$this->tokenEquals($this->_global_search[$gpos],$this->_all[$pos])) $found = false;
$this->pos += count($this->_global_search) - 1;
unset ($this->_global_search);
if (in_array($word[0],$this->_nl_check))
if ($word[0] == T_WHITESPACE && !$this->returnWhiteSpace) return $this->getWord();
// seeing if we can get line numbers out of the beast
if (is_array($word) && $word[0] == T_COMMENT) $this->_docblock_linenum = $oldlinenum;
* Wrapper for {@link addSource()} used to retrieve the entire source code
* organized by line number in setup()
* @param array full file source code
// var_dump($this->_file_source);
* Generate source token arrays organized by line number
* This code will split up tokens that contain "\n" and add them to the
* source code as separate tokens on different lines.
* @param array|stringtoken to add
* @param boolean true if this should be added to {@link $_file_source}
* @param array|stringnext token, for lookahead splitting
foreach($lines as $i => $line)
$this->_set_sars($file, array($word[0],$line));
if ($i < count($lines) - 1)
} else $this->_set_sars($file, $word);
* Add tokens to source code
* @param boolean true if this is file source, otherwise it is function source
* @param string|arraytoken to add
function _set_sars($type,$word)
$this->_file_source[$this->_sourceline][] = $word;
$this->source[$this->_sourceline][] = $word;
* Tell the phpDocumentorTWordParser to return the entire global variable
* @param array tokens that represent the global variable definition
unset ($this->_global_search);
$this->_global_search = $tokens;
$word = $this->_all[$this->pos];
unset ($this->source[$this->_sourceline][count($this->source[$this->_sourceline]) - 1]);
if (empty($this->source[$this->_sourceline])) unset ($this->source[$this->_sourceline]);
else $this->source[$this->_sourceline] = array_values($this->source[$this->_sourceline]);
if ($word[0] == T_WHITESPACE && !$this->returnWhiteSpace) return $this->getWord();
// seeing if we can get line numbers out of the beast
if (in_array($word[0],$this->_nl_check))
|