| 1 |
1088
|
mapi |
<?php |
|
| 2 |
↓
|
mapi |
/** |
|
| 3 |
↓
|
mapi |
* This file is part of PHP_Depend. |
|
| 4 |
↓
|
mapi |
* |
|
| 5 |
↓
|
mapi |
* PHP Version 5 |
|
| 6 |
↓
|
mapi |
* |
|
| 7 |
↓
|
mapi |
* Copyright (c) 2008-2010, Manuel Pichler <mapi@pdepend.org>. |
|
| 8 |
↓
|
mapi |
* All rights reserved. |
|
| 9 |
↓
|
mapi |
* |
|
| 10 |
↓
|
mapi |
* Redistribution and use in source and binary forms, with or without |
|
| 11 |
↓
|
mapi |
* modification, are permitted provided that the following conditions |
|
| 12 |
↓
|
mapi |
* are met: |
|
| 13 |
↓
|
mapi |
* |
|
| 14 |
↓
|
mapi |
* * Redistributions of source code must retain the above copyright |
|
| 15 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer. |
|
| 16 |
↓
|
mapi |
* |
|
| 17 |
↓
|
mapi |
* * Redistributions in binary form must reproduce the above copyright |
|
| 18 |
↓
|
mapi |
* notice, this list of conditions and the following disclaimer in |
|
| 19 |
↓
|
mapi |
* the documentation and/or other materials provided with the |
|
| 20 |
↓
|
mapi |
* distribution. |
|
| 21 |
↓
|
mapi |
* |
|
| 22 |
↓
|
mapi |
* * Neither the name of Manuel Pichler nor the names of his |
|
| 23 |
↓
|
mapi |
* contributors may be used to endorse or promote products derived |
|
| 24 |
↓
|
mapi |
* from this software without specific prior written permission. |
|
| 25 |
↓
|
mapi |
* |
|
| 26 |
↓
|
mapi |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
| 27 |
↓
|
mapi |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
| 28 |
↓
|
mapi |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
| 29 |
↓
|
mapi |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|
| 30 |
↓
|
mapi |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|
| 31 |
↓
|
mapi |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
| 32 |
↓
|
mapi |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
| 33 |
↓
|
mapi |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
| 34 |
↓
|
mapi |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
| 35 |
↓
|
mapi |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
| 36 |
↓
|
mapi |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
| 37 |
↓
|
mapi |
* POSSIBILITY OF SUCH DAMAGE. |
|
| 38 |
↓
|
mapi |
* |
|
| 39 |
↓
|
mapi |
* @category PHP |
|
| 40 |
↓
|
mapi |
* @package PHP_Depend |
|
| 41 |
↓
|
mapi |
* @subpackage Parser |
|
| 42 |
↓
|
mapi |
* @author Manuel Pichler <mapi@pdepend.org> |
|
| 43 |
↓
|
mapi |
* @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
| 44 |
↓
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 45 |
↓
|
mapi |
* @version SVN: $Id$ |
|
| 46 |
↓
|
mapi |
* @link http://www.pdepend.org/ |
|
| 47 |
↓
|
mapi |
*/ |
|
| 48 |
↓
|
mapi |
|
|
| 49 |
↓
|
mapi |
require_once 'PHP/Depend/Parser/FunctionNameParser.php'; |
|
| 50 |
↓
|
mapi |
require_once 'PHP/Depend/Parser/TokenStreamEndException.php'; |
|
| 51 |
↓
|
mapi |
require_once 'PHP/Depend/Parser/UnexpectedTokenException.php'; |
|
| 52 |
↓
|
mapi |
|
|
| 53 |
↓
|
mapi |
/** |
|
| 54 |
↓
|
mapi |
* Default implementation of the function name parser. This implementation is |
|
| 55 |
↓
|
mapi |
* not fixed to a special php version and its keywords. |
|
| 56 |
↓
|
mapi |
* |
|
| 57 |
↓
|
mapi |
* @category PHP |
|
| 58 |
↓
|
mapi |
* @package PHP_Depend |
|
| 59 |
↓
|
mapi |
* @subpackage Parser |
|
| 60 |
↓
|
mapi |
* @author Manuel Pichler <mapi@pdepend.org> |
|
| 61 |
↓
|
mapi |
* @copyright 2008-2010 Manuel Pichler. All rights reserved. |
|
| 62 |
↓
|
mapi |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|
| 63 |
↓
|
mapi |
* @version Release: @package_version@ |
|
| 64 |
↓
|
mapi |
* @link http://www.pdepend.org/ |
|
| 65 |
↓
|
mapi |
*/ |
|
| 66 |
↓
|
mapi |
class PHP_Depend_Parser_FunctionNameParserImpl |
|
| 67 |
↓
|
mapi |
implements PHP_Depend_Parser_FunctionNameParser |
|
| 68 |
↓
|
mapi |
{ |
|
| 69 |
↓
|
mapi |
/** |
|
| 70 |
↓
|
mapi |
* The used tokenizer instance. |
|
| 71 |
↓
|
mapi |
* |
|
| 72 |
↓
|
mapi |
* @var PHP_Depend_TokenizerI |
|
| 73 |
↓
|
mapi |
*/ |
|
| 74 |
↓
|
mapi |
private $_tokenizer = null; |
|
| 75 |
↓
|
mapi |
|
|
| 76 |
↓
|
mapi |
/** |
|
| 77 |
↓
|
mapi |
* The used token stack. |
|
| 78 |
↓
|
mapi |
* |
|
| 79 |
↓
|
mapi |
* @var PHP_Depend_Parser_TokenStack |
|
| 80 |
↓
|
mapi |
*/ |
|
| 81 |
↓
|
mapi |
private $_tokenStack = null; |
|
| 82 |
↓
|
mapi |
|
|
| 83 |
1089
|
mapi |
/** |
|
| 84 |
↓
|
mapi |
* Setter method for the context tokenizer instance. |
|
| 85 |
↓
|
mapi |
* |
|
| 86 |
↓
|
mapi |
* @param PHP_Depend_TokenizerI $tokenizer The context tokenizer. |
|
| 87 |
↓
|
mapi |
* |
|
| 88 |
↓
|
mapi |
* @return void |
|
| 89 |
↓
|
mapi |
*/ |
|
| 90 |
1088
|
mapi |
public function setTokenizer(PHP_Depend_TokenizerI $tokenizer) |
|
| 91 |
↓
|
mapi |
{ |
|
| 92 |
↓
|
mapi |
$this->_tokenizer = $tokenizer; |
|
| 93 |
↓
|
mapi |
} |
|
| 94 |
↓
|
mapi |
|
|
| 95 |
1089
|
mapi |
/** |
|
| 96 |
↓
|
mapi |
* Setter method for the context token stack instance. |
|
| 97 |
↓
|
mapi |
* |
|
| 98 |
↓
|
mapi |
* @param PHP_Depend_Parser_TokenStack $tokenStack The context token stack |
|
| 99 |
↓
|
mapi |
* |
|
| 100 |
↓
|
mapi |
* @return void |
|
| 101 |
↓
|
mapi |
*/ |
|
| 102 |
1088
|
mapi |
public function setTokenStack(PHP_Depend_Parser_TokenStack $tokenStack) |
|
| 103 |
↓
|
mapi |
{ |
|
| 104 |
↓
|
mapi |
$this->_tokenStack = $tokenStack; |
|
| 105 |
↓
|
mapi |
} |
|
| 106 |
↓
|
mapi |
|
|
| 107 |
↓
|
mapi |
/** |
|
| 108 |
↓
|
mapi |
* Parses a function name from the given tokenizer and returns the string |
|
| 109 |
↓
|
mapi |
* literal representing the function name. If no valid token exists in the |
|
| 110 |
↓
|
mapi |
* token stream, this method will throw an exception. |
|
| 111 |
↓
|
mapi |
* |
|
| 112 |
↓
|
mapi |
* @return string |
|
| 113 |
↓
|
mapi |
* @throws PHP_Depend_Parser_UnexpectedTokenException When the next available |
|
| 114 |
↓
|
mapi |
* token does not represent a valid php function name. |
|
| 115 |
↓
|
mapi |
* @throws PHP_Depend_Parser_TokenStreamEndException When there is no next |
|
| 116 |
↓
|
mapi |
* token available in the given token stream. |
|
| 117 |
↓
|
mapi |
*/ |
|
| 118 |
↓
|
mapi |
public function parse() |
|
| 119 |
↓
|
mapi |
{ |
|
| 120 |
↓
|
mapi |
switch ($this->_tokenizer->peek()) { |
|
| 121 |
↓
|
mapi |
|
|
| 122 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_STRING: |
|
| 123 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_USE: |
|
| 124 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_GOTO: |
|
| 125 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_NULL: |
|
| 126 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_SELF: |
|
| 127 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_TRUE: |
|
| 128 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_FALSE: |
|
| 129 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_NAMESPACE: |
|
| 130 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_DIR: |
|
| 131 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_NS_C: |
|
| 132 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_PARENT: |
|
| 133 |
↓
|
mapi |
$token = $this->_tokenizer->next(); |
|
| 134 |
↓
|
mapi |
$this->_tokenStack->add($token); |
|
| 135 |
↓
|
mapi |
|
|
| 136 |
↓
|
mapi |
return $token->image; |
|
| 137 |
↓
|
mapi |
|
|
| 138 |
↓
|
mapi |
case PHP_Depend_TokenizerI::T_EOF: |
|
| 139 |
1090
|
mapi |
throw new PHP_Depend_Parser_TokenStreamEndException($this->_tokenizer); |
|
| 140 |
1088
|
mapi |
} |
|
| 141 |
1196
|
mapi |
throw new PHP_Depend_Parser_UnexpectedTokenException( |
|
| 142 |
↓
|
mapi |
$this->_tokenizer->next(), |
|
| 143 |
↓
|
mapi |
$this->_tokenizer->getSourceFile() |
|
| 144 |
↓
|
mapi |
); |
|
| 145 |
1088
|
mapi |
} |
|
| 146 |
↓
|
mapi |
} |
|