Пример #1
0
 public function testNotMatching()
 {
     $parser = new NamedSelectorParser();
     $this->assertFalse($parser->match('Article()'));
     $this->assertFalse($parser->match('Article(1)'));
 }
Пример #2
0
 /**
  *
  * @throws ParsingException
  * @return Node
  */
 protected function parseInternal()
 {
     $idSelectorParser = new IdSelectorParser();
     $allInstancesSelectorParser = new AllInstancesSelectorParser();
     $namedSelectorParser = new NamedSelectorParser();
     $propertyAccessParser = new PropertyAccessParser();
     $arrayAccessParser = new ArrayAccessParser();
     $methodCallParser = new MethodCallParser();
     if (!$this->lexer->isNextAny([self::T_ID_SELECTOR, self::T_ALL_INSTANCES_SELECTOR, self::T_NAMED_SELECTOR])) {
         throw new ParsingException("First item of the expression should be a selector");
     }
     // First item is a selector
     if ($this->lexer->isNext(self::T_ID_SELECTOR)) {
         $part = $this->match(self::T_ID_SELECTOR);
         /** @var Node $node */
         $node = $idSelectorParser->parse($part);
     } elseif ($this->lexer->isNext(self::T_ALL_INSTANCES_SELECTOR)) {
         $part = $this->match(self::T_ALL_INSTANCES_SELECTOR);
         /** @var Node $node */
         $node = $allInstancesSelectorParser->parse($part);
     } else {
         $part = $this->match(self::T_NAMED_SELECTOR);
         /** @var Node $node */
         $node = $namedSelectorParser->parse($part);
     }
     while ($this->lexer->isNextAny([self::T_PROPERTY_ACCESS, self::T_ARRAY_ACCESS, self::T_METHOD_CALL])) {
         if ($this->lexer->isNext(self::T_PROPERTY_ACCESS)) {
             $part = $this->match(self::T_PROPERTY_ACCESS);
             /** @var PropertyAccess $propertyAccess */
             $propertyAccess = $propertyAccessParser->parse($part);
             // Wraps around the current node
             $propertyAccess->setSubNode($node);
             $node = $propertyAccess;
         } elseif ($this->lexer->isNext(self::T_ARRAY_ACCESS)) {
             $part = $this->match(self::T_ARRAY_ACCESS);
             /** @var ArrayAccess $arrayAccess */
             $arrayAccess = $arrayAccessParser->parse($part);
             // Wraps around the current node
             $arrayAccess->setSubNode($node);
             $node = $arrayAccess;
         } elseif ($this->lexer->isNext(self::T_METHOD_CALL)) {
             $part = $this->match(self::T_METHOD_CALL);
             /** @var MethodCall $methodCall */
             $methodCall = $methodCallParser->parse($part);
             // Wraps around the current node
             $methodCall->setSubNode($node);
             $node = $methodCall;
         }
     }
     return $node;
 }