annotate vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2 /*
Chris@0 3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@0 4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@0 5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@0 6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Chris@0 7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Chris@0 8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Chris@0 9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Chris@0 10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Chris@0 11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Chris@0 12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Chris@0 13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@0 14 *
Chris@0 15 * This software consists of voluntary contributions made by many individuals
Chris@0 16 * and is licensed under the MIT license. For more information, see
Chris@0 17 * <http://www.doctrine-project.org>.
Chris@0 18 */
Chris@0 19
Chris@0 20 namespace Doctrine\Common\Annotations;
Chris@0 21
Chris@0 22 use Doctrine\Common\Lexer\AbstractLexer;
Chris@0 23
Chris@0 24 /**
Chris@0 25 * Simple lexer for docblock annotations.
Chris@0 26 *
Chris@0 27 * @author Benjamin Eberlei <kontakt@beberlei.de>
Chris@0 28 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
Chris@0 29 * @author Jonathan Wage <jonwage@gmail.com>
Chris@0 30 * @author Roman Borschel <roman@code-factory.org>
Chris@0 31 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
Chris@0 32 */
Chris@0 33 final class DocLexer extends AbstractLexer
Chris@0 34 {
Chris@0 35 const T_NONE = 1;
Chris@0 36 const T_INTEGER = 2;
Chris@0 37 const T_STRING = 3;
Chris@0 38 const T_FLOAT = 4;
Chris@0 39
Chris@0 40 // All tokens that are also identifiers should be >= 100
Chris@0 41 const T_IDENTIFIER = 100;
Chris@0 42 const T_AT = 101;
Chris@0 43 const T_CLOSE_CURLY_BRACES = 102;
Chris@0 44 const T_CLOSE_PARENTHESIS = 103;
Chris@0 45 const T_COMMA = 104;
Chris@0 46 const T_EQUALS = 105;
Chris@0 47 const T_FALSE = 106;
Chris@0 48 const T_NAMESPACE_SEPARATOR = 107;
Chris@0 49 const T_OPEN_CURLY_BRACES = 108;
Chris@0 50 const T_OPEN_PARENTHESIS = 109;
Chris@0 51 const T_TRUE = 110;
Chris@0 52 const T_NULL = 111;
Chris@0 53 const T_COLON = 112;
Chris@0 54
Chris@0 55 /**
Chris@0 56 * @var array
Chris@0 57 */
Chris@0 58 protected $noCase = array(
Chris@0 59 '@' => self::T_AT,
Chris@0 60 ',' => self::T_COMMA,
Chris@0 61 '(' => self::T_OPEN_PARENTHESIS,
Chris@0 62 ')' => self::T_CLOSE_PARENTHESIS,
Chris@0 63 '{' => self::T_OPEN_CURLY_BRACES,
Chris@0 64 '}' => self::T_CLOSE_CURLY_BRACES,
Chris@0 65 '=' => self::T_EQUALS,
Chris@0 66 ':' => self::T_COLON,
Chris@0 67 '\\' => self::T_NAMESPACE_SEPARATOR
Chris@0 68 );
Chris@0 69
Chris@0 70 /**
Chris@0 71 * @var array
Chris@0 72 */
Chris@0 73 protected $withCase = array(
Chris@0 74 'true' => self::T_TRUE,
Chris@0 75 'false' => self::T_FALSE,
Chris@0 76 'null' => self::T_NULL
Chris@0 77 );
Chris@0 78
Chris@0 79 /**
Chris@0 80 * {@inheritdoc}
Chris@0 81 */
Chris@0 82 protected function getCatchablePatterns()
Chris@0 83 {
Chris@0 84 return array(
Chris@0 85 '[a-z_\\\][a-z0-9_\:\\\]*[a-z_][a-z0-9_]*',
Chris@0 86 '(?:[+-]?[0-9]+(?:[\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
Chris@0 87 '"(?:""|[^"])*+"',
Chris@0 88 );
Chris@0 89 }
Chris@0 90
Chris@0 91 /**
Chris@0 92 * {@inheritdoc}
Chris@0 93 */
Chris@0 94 protected function getNonCatchablePatterns()
Chris@0 95 {
Chris@0 96 return array('\s+', '\*+', '(.)');
Chris@0 97 }
Chris@0 98
Chris@0 99 /**
Chris@0 100 * {@inheritdoc}
Chris@0 101 */
Chris@0 102 protected function getType(&$value)
Chris@0 103 {
Chris@0 104 $type = self::T_NONE;
Chris@0 105
Chris@0 106 if ($value[0] === '"') {
Chris@0 107 $value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
Chris@0 108
Chris@0 109 return self::T_STRING;
Chris@0 110 }
Chris@0 111
Chris@0 112 if (isset($this->noCase[$value])) {
Chris@0 113 return $this->noCase[$value];
Chris@0 114 }
Chris@0 115
Chris@0 116 if ($value[0] === '_' || $value[0] === '\\' || ctype_alpha($value[0])) {
Chris@0 117 return self::T_IDENTIFIER;
Chris@0 118 }
Chris@0 119
Chris@0 120 $lowerValue = strtolower($value);
Chris@0 121
Chris@0 122 if (isset($this->withCase[$lowerValue])) {
Chris@0 123 return $this->withCase[$lowerValue];
Chris@0 124 }
Chris@0 125
Chris@0 126 // Checking numeric value
Chris@0 127 if (is_numeric($value)) {
Chris@0 128 return (strpos($value, '.') !== false || stripos($value, 'e') !== false)
Chris@0 129 ? self::T_FLOAT : self::T_INTEGER;
Chris@0 130 }
Chris@0 131
Chris@0 132 return $type;
Chris@0 133 }
Chris@0 134 }