mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Test PHP 5 and PHP 7 parsers
At this point they should return the same result.
This commit is contained in:
parent
fdbddc4b8c
commit
74c57eef0e
@ -14,7 +14,7 @@ namespace PhpParser\Parser;
|
||||
* * the skeleton file grammar/kymacc.php.parser
|
||||
* * the preprocessing script grammar/rebuildParsers.php
|
||||
*/
|
||||
class Php5 extends \PhpParser\ParserAbstract
|
||||
class #(-p) extends \PhpParser\ParserAbstract
|
||||
{
|
||||
protected $tokenToSymbolMapSize = #(YYMAXLEX);
|
||||
protected $actionTableSize = #(YYLAST);
|
||||
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
$grammarToResultFile = [
|
||||
__DIR__ . '/php5.y' => __DIR__ . '/../lib/PhpParser/Parser/Php5.php',
|
||||
__DIR__ . '/php7.y' => __DIR__ . '/../lib/PhpParser/Parser/Php7.php',
|
||||
$grammarFileToName = [
|
||||
__DIR__ . '/php5.y' => 'Php5',
|
||||
__DIR__ . '/php7.y' => 'Php7',
|
||||
];
|
||||
|
||||
$skeletonFile = __DIR__ . '/kmyacc.php.parser';
|
||||
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
|
||||
$tmpResultFile = __DIR__ . '/tmp_parser.php';
|
||||
$resultDir = __DIR__ . '/../lib/PhpParser/Parser';
|
||||
|
||||
// check for kmyacc.exe binary in this directory, otherwise fall back to global name
|
||||
$kmyacc = __DIR__ . '/kmyacc.exe';
|
||||
@ -38,8 +39,8 @@ const ARGS = '\((?<args>[^()]*+(?:\((?&args)\)[^()]*+)*+)\)';
|
||||
/// Main script ///
|
||||
///////////////////
|
||||
|
||||
foreach ($grammarToResultFile as $grammarFile => $resultFile) {
|
||||
echo 'Building temporary preproprocessed grammar file.', "\n";
|
||||
foreach ($grammarFileToName as $grammarFile => $name) {
|
||||
echo "Building temporary $name grammar file.\n";
|
||||
|
||||
$grammarCode = file_get_contents($grammarFile);
|
||||
|
||||
@ -51,15 +52,15 @@ foreach ($grammarToResultFile as $grammarFile => $resultFile) {
|
||||
|
||||
$additionalArgs = $optionDebug ? '-t -v' : '';
|
||||
|
||||
echo "Building parser.\n";
|
||||
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile $tmpGrammarFile 2>&1"));
|
||||
echo "Building $name parser.\n";
|
||||
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile -p $name $tmpGrammarFile 2>&1"));
|
||||
echo "Output: \"$output\"\n";
|
||||
|
||||
$resultCode = file_get_contents($tmpResultFile);
|
||||
$resultCode = removeTrailingWhitespace($resultCode);
|
||||
|
||||
ensureDirExists(dirname($resultFile));
|
||||
file_put_contents($resultFile, $resultCode);
|
||||
ensureDirExists($resultDir);
|
||||
file_put_contents("$resultDir/$name.php", $resultCode);
|
||||
unlink($tmpResultFile);
|
||||
|
||||
if (!$optionKeepTmpGrammar) {
|
||||
|
@ -11,9 +11,9 @@ use PhpParser\Node\Stmt;
|
||||
|
||||
/* This is an automatically GENERATED file, which should not be manually edited.
|
||||
* Instead edit one of the following:
|
||||
* * the grammar file grammar/zend_language_parser.phpy
|
||||
* * the grammar files grammar/php5.y or grammar/php7.y
|
||||
* * the skeleton file grammar/kymacc.php.parser
|
||||
* * the preprocessing script grammar/rebuildParser.php
|
||||
* * the preprocessing script grammar/rebuildParsers.php
|
||||
*/
|
||||
class Php5 extends \PhpParser\ParserAbstract
|
||||
{
|
||||
|
@ -11,11 +11,11 @@ use PhpParser\Node\Stmt;
|
||||
|
||||
/* This is an automatically GENERATED file, which should not be manually edited.
|
||||
* Instead edit one of the following:
|
||||
* * the grammar file grammar/zend_language_parser.phpy
|
||||
* * the grammar files grammar/php5.y or grammar/php7.y
|
||||
* * the skeleton file grammar/kymacc.php.parser
|
||||
* * the preprocessing script grammar/rebuildParser.php
|
||||
* * the preprocessing script grammar/rebuildParsers.php
|
||||
*/
|
||||
class Php5 extends \PhpParser\ParserAbstract
|
||||
class Php7 extends \PhpParser\ParserAbstract
|
||||
{
|
||||
protected $tokenToSymbolMapSize = 392;
|
||||
protected $actionTableSize = 1313;
|
||||
|
@ -15,10 +15,21 @@ class ParserTest extends CodeTestAbstract
|
||||
$lexer = new Lexer\Emulative(array('usedAttributes' => array(
|
||||
'startLine', 'endLine', 'startFilePos', 'endFilePos'
|
||||
)));
|
||||
$parser = new Parser($lexer, array(
|
||||
$parser5 = new Parser\Php5($lexer, array(
|
||||
'throwOnError' => false,
|
||||
));
|
||||
$parser7 = new Parser\Php7($lexer, array(
|
||||
'throwOnError' => false,
|
||||
));
|
||||
|
||||
$output5 = $this->getParseOutput($parser5, $code);
|
||||
$output7 = $this->getParseOutput($parser7, $code);
|
||||
|
||||
$this->assertSame($this->canonicalize($expected), $output5, $name);
|
||||
$this->assertSame($this->canonicalize($expected), $output7, $name);
|
||||
}
|
||||
|
||||
private function getParseOutput(ParserInterface $parser, $code) {
|
||||
$stmts = $parser->parse($code);
|
||||
$errors = $parser->getErrors();
|
||||
|
||||
@ -32,7 +43,7 @@ class ParserTest extends CodeTestAbstract
|
||||
$output .= $dumper->dump($stmts);
|
||||
}
|
||||
|
||||
$this->assertSame($this->canonicalize($expected), $this->canonicalize($output), $name);
|
||||
return $this->canonicalize($output);
|
||||
}
|
||||
|
||||
public function provideTestParse() {
|
||||
|
Loading…
Reference in New Issue
Block a user