You are here

final class DocLexer in Service Container 7

Same name and namespace in other branches
  1. 7.2 modules/providers/service_container_annotation_discovery/lib/Doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php \Doctrine\Common\Annotations\DocLexer

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>

Hierarchy

Expanded class hierarchy of DocLexer

File

modules/providers/service_container_annotation_discovery/lib/Doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php, line 33

Namespace

Doctrine\Common\Annotations
View source
final class DocLexer extends AbstractLexer {
  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;

  /**
   * @var array
   */
  protected $noCase = array(
    '@' => 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_NAMESPACE_SEPARATOR,
  );

  /**
   * @var array
   */
  protected $withCase = array(
    'true' => self::T_TRUE,
    'false' => self::T_FALSE,
    'null' => self::T_NULL,
  );

  /**
   * {@inheritdoc}
   */
  protected function getCatchablePatterns() {
    return array(
      '[a-z_\\\\][a-z0-9_\\:\\\\]*[a-z_][a-z0-9_]*',
      '(?:[+-]?[0-9]+(?:[\\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
      '"(?:[^"]|"")*"',
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function getNonCatchablePatterns() {
    return array(
      '\\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

Namesort descending Modifiers Type Description Overrides
AbstractLexer::$lookahead public property
AbstractLexer::$peek private property
AbstractLexer::$position private property
AbstractLexer::$token public property
AbstractLexer::$tokens private property
AbstractLexer::getLiteral public function Gets the literal for a given token.
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.
AbstractLexer::peek public function Moves the lookahead token forward.
AbstractLexer::reset public function Resets the lexer.
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
DocLexer::$withCase protected property
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::T_AT constant
DocLexer::T_CLOSE_CURLY_BRACES constant
DocLexer::T_CLOSE_PARENTHESIS constant
DocLexer::T_COLON constant
DocLexer::T_COMMA constant
DocLexer::T_EQUALS constant
DocLexer::T_FALSE constant
DocLexer::T_FLOAT constant
DocLexer::T_IDENTIFIER constant
DocLexer::T_INTEGER constant
DocLexer::T_NAMESPACE_SEPARATOR constant
DocLexer::T_NONE constant
DocLexer::T_NULL constant
DocLexer::T_OPEN_CURLY_BRACES constant
DocLexer::T_OPEN_PARENTHESIS constant
DocLexer::T_STRING constant
DocLexer::T_TRUE constant