diff --git a/lib/hafriedlander/Peg/Parser/FalseOnlyPackrat.php b/lib/hafriedlander/Peg/Parser/FalseOnlyPackrat.php index ec2a8b5..e5c57e3 100644 --- a/lib/hafriedlander/Peg/Parser/FalseOnlyPackrat.php +++ b/lib/hafriedlander/Peg/Parser/FalseOnlyPackrat.php @@ -8,28 +8,34 @@ * @author Hamish Friedlander */ class FalseOnlyPackrat extends Basic { - function __construct( $string ) { - parent::__construct( $string ) ; - $this->packstatebase = \str_repeat( '.', \strlen( $string ) ) ; - $this->packstate = [] ; - } + public function __construct($string) { - function packhas( $key, $pos ) { - return isset( $this->packstate[$key] ) && $this->packstate[$key][$pos] == 'F' ; - } + parent::__construct($string); + $this->packstate = []; - function packread( $key, $pos ) { - return \false ; - } + } + + public function packhas($key, $pos) { + return ($this->packstate[$key][$pos] ?? false) == 'F'; + } - function packwrite( $key, $pos, $res ) { - if ( !isset( $this->packstate[$key] ) ) $this->packstate[$key] = $this->packstatebase ; + public function packread($key, $pos) { + return \false; + } - if ( $res === \false ) { - $this->packstate[$key][$pos] = 'F' ; - } + public function packwrite($key, $pos, $result) { + + if (!isset($this->packstate[$key])) { + $this->packstate[$key] = []; + } + + if ($result === \false) { + $this->packstate[$key][$pos] = 'F'; + } + + return $result; - return $res ; } + }