2009-07-07 00:34:54 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Doctrine\Common\Annotations;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple lexer for docblock annotations.
|
|
|
|
*
|
2009-08-06 01:13:42 +04:00
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision: 3938 $
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
2009-07-07 00:34:54 +04:00
|
|
|
*/
|
2009-08-06 01:13:42 +04:00
|
|
|
class Lexer extends \Doctrine\Common\Lexer
|
2009-07-07 00:34:54 +04:00
|
|
|
{
|
2009-11-04 04:52:40 +03:00
|
|
|
const T_NONE = 1;
|
|
|
|
const T_IDENTIFIER = 2;
|
|
|
|
const T_INTEGER = 3;
|
|
|
|
const T_STRING = 4;
|
|
|
|
const T_FLOAT = 5;
|
|
|
|
|
|
|
|
const T_AT = 101;
|
|
|
|
const T_CLOSE_CURLY_BRACES = 102;
|
|
|
|
const T_CLOSE_PARENTHESIS = 103;
|
|
|
|
const T_COMMA = 104;
|
|
|
|
const T_EQUALS = 105;
|
|
|
|
const T_FALSE = 106;
|
|
|
|
const T_NAMESPACE_SEPARATOR = 107;
|
|
|
|
const T_OPEN_CURLY_BRACES = 108;
|
|
|
|
const T_OPEN_PARENTHESIS = 109;
|
|
|
|
const T_TRUE = 110;
|
2009-07-07 00:34:54 +04:00
|
|
|
|
|
|
|
/**
|
2009-08-06 01:13:42 +04:00
|
|
|
* @inheritdoc
|
2009-07-07 00:34:54 +04:00
|
|
|
*/
|
2009-08-06 01:13:42 +04:00
|
|
|
protected function getCatchablePatterns()
|
2009-07-07 00:34:54 +04:00
|
|
|
{
|
2009-08-06 01:13:42 +04:00
|
|
|
return array(
|
2010-02-24 17:33:12 +03:00
|
|
|
'[a-z_][a-z0-9_:]*',
|
2009-08-06 01:13:42 +04:00
|
|
|
'(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
|
|
|
|
'"(?:[^"]|"")*"'
|
|
|
|
);
|
2009-07-07 00:34:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-06 01:13:42 +04:00
|
|
|
* @inheritdoc
|
2009-07-07 00:34:54 +04:00
|
|
|
*/
|
2009-08-06 01:13:42 +04:00
|
|
|
protected function getNonCatchablePatterns()
|
2009-07-07 00:34:54 +04:00
|
|
|
{
|
2009-08-06 01:13:42 +04:00
|
|
|
return array('\s+', '\*+', '(.)');
|
2009-07-07 00:34:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-06 01:13:42 +04:00
|
|
|
* @inheritdoc
|
2009-07-07 00:34:54 +04:00
|
|
|
*/
|
2009-08-06 01:13:42 +04:00
|
|
|
protected function _getType(&$value)
|
2009-07-07 00:34:54 +04:00
|
|
|
{
|
|
|
|
$type = self::T_NONE;
|
|
|
|
$newVal = $this->_getNumeric($value);
|
2009-08-08 01:47:21 +04:00
|
|
|
|
2009-11-04 04:52:40 +03:00
|
|
|
// Checking numeric value
|
2009-07-07 00:34:54 +04:00
|
|
|
if ($newVal !== false){
|
|
|
|
$value = $newVal;
|
2009-08-08 01:47:21 +04:00
|
|
|
|
2009-11-04 04:52:40 +03:00
|
|
|
return (strpos($value, '.') !== false || stripos($value, 'e') !== false)
|
|
|
|
? self::T_FLOAT : self::T_INTEGER;
|
2009-07-07 00:34:54 +04:00
|
|
|
}
|
2009-08-08 01:47:21 +04:00
|
|
|
|
2009-07-07 00:34:54 +04:00
|
|
|
if ($value[0] === '"') {
|
|
|
|
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
|
2009-11-04 04:52:40 +03:00
|
|
|
|
|
|
|
return self::T_STRING;
|
|
|
|
} else {
|
2009-12-22 05:15:12 +03:00
|
|
|
switch (strtolower($value)) {
|
2009-11-04 04:52:40 +03:00
|
|
|
case '@': return self::T_AT;
|
|
|
|
case ',': return self::T_COMMA;
|
|
|
|
case '(': return self::T_OPEN_PARENTHESIS;
|
|
|
|
case ')': return self::T_CLOSE_PARENTHESIS;
|
|
|
|
case '{': return self::T_OPEN_CURLY_BRACES;
|
|
|
|
case '}': return self::T_CLOSE_CURLY_BRACES;
|
|
|
|
case '=': return self::T_EQUALS;
|
|
|
|
case '\\': return self::T_NAMESPACE_SEPARATOR;
|
2009-12-22 05:15:12 +03:00
|
|
|
case 'true': return self::T_TRUE;
|
|
|
|
case 'false': return self::T_FALSE;
|
2009-11-04 04:52:40 +03:00
|
|
|
default:
|
2009-12-22 05:15:12 +03:00
|
|
|
if (ctype_alpha($value[0]) || $value[0] === '_') {
|
|
|
|
return self::T_IDENTIFIER;
|
|
|
|
}
|
|
|
|
|
2009-11-04 04:52:40 +03:00
|
|
|
break;
|
|
|
|
}
|
2009-07-07 00:34:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-08-08 01:47:21 +04:00
|
|
|
* Checks if a value is numeric or not
|
|
|
|
*
|
|
|
|
* @param mixed $value Value to be inspected
|
|
|
|
* @return boolean|integer|float Processed value
|
2009-07-07 00:34:54 +04:00
|
|
|
*/
|
|
|
|
private function _getNumeric($value)
|
|
|
|
{
|
|
|
|
if ( ! is_scalar($value)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Checking for valid numeric numbers: 1.234, -1.234e-2
|
|
|
|
if (is_numeric($value)) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|