1<?php 2 3declare(strict_types=1); 4 5namespace Antlr\Antlr4\Runtime\Atn\Transitions; 6 7use Antlr\Antlr4\Runtime\Atn\SemanticContexts\Predicate; 8use Antlr\Antlr4\Runtime\Atn\States\ATNState; 9 10class PredicateTransition extends AbstractPredicateTransition 11{ 12 /** @var int */ 13 public $ruleIndex; 14 15 /** @var int */ 16 public $predIndex; 17 18 /** 19 * e.g., $i ref in pred 20 * 21 * @var bool 22 */ 23 public $isCtxDependent; 24 25 public function __construct(ATNState $target, int $ruleIndex, int $predIndex, bool $isCtxDependent) 26 { 27 parent::__construct($target); 28 29 $this->ruleIndex = $ruleIndex; 30 $this->predIndex = $predIndex; 31 $this->isCtxDependent = $isCtxDependent; 32 } 33 34 public function matches(int $symbol, int $minVocabSymbol, int $maxVocabSymbol) : bool 35 { 36 return false; 37 } 38 39 public function getPredicate() : Predicate 40 { 41 return new Predicate($this->ruleIndex, $this->predIndex, $this->isCtxDependent); 42 } 43 44 /** 45 * {@inheritdoc} 46 */ 47 public function isEpsilon() : bool 48 { 49 return true; 50 } 51 52 public function getSerializationType() : int 53 { 54 return self::PREDICATE; 55 } 56 57 public function equals(object $other) : bool 58 { 59 if ($this === $other) { 60 return true; 61 } 62 63 return $other instanceof self 64 && $this->ruleIndex === $other->ruleIndex 65 && $this->predIndex === $other->predIndex 66 && $this->isCtxDependent === $other->isCtxDependent 67 && $this->target->equals($other->target); 68 } 69 70 public function __toString() : string 71 { 72 return \sprintf('pred_%d:%d', $this->ruleIndex, $this->predIndex); 73 } 74} 75