Simple lexer for docblock annotations.
@author Benjamin Eberlei <kontakt@beberlei.de> @author Guilherme Blanco <guilhermeblanco@hotmail.com> @author Jonathan Wage <jonwage@gmail.com> @author Roman Borschel <roman@code-factory.org> @author Johannes M. Schmitt <schmittjoh@gmail.com>
Expanded class hierarchy of DocLexer
final class DocLexer extends Lexer {
const T_NONE = 1;
const T_INTEGER = 2;
const T_STRING = 3;
const T_FLOAT = 4;
// All tokens that are also identifiers should be >= 100
const T_IDENTIFIER = 100;
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;
const T_NULL = 111;
const T_COLON = 112;
/**
* {@inheritdoc}
*/
protected function getCatchablePatterns() {
return array(
'[a-z_\\\\][a-z0-9_\\:\\\\]*[a-z]{1}',
'(?:[+-]?[0-9]+(?:[\\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
'"(?:[^"]|"")*"',
);
}
/**
* {@inheritdoc}
*/
protected function getNonCatchablePatterns() {
return array(
'\\s+',
'\\*+',
'(.)',
);
}
/**
* {@inheritdoc}
*
* @param string $value
*
* @return int
*/
protected function getType(&$value) {
$type = self::T_NONE;
// Checking numeric value
if (is_numeric($value)) {
return strpos($value, '.') !== false || stripos($value, 'e') !== false ? self::T_FLOAT : self::T_INTEGER;
}
if ($value[0] === '"') {
$value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
return self::T_STRING;
}
else {
switch (strtolower($value)) {
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;
case 'true':
return self::T_TRUE;
case 'false':
return self::T_FALSE;
case 'null':
return self::T_NULL;
case ':':
return self::T_COLON;
default:
if (ctype_alpha($value[0]) || $value[0] === '_' || $value[0] === '\\') {
return self::T_IDENTIFIER;
}
break;
}
}
return $type;
}
}
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DocLexer:: |
protected | function |
Lexical catchable patterns. Overrides Lexer:: |
|
DocLexer:: |
protected | function |
Lexical non-catchable patterns. Overrides Lexer:: |
|
DocLexer:: |
protected | function |
Overrides Lexer:: |
|
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
DocLexer:: |
constant | |||
Lexer:: |
public | property | ||
Lexer:: |
private | property | ||
Lexer:: |
private | property | ||
Lexer:: |
public | property | ||
Lexer:: |
private | property | ||
Lexer:: |
public | function | Gets the literal for a given token. | |
Lexer:: |
public | function | Peeks at the next token, returns it and immediately resets the peek. | |
Lexer:: |
public | function | Checks if given value is identical to the given token | |
Lexer:: |
public | function | Checks whether a given token matches the current lookahead. | |
Lexer:: |
public | function | Checks whether any of the given tokens matches the current lookahead | |
Lexer:: |
public | function | Moves to the next token in the input string. | |
Lexer:: |
public | function | Moves the lookahead token forward. | |
Lexer:: |
public | function | Resets the lexer. | |
Lexer:: |
public | function | Resets the peek pointer to 0. | |
Lexer:: |
public | function | Resets the lexer position on the input to the given position. | |
Lexer:: |
protected | function | Scans the input string for tokens. | |
Lexer:: |
public | function | Sets the input data to be tokenized. | |
Lexer:: |
public | function | Tells the lexer to skip input tokens until it sees a token with the given value. |