1<?php 2 3declare(strict_types=1); 4 5namespace Antlr\Antlr4\Runtime\Atn\Transitions; 6 7use Antlr\Antlr4\Runtime\Atn\States\ATNState; 8use Antlr\Antlr4\Runtime\IntervalSet; 9use Antlr\Antlr4\Runtime\Token; 10 11/** 12 * A transition containing a set of values. 13 */ 14class SetTransition extends Transition 15{ 16 /** @var IntervalSet */ 17 public $set; 18 19 public function __construct(ATNState $target, ?IntervalSet $set = null) 20 { 21 parent::__construct($target); 22 23 if ($set !== null) { 24 $this->set = $set; 25 } else { 26 $this->set = new IntervalSet(); 27 $this->set->addOne(Token::INVALID_TYPE); 28 } 29 } 30 31 public function matches(int $symbol, int $minVocabSymbol, int $maxVocabSymbol) : bool 32 { 33 return $this->set->contains($symbol); 34 } 35 36 public function label() : ?IntervalSet 37 { 38 return $this->set; 39 } 40 41 public function getSerializationType() : int 42 { 43 return self::SET; 44 } 45 46 public function equals(object $other) : bool 47 { 48 if ($this === $other) { 49 return true; 50 } 51 52 return $other instanceof self 53 && $this->set->equals($other->set) 54 && $this->target->equals($other->target); 55 } 56 57 public function __toString() : string 58 { 59 return (string) $this->set; 60 } 61} 62