lex() public méthode

Converts a string into a sequence of tokens.
public lex ( string $value ) : array
$value string
Résultat array
Exemple #1
0
 /**
  * {@inheritdoc}
  *
  * @throws MalformedFunctionException
  */
 public function lex(string $value) : array
 {
     if (false === $this->functionTokenizer->isTokenized($value)) {
         $value = $this->functionTokenizer->tokenize($value);
     }
     return $this->decoratedLexer->lex($value);
 }
Exemple #2
0
 /**
  * @inheritdoc
  */
 public function parse(string $value)
 {
     $tokens = $this->lexer->lex($value);
     $parsedTokens = [];
     foreach ($tokens as $token) {
         $parsedTokens = $this->parseToken($parsedTokens, $this->tokenParser, $token);
     }
     return 1 === count($parsedTokens) ? $parsedTokens[0] : new ListValue($parsedTokens);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  *
  * @throws LexException
  */
 public function lex(string $value) : array
 {
     foreach (self::PATTERNS as $pattern => $tokenTypeConstant) {
         if (1 === preg_match($pattern, $value, $matches)) {
             if (null === $tokenTypeConstant) {
                 throw InvalidArgumentExceptionFactory::createForInvalidExpressionLanguageToken($value);
             }
             return [new Token($matches[0], new TokenType($tokenTypeConstant))];
         }
     }
     return $this->lexer->lex($value);
 }
 /**
  * @dataProvider provideValues
  */
 public function testTestCanLexValues(string $value, $expected)
 {
     try {
         $actual = $this->lexer->lex($value);
         if (null === $expected) {
             $this->fail(sprintf('Expected exception to be thrown for "%s", got "%s" instead.', $value, var_export($actual, true)));
         }
     } catch (\InvalidArgumentException $exception) {
         if (null === $expected) {
             return;
         }
         throw $exception;
     } catch (LexException $exception) {
         if (null === $expected) {
             return;
         }
         throw $exception;
     }
     $this->assertEquals($expected, $actual, var_export($actual, true));
     $this->assertSameSize($expected, $actual);
 }
Exemple #5
0
 /**
  * @param LexerInterface $referenceLexer
  * @param string         $valueFragment
  *
  * @throws LexException
  *
  * @return Token[]
  */
 private function lexFragment(LexerInterface $referenceLexer, string $valueFragment) : array
 {
     foreach (self::PATTERNS as $pattern => $tokenTypeConstant) {
         if (1 === preg_match($pattern, $valueFragment, $matches)) {
             if (null === $tokenTypeConstant) {
                 throw InvalidArgumentExceptionFactory::createForInvalidExpressionLanguageToken($valueFragment);
             }
             $match = $matches[1];
             if (self::REFERENCE_LEXER === $tokenTypeConstant) {
                 return $referenceLexer->lex($match);
             }
             return [new Token($match, new TokenType($tokenTypeConstant))];
         }
     }
     throw ExpressionLanguageExceptionFactory::createForCouldNotLexValue($valueFragment);
 }
 /**
  * {@inheritdoc}
  *
  * @throws LexException
  */
 public function lex(string $value) : array
 {
     $escapedValue = preg_replace('/(\\p{L})@/', '$1\\@', $value);
     return $this->lexer->lex($escapedValue);
 }