Skip to content

Commit

Permalink
FalsePackrat parser class fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
smuuf committed Jun 2, 2020
1 parent cd67959 commit 33bd80e
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions lib/hafriedlander/Peg/Parser/FalseOnlyPackrat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
}

}

0 comments on commit 33bd80e

Please sign in to comment.