php-peg
php-peg copied to clipboard
PHP Segmentation fault executeing cli.php
Hi, I got a php5-Segmentation fault when I run cli.php with the BooleanParser.peg.inc_new (https://gist.github.com/4623645), with BooleanParser.peg.inc (https://gist.github.com/4623616) everything works. Any Idea what this may be? The difference is really small and I'm unsure, if this is due to a wrong Syntax or a PHP-Error. Any help apreciated...
I belive that the problem is related to the regex expression used to create the parser. I found a workaround by using the substr functions. In the following answer from stackoverflow there are some hints that might help: http://stackoverflow.com/a/7627962/4503525
I've come up with the following code (it's not pretty but it is working):
$syntax = file_get_contents('syntax.peg');
$parser = substr($syntax, strpos($syntax, '/*!*'));
$parser = substr($parser, 0, strpos($parser, '*/'));
$lenMatch = strlen($parser)+2;
$parserName = substr($parser, 5, strpos($parser, "\n"));
$parser = substr($parser, strpos($parser, "\n")+1);
$res = hafriedlander\Peg\Compiler::create_parser(array(
1=> '', // Here should be the indentation, make sure you do not have any indentation before /*!*
2=> $parserName,
3=> $parser,
));
$start = substr($syntax, 0, strpos($syntax, '/*!*'));
$end = substr($syntax, strlen($start)+$lenMatch);
$res = $start.$res.$end;
file_put_contents($parserName.".php", $res);
@MiguelDomingues thank you very much! worked for me.