SetBased /
antlr-php-runtime
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Antlr\Antlr4\Runtime\Atn; |
||
| 6 | |||
| 7 | use Antlr\Antlr4\Runtime\Atn\States\ATNState; |
||
| 8 | use Antlr\Antlr4\Runtime\Atn\States\DecisionState; |
||
| 9 | use Antlr\Antlr4\Runtime\Comparison\Equality; |
||
| 10 | use Antlr\Antlr4\Runtime\Comparison\Hasher; |
||
| 11 | use Antlr\Antlr4\Runtime\PredictionContexts\PredictionContext; |
||
| 12 | |||
| 13 | final class LexerATNConfig extends ATNConfig |
||
| 14 | { |
||
| 15 | /** @var LexerActionExecutor|null */ |
||
| 16 | private $lexerActionExecutor; |
||
| 17 | |||
| 18 | /** @var bool */ |
||
| 19 | private $passedThroughNonGreedyDecision; |
||
| 20 | |||
| 21 | 4 | public function __construct( |
|
| 22 | ?self $oldConfig, |
||
| 23 | ?ATNState $state, |
||
| 24 | ?PredictionContext $context = null, |
||
| 25 | ?LexerActionExecutor $executor = null, |
||
| 26 | ?int $alt = null |
||
| 27 | ) { |
||
| 28 | 4 | parent::__construct($oldConfig, $state, $context, null, $alt); |
|
| 29 | |||
| 30 | 4 | $this->lexerActionExecutor = $executor ?? ($oldConfig->lexerActionExecutor ?? null); |
|
| 31 | 4 | $this->passedThroughNonGreedyDecision = $oldConfig ? |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 32 | 4 | self::checkNonGreedyDecision($oldConfig, $this->state) : |
|
| 33 | 1 | false; |
|
| 34 | 4 | } |
|
| 35 | |||
| 36 | 4 | public function getLexerActionExecutor() : ?LexerActionExecutor |
|
| 37 | { |
||
| 38 | 4 | return $this->lexerActionExecutor; |
|
| 39 | } |
||
| 40 | |||
| 41 | 2 | public function isPassedThroughNonGreedyDecision() : bool |
|
| 42 | { |
||
| 43 | 2 | return $this->passedThroughNonGreedyDecision; |
|
| 44 | } |
||
| 45 | |||
| 46 | 4 | public function hashCode() : int |
|
| 47 | { |
||
| 48 | 4 | return Hasher::hash( |
|
| 49 | 4 | $this->state->stateNumber, |
|
| 50 | 4 | $this->alt, |
|
| 51 | 4 | $this->context, |
|
| 52 | 4 | $this->semanticContext, |
|
| 53 | 4 | $this->passedThroughNonGreedyDecision, |
|
| 54 | 4 | $this->lexerActionExecutor |
|
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | 4 | public function equals(object $other) : bool |
|
| 59 | { |
||
| 60 | 4 | if ($this === $other) { |
|
| 61 | 4 | return true; |
|
| 62 | } |
||
| 63 | |||
| 64 | 1 | if (!$other instanceof self) { |
|
| 65 | return false; |
||
| 66 | } |
||
| 67 | |||
| 68 | 1 | if (!parent::equals($other)) { |
|
| 69 | return false; |
||
| 70 | } |
||
| 71 | |||
| 72 | 1 | if ($this->passedThroughNonGreedyDecision !== $other->passedThroughNonGreedyDecision) { |
|
| 73 | return false; |
||
| 74 | } |
||
| 75 | |||
| 76 | 1 | return Equality::equals($this->lexerActionExecutor, $other->lexerActionExecutor); |
|
| 77 | } |
||
| 78 | |||
| 79 | 4 | private static function checkNonGreedyDecision(LexerATNConfig $source, ATNState $target) : bool |
|
| 80 | { |
||
| 81 | 4 | return $source->passedThroughNonGreedyDecision || ($target instanceof DecisionState && $target->nonGreedy); |
|
| 82 | } |
||
| 83 | } |
||
| 84 |