Skip to content

Commit

Permalink
Accept KMYACC env var in rebuildParsers.php
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 19, 2019
1 parent 54c37f6 commit 3226eb4
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions grammar/rebuildParsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
$resultDir = __DIR__ . '/../lib/PhpParser/Parser';
$tokensResultsFile = $resultDir . '/Tokens.php';

// check for kmyacc binary in this directory, otherwise fall back to global name
if (file_exists(__DIR__ . '/kmyacc.exe')) {
$kmyacc = __DIR__ . '/kmyacc.exe';
} else if (file_exists(__DIR__ . '/kmyacc')) {
$kmyacc = __DIR__ . '/kmyacc';
} else {
$kmyacc = 'kmyacc';
$kmyacc = getenv('KMYACC');
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';
} else if (file_exists(__DIR__ . '/kmyacc')) {
$kmyacc = __DIR__ . '/kmyacc';
} else {
$kmyacc = 'kmyacc';
}
}

$options = array_flip($argv);
Expand Down Expand Up @@ -62,8 +65,7 @@
$additionalArgs = $optionDebug ? '-t -v' : '';

echo "Building $name parser.\n";
$output = trim(shell_exec("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile 2>&1"));
echo "Output: \"$output\"\n";
$output = execCmd("$kmyacc $additionalArgs -m $skeletonFile -p $name $tmpGrammarFile");

$resultCode = file_get_contents($tmpResultFile);
$resultCode = removeTrailingWhitespace($resultCode);
Expand All @@ -73,8 +75,7 @@
unlink($tmpResultFile);

echo "Building token definition.\n";
$output = trim(shell_exec("$kmyacc -l -m $tokensTemplate $tmpGrammarFile 2>&1"));
assert($output === '');
$output = execCmd("$kmyacc -m $tokensTemplate $tmpGrammarFile");
rename($tmpResultFile, $tokensResultsFile);

if (!$optionKeepTmpGrammar) {
Expand Down Expand Up @@ -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 ///
//////////////////////////////
Expand Down

0 comments on commit 3226eb4

Please sign in to comment.