+++ /dev/null
-<?php\r
-/**\r
- * a generic lexer\r
- * \r
- * phpDocumentor :: automatic documentation generator\r
- * \r
- * PHP versions 4 and 5\r
- *\r
- * Copyright (c) 2000-2007 Joshua Eichorn\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 WordParsers\r
- * @author Joshua Eichorn <jeichorn@phpdoc.org>\r
- * @copyright 2000-2007 Joshua Eichorn\r
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL\r
- * @version CVS: $Id: WordParser.inc,v 1.5 2007/11/14 01:37:03 ashnazg Exp $\r
- * @link http://www.phpdoc.org\r
- * @link http://pear.php.net/PhpDocumentor\r
- * @since 0.1\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- */\r
-\r
-/**\r
- * Retrieves tokens from source code for use by the Parser\r
- *\r
- * @category ToolsAndUtilities\r
- * @package phpDocumentor\r
- * @subpackage WordParsers\r
- * @author Joshua Eichorn <jeichorn@phpdoc.org>\r
- * @copyright 2000-2007 Joshua Eichorn\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
- * @see Parser\r
- * @todo CS cleanup - change package to PhpDocumentor\r
- */\r
-class WordParser\r
-{\r
- /*\r
- New lines around the world\r
- Macintosh: \r \r
- Unix : \n \r
- Windows : \r\n \r
- */\r
- \r
- /**#@+\r
- * @access private\r
- */\r
- /**\r
- * List of text that separates tokens, used to retrieve tokens\r
- * @var array\r
- */\r
- var $wordseperators = array();\r
- \r
- /**\r
- * Position within input of the cursor pointing to the next text to be\r
- * retrieved as a token\r
- * @var integer\r
- */\r
- var $pos = 0;\r
-\r
- /**\r
- * Size of the input source code\r
- * @var integer\r
- */\r
- var $size;\r
-\r
- /**\r
- * Source code\r
- * @var string\r
- */\r
- var $data;\r
-\r
- var $cache;\r
- /**\r
- * Current line number\r
- * @var integer\r
- */\r
- var $linenum = 0;\r
- /**\r
- * Position the cursor was at the last time line numbers were counted, used\r
- * to guarantee that line numbers are incremented\r
- * @var integer\r
- */\r
- var $linenumpos = 0;\r
- \r
- /**\r
- * Used for {@}source} tag, contains currently parsed function source\r
- * @var string\r
- */\r
- var $source = '';\r
- /**\r
- * flag, determines whether tokens are added to {@link $source}\r
- * @var boolean\r
- */\r
- var $getsource = false;\r
-\r
- /**\r
- * If true, then white space is returned as a part of tokens, otherwise\r
- * tokens are trimmed\r
- * @var boolean\r
- */\r
- var $returnWhiteSpace = false;\r
- /**#@-*/\r
-\r
- /**\r
- * Initialize the WordParser\r
- *\r
- * @param string &$input source code\r
- * \r
- * @return void\r
- */\r
- function setup(&$input)\r
- {\r
- $this->size = strlen($input);\r
- $this->data = & $input;\r
- $this->pos = 0;\r
- $this->linenum = 0;\r
- $this->linenumpos = 0;\r
- $this->cache = array();\r
- //$this->run = 0;\r
- //$this->word = WORD_PARSER_RET_WORD;\r
- }\r
- \r
- /**\r
- * Retrieve source code for the last function/method\r
- *\r
- * @return string\r
- */\r
- function getSource()\r
- {\r
- $source = $this->source;\r
- $this->source = '';\r
- $this->getsource = false;\r
- return $source;\r
- }\r
- \r
- /**\r
- * Used to tell the WordParser to start retrieving source code\r
- *\r
- * @param string $word source code\r
- *\r
- * @return void\r
- * @access private\r
- */\r
- function retrievesource($word = '')\r
- {\r
- $this->source = $word;\r
- $this->getsource = true;\r
- }\r
-\r
- /**\r
- * Retrieve a token from the token list\r
- *\r
- * The {@link Parser} class relies upon this method to retrieve the next\r
- * token. The {@link $wordseperators} array is a collection of strings\r
- * that delineate tokens for the current parser state. $wordseperators\r
- * is set by the parser with a call to {@link Parser::configWordParser()}\r
- * every time a new parser state is reached.\r
- *\r
- * For example, while parsing the source code for a class, the word\r
- * <code>var</code> is a token, and <code>global</code> is not,\r
- * but inside a function, the reverse is true. The parser state\r
- * {@link PARSER_STATE_CLASS} has a token list that includes whitespace,\r
- * code delimiters like ; and {}, and comment/DocBlock indicators\r
- *\r
- * If the whitespace option has been turned off using\r
- * {@link setWhitespace()}, then no whitespace is returned with tokens\r
- *\r
- * {@internal\r
- * In the first segment of the function, the code attempts to find the next\r
- * token. A cache is used to speed repetitious tasks. The $tpos variable\r
- * is used to hold the position of the next token. $npos is used to\r
- * hold the end of the token, and so $npos - $tpos will give the length\r
- * of the token. This is used to allow tokens that contain whitespace,\r
- * should that option be desired.\r
- *\r
- * {@link $data} is of course the string containing the PHP code to be\r
- * parsed, and {@link $pos} is the cursor, or current location within the\r
- * parsed data.\r
- * }}\r
- *\r
- * @return string|false the next token, an empty string if there are no\r
- * token separators in the $wordseperators array,\r
- * or false if the end of input has been reached\r
- */\r
- function getWord()\r
- {\r
- //$st = $this->mtime();\r
- if ($this->size == $this->pos) {\r
- return false;\r
- }\r
-\r
- // assume, for starting, that the token is from $this->pos to the end\r
- $npos = $this->size;\r
- if (is_array($this->wordseperators)) {\r
- //$this->wordseperators = array();\r
- foreach ($this->wordseperators as $sep) {\r
- // cache is set if this separator has been tested\r
- if (isset($this->cache[$sep])) {\r
- $tpos = $this->cache[$sep];\r
- } else {\r
- $tpos = false;\r
- }\r
- if ($tpos < $this->pos || !is_int($tpos)) {\r
- // find the position of the next token separator\r
- $tpos = strpos($this->data, $sep, $this->pos);\r
- }\r
-\r
- // was a token separator found \r
- // that is closer to the current location?\r
- if ( ($tpos < $npos) && !($tpos === false)) {\r
- //echo trim($sep) . "=$tpos\n";\r
- // set the length of the token \r
- // to be from $this->pos to\r
- // the next token separator\r
- $npos = $tpos;\r
- $seplen = strlen($sep);\r
- } else if (!($tpos === false)) {\r
- $this->cache[$sep] = $tpos;\r
- }\r
- }\r
- } else {\r
- // no token separators, tell the parser to choose a new state\r
- return "";\r
- }\r
-\r
- $len = $npos - $this->pos;\r
- if ($len == 0) {\r
- $len = $seplen;\r
- }\r
-\r
- //$st3 = $this->mtime();\r
- $word = substr($this->data, $this->pos, $len);\r
- \r
- // Change random other os newlines to the unix one\r
- if ($word == "\r" || $word == "\r\n") {\r
- $word = "\n";\r
- }\r
- \r
- if ($this->linenumpos <= $this->pos) {\r
- $this->linenumpos = $this->pos + $len;\r
- $this->linenum += count(explode("\n", $word)) - 1;\r
- }\r
-\r
- if ($this->getsource) {\r
- $this->source .= $word;\r
- }\r
- $this->pos = $this->pos + $len;\r
- //$this->word = WORD_PARSER_RET_SEP;\r
-\r
- // Things like // commenats rely on the newline \r
- // to find their end so im going to have to return them\r
- // never return worthless white space /t ' '\r
- if ($this->returnWhiteSpace == false) {\r
- if (strlen(trim($word)) == 0 && $word != "\n") {\r
- $word = $this->getWord();\r
- }\r
- }\r
- //$this->time3 = $this->time3 + ($this->mtime() - $st3);\r
- //$this->time = $this->time + ($this->mtime() - $st);\r
- return $word;\r
- }\r
- \r
-\r
- /**\r
- * Returns the current pointer position, or 1 character after the end of the word\r
- *\r
- * @return int the position\r
- */\r
- function getPos()\r
- {\r
- return $this->pos;\r
- }\r
-\r
- /**\r
- * Unused\r
- *\r
- * {@source}\r
- *\r
- * @param integer $start starting position\r
- * @param integer $len length of block to retrieve\r
- *\r
- * @return string the requested block of characters\r
- */\r
- function getBlock($start, $len)\r
- {\r
- return substr($this->data, $start, $len);\r
- }\r
-\r
- /**\r
- * Sets the list of possible separator tokens\r
- *\r
- * @param array &$seps array of strings that separate tokens\r
- *\r
- * @return void\r
- * @uses $wordseperators\r
- */\r
- function setSeperator(&$seps)\r
- {\r
- $this->wordseperators = &$seps;\r
- }\r
-\r
- /**\r
- * Set the internal cursor within the source code\r
- *\r
- * @param integer $pos the position\r
- *\r
- * @return void\r
- */\r
- function setPos($pos)\r
- {\r
- $this->pos = $pos;\r
- }\r
- \r
- /**\r
- * Backup to the previous token so that it can be retrieved again in a new\r
- * context.\r
- *\r
- * Occasionally, a word will be passed to an event handler that should be\r
- * handled by another event handler. This method allows that to happen.\r
- *\r
- * @param string $word token to back up to\r
- *\r
- * @return void\r
- */\r
- function backupPos($word)\r
- {\r
- if ($this->getsource) $this->source = \r
- substr($this->source, 0, strlen($this->source) - 1);\r
- $this->pos = $this->pos - strlen($word);\r
- }\r
-\r
- /**\r
- * set parser to return or strip whitespace\r
- *\r
- * @param boolean $val flag to return or strip whitespace\r
- *\r
- * @return void\r
- */\r
- function setWhitespace($val = false)\r
- {\r
- $this->returnWhiteSpace = $val;\r
- }\r
-}\r
-?>\r