diff --git a/src/Atn/ATNConfigSet.php b/src/Atn/ATNConfigSet.php index 319cd6b..5b196bd 100644 --- a/src/Atn/ATNConfigSet.php +++ b/src/Atn/ATNConfigSet.php @@ -82,32 +82,7 @@ public function __construct(bool $fullCtx = true) * not including context. Wiped out when we go readonly as this se * becomes a DFA state. */ - $this->configLookup = new Set(new class implements Equivalence { - public function equivalent(Hashable $left, Hashable $right): bool - { - if ($left === $right) { - return true; - } - - if (!$left instanceof ATNConfig || !$right instanceof ATNConfig) { - return false; - } - - return $left->alt === $right->alt - && $left->semanticContext->equals($right->semanticContext) - && Equality::equals($left->state, $right->state); - } - - public function hash(Hashable $value): int - { - return $value->hashCode(); - } - - public function equals(object $other): bool - { - return $other instanceof self; - } - }); + $this->configLookup = new Set(new ATNEquivalence()); $this->fullCtx = $fullCtx; } diff --git a/src/Atn/ATNEquivalence.php b/src/Atn/ATNEquivalence.php new file mode 100644 index 0000000..1c5c117 --- /dev/null +++ b/src/Atn/ATNEquivalence.php @@ -0,0 +1,45 @@ +alt === $right->alt + && $left->semanticContext->equals($right->semanticContext) + && Equality::equals($left->state, $right->state); + } + + public function hash(Hashable $value): int + { + return $value->hashCode(); + } + + public function equals(object $other): bool + { + return $other instanceof self; + } + +}