mirror of
https://github.com/danog/PHP-Parser.git
synced 2025-01-22 22:01:18 +01:00
Accept KMYACC env var in rebuildParsers.php
This commit is contained in:
parent
54c37f6b3b
commit
3226eb4086
@ -13,13 +13,16 @@ $tmpResultFile = __DIR__ . '/tmp_parser.php';
|
|||||||
$resultDir = __DIR__ . '/../lib/PhpParser/Parser';
|
$resultDir = __DIR__ . '/../lib/PhpParser/Parser';
|
||||||
$tokensResultsFile = $resultDir . '/Tokens.php';
|
$tokensResultsFile = $resultDir . '/Tokens.php';
|
||||||
|
|
||||||
// check for kmyacc binary in this directory, otherwise fall back to global name
|
$kmyacc = getenv('KMYACC');
|
||||||
if (file_exists(__DIR__ . '/kmyacc.exe')) {
|
if (!$kmyacc) {
|
||||||
|
// Check for kmyacc binary in this directory, otherwise fall back to global name
|
||||||
|
if (file_exists(__DIR__ . '/kmyacc.exe')) {
|
||||||
$kmyacc = __DIR__ . '/kmyacc.exe';
|
$kmyacc = __DIR__ . '/kmyacc.exe';
|
||||||
} else if (file_exists(__DIR__ . '/kmyacc')) {
|
} else if (file_exists(__DIR__ . '/kmyacc')) {
|
||||||
$kmyacc = __DIR__ . '/kmyacc';
|
$kmyacc = __DIR__ . '/kmyacc';
|
||||||
} else {
|
} else {
|
||||||
$kmyacc = 'kmyacc';
|
$kmyacc = 'kmyacc';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array_flip($argv);
|
$options = array_flip($argv);
|
||||||
@ -62,8 +65,7 @@ foreach ($grammarFileToName as $grammarFile => $name) {
|
|||||||
$additionalArgs = $optionDebug ? '-t -v' : '';
|
$additionalArgs = $optionDebug ? '-t -v' : '';
|
||||||
|
|
||||||
echo "Building $name parser.\n";
|
echo "Building $name parser.\n";
|
||||||
$output = trim(shell_exec("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile 2>&1"));
|
$output = execCmd("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile");
|
||||||
echo "Output: \"$output\"\n";
|
|
||||||
|
|
||||||
$resultCode = file_get_contents($tmpResultFile);
|
$resultCode = file_get_contents($tmpResultFile);
|
||||||
$resultCode = removeTrailingWhitespace($resultCode);
|
$resultCode = removeTrailingWhitespace($resultCode);
|
||||||
@ -73,8 +75,7 @@ foreach ($grammarFileToName as $grammarFile => $name) {
|
|||||||
unlink($tmpResultFile);
|
unlink($tmpResultFile);
|
||||||
|
|
||||||
echo "Building token definition.\n";
|
echo "Building token definition.\n";
|
||||||
$output = trim(shell_exec("$kmyacc -l -m $tokensTemplate $tmpGrammarFile 2>&1"));
|
$output = execCmd("$kmyacc -m $tokensTemplate $tmpGrammarFile");
|
||||||
assert($output === '');
|
|
||||||
rename($tmpResultFile, $tokensResultsFile);
|
rename($tmpResultFile, $tokensResultsFile);
|
||||||
|
|
||||||
if (!$optionKeepTmpGrammar) {
|
if (!$optionKeepTmpGrammar) {
|
||||||
@ -234,6 +235,15 @@ function ensureDirExists($dir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function execCmd($cmd) {
|
||||||
|
$output = trim(shell_exec("$cmd 2>&1"));
|
||||||
|
if ($output !== "") {
|
||||||
|
echo "> " . $cmd . "\n";
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
/// Regex helper functions ///
|
/// Regex helper functions ///
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user