class DocLexer
Simple lexer for docblock annotations.
@template-extends AbstractLexer<DocLexer::T_*, string>
Hierarchy
- class \Doctrine\Common\Lexer\AbstractLexer
- class \Doctrine\Common\Annotations\DocLexer extends \Doctrine\Common\Lexer\AbstractLexer
Expanded class hierarchy of DocLexer
1 file declares its use of DocLexer
- DocParser.php in core/
lib/ Drupal/ Component/ Annotation/ Doctrine/ DocParser.php - This class is a near-copy of Doctrine\Common\Annotations\DocParser, which is part of the Doctrine project: <http://www.doctrine-project.org>. It was copied from version 1.2.7.
File
-
vendor/
doctrine/ annotations/ lib/ Doctrine/ Common/ Annotations/ DocLexer.php, line 21
Namespace
Doctrine\Common\AnnotationsView source
final class DocLexer extends AbstractLexer {
public const T_NONE = 1;
public const T_INTEGER = 2;
public const T_STRING = 3;
public const T_FLOAT = 4;
// All tokens that are also identifiers should be >= 100
public const T_IDENTIFIER = 100;
public const T_AT = 101;
public const T_CLOSE_CURLY_BRACES = 102;
public const T_CLOSE_PARENTHESIS = 103;
public const T_COMMA = 104;
public const T_EQUALS = 105;
public const T_FALSE = 106;
public const T_NAMESPACE_SEPARATOR = 107;
public const T_OPEN_CURLY_BRACES = 108;
public const T_OPEN_PARENTHESIS = 109;
public const T_TRUE = 110;
public const T_NULL = 111;
public const T_COLON = 112;
public const T_MINUS = 113;
/** @var array<string, self::T*> */
protected $noCase = [
'@' => self::T_AT,
',' => self::T_COMMA,
'(' => self::T_OPEN_PARENTHESIS,
')' => self::T_CLOSE_PARENTHESIS,
'{' => self::T_OPEN_CURLY_BRACES,
'}' => self::T_CLOSE_CURLY_BRACES,
'=' => self::T_EQUALS,
':' => self::T_COLON,
'-' => self::T_MINUS,
'\\' => self::T_NAMESPACE_SEPARATOR,
];
/** @var array<string, self::T*> */
protected $withCase = [
'true' => self::T_TRUE,
'false' => self::T_FALSE,
'null' => self::T_NULL,
];
/**
* Whether the next token starts immediately, or if there were
* non-captured symbols before that
*/
public function nextTokenIsAdjacent() : bool {
return $this->token === null || $this->lookahead !== null && $this->lookahead->position - $this->token->position === strlen($this->token->value);
}
/**
* {@inheritDoc}
*/
protected function getCatchablePatterns() {
return [
'[a-z_\\\\][a-z0-9_\\:\\\\]*[a-z_][a-z0-9_]*',
'(?:[+-]?[0-9]+(?:[\\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
'"(?:""|[^"])*+"',
];
}
/**
* {@inheritDoc}
*/
protected function getNonCatchablePatterns() {
return [
'\\s+',
'\\*+',
'(.)',
];
}
/**
* {@inheritDoc}
*/
protected function getType(&$value) {
$type = self::T_NONE;
if ($value[0] === '"') {
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
return self::T_STRING;
}
if (isset($this->noCase[$value])) {
return $this->noCase[$value];
}
if ($value[0] === '_' || $value[0] === '\\' || ctype_alpha($value[0])) {
return self::T_IDENTIFIER;
}
$lowerValue = strtolower($value);
if (isset($this->withCase[$lowerValue])) {
return $this->withCase[$lowerValue];
}
// Checking numeric value
if (is_numeric($value)) {
return strpos($value, '.') !== false || stripos($value, 'e') !== false ? self::T_FLOAT : self::T_INTEGER;
}
return $type;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
AbstractLexer::$input | private | property | Lexer original input string. | ||
AbstractLexer::$lookahead | public | property | The next token in the input. | ||
AbstractLexer::$peek | private | property | Current peek of current lexer position. | ||
AbstractLexer::$position | private | property | Current lexer position in input string. | ||
AbstractLexer::$regex | private | property | Composed regex for input parsing. | ||
AbstractLexer::$token | public | property | The last matched/seen token. | ||
AbstractLexer::$tokens | private | property | Array of scanned tokens. | ||
AbstractLexer::getInputUntilPosition | public | function | Retrieve the original lexer's input until a given position. | ||
AbstractLexer::getLiteral | public | function | Gets the literal for a given token. | ||
AbstractLexer::getModifiers | protected | function | Regex modifiers | 1 | |
AbstractLexer::glimpse | public | function | Peeks at the next token, returns it and immediately resets the peek. | ||
AbstractLexer::isA | public | function | Checks if given value is identical to the given token. | ||
AbstractLexer::isNextToken | public | function | Checks whether a given token matches the current lookahead. | ||
AbstractLexer::isNextTokenAny | public | function | Checks whether any of the given tokens matches the current lookahead. | ||
AbstractLexer::moveNext | public | function | Moves to the next token in the input string. | 1 | |
AbstractLexer::peek | public | function | Moves the lookahead token forward. | ||
AbstractLexer::reset | public | function | Resets the lexer. | 1 | |
AbstractLexer::resetPeek | public | function | Resets the peek pointer to 0. | ||
AbstractLexer::resetPosition | public | function | Resets the lexer position on the input to the given position. | ||
AbstractLexer::scan | protected | function | Scans the input string for tokens. | ||
AbstractLexer::setInput | public | function | Sets the input data to be tokenized. | ||
AbstractLexer::skipUntil | public | function | Tells the lexer to skip input tokens until it sees a token with the given value. | ||
DocLexer::$noCase | protected | property | @var array<string, self::T*> | ||
DocLexer::$withCase | protected | property | @var array<string, self::T*> | ||
DocLexer::getCatchablePatterns | protected | function | Lexical catchable patterns. | Overrides AbstractLexer::getCatchablePatterns | |
DocLexer::getNonCatchablePatterns | protected | function | Lexical non-catchable patterns. | Overrides AbstractLexer::getNonCatchablePatterns | |
DocLexer::getType | protected | function | Retrieve token type. Also processes the token value if necessary. | Overrides AbstractLexer::getType | |
DocLexer::nextTokenIsAdjacent | public | function | Whether the next token starts immediately, or if there were non-captured symbols before that |
||
DocLexer::T_AT | public | constant | |||
DocLexer::T_CLOSE_CURLY_BRACES | public | constant | |||
DocLexer::T_CLOSE_PARENTHESIS | public | constant | |||
DocLexer::T_COLON | public | constant | |||
DocLexer::T_COMMA | public | constant | |||
DocLexer::T_EQUALS | public | constant | |||
DocLexer::T_FALSE | public | constant | |||
DocLexer::T_FLOAT | public | constant | |||
DocLexer::T_IDENTIFIER | public | constant | |||
DocLexer::T_INTEGER | public | constant | |||
DocLexer::T_MINUS | public | constant | |||
DocLexer::T_NAMESPACE_SEPARATOR | public | constant | |||
DocLexer::T_NONE | public | constant | |||
DocLexer::T_NULL | public | constant | |||
DocLexer::T_OPEN_CURLY_BRACES | public | constant | |||
DocLexer::T_OPEN_PARENTHESIS | public | constant | |||
DocLexer::T_STRING | public | constant | |||
DocLexer::T_TRUE | public | constant |