|null */ public $edges; /** @var bool */ public $isAcceptState = false; /** * If accept state, what ttype do we match or alt do we predict? * This is set to {@see ATN::INVALID_ALT_NUMBER)} when * `{@see DFAState::$predicates} !== null` or {@see DFAState::$requiresFullContext}. * * @var int */ public $prediction = 0; /** @var LexerActionExecutor|null */ public $lexerActionExecutor; /** * Indicates that this state was created during SLL prediction that * discovered a conflict between the configurations in the state. Future * {@see ParserATNSimulator::execATN()} invocations immediately jumped doing * full context prediction if this field is true. * * @var bool */ public $requiresFullContext = false; /** * During SLL parsing, this is a list of predicates associated with the * ATN configurations of the DFA state. When we have predicates, * {@see DFAState::$requiresFullContext} is `false` since full context * prediction evaluates predicates on-the-fly. If this is not null, then * {@see DFAState::$prediction} is {@see ATN::INVALID_ALT_NUMBER}. * * We only use these for non-{@see DFAState::$requiresFullContext} bu * conflicting states. That means we know from the context (it's $ or we * don't dip into outer context) that it's an ambiguity not a conflict. * * This list is computed by {@see ParserATNSimulator::predicateDFAState()}. * * @var array|null */ public $predicates; public function __construct(?ATNConfigSet $configs = null, int $stateNumber = -1) { $this->configs = $configs ?? new ATNConfigSet(); $this->stateNumber = $stateNumber; } /** * Two {@see DFAState} instances are equal if their ATN configuration sets * are the same. This method is used to see if a state already exists. * * Because the number of alternatives and number of ATN configurations are * finite, there is a finite number of DFA states that can be processed. * This is necessary to show that the algorithm terminates. * * Cannot test the DFA state numbers here because in * {@see ParserATNSimulator::addDFAState()} we need to know if any other state * exists that has this exact set of ATN configurations. The * {@see DFAState::$stateNumber} is irrelevant. */ public function equals(object $other) : bool { if ($this === $other) { return true; } if (!$other instanceof self) { return false; } // Compare set of ATN configurations in this set with other return Equality::equals($this->configs, $other->configs); } public function __toString() : string { $s = \sprintf('%d:%s', $this->stateNumber, (string) $this->configs); if ($this->isAcceptState) { $s .= '=>'; if ($this->predicates !== null) { $s .= \sprintf('[%s]', \implode(', ', $this->predicates)); } else { $s .= $this->prediction; } } return $s; } public function hashCode() : int { return Hasher::hash($this->configs); } }