From 9a93b6e6dc49e1074909489b7b9a4616b3967487 Mon Sep 17 00:00:00 2001 From: Goutte Date: Tue, 31 May 2022 09:54:36 +0200 Subject: [PATCH] refacto: name an anonymous class to allow serialization --- src/Atn/ATNConfigSet.php | 27 +---------------------- src/Atn/ATNEquivalence.php | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 src/Atn/ATNEquivalence.php 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; + } + +}