Ejemplo n.º 1
0
echo 'Building temporary preproprocessed grammar file.', "\n";
$grammarCode = file_get_contents($grammarFile);
$grammarCode = resolveConstants($grammarCode);
$grammarCode = resolveNodes($grammarCode);
$grammarCode = resolveMacros($grammarCode);
$grammarCode = resolveArrays($grammarCode);
file_put_contents($tmpGrammarFile, $grammarCode);
echo "Building parser.\n";
$output = trim(shell_exec("{$kmyacc} -l -m {$skeletonFile} -p PHPParser_Parser {$tmpGrammarFile} 2>&1"));
echo "Output: \"{$output}\"\n";
moveFileWithDirCheck($tmpResultFile, $parserResultFile);
if ($optionDebug) {
    echo "Building debug parser.\n";
    $output = trim(shell_exec("{$kmyacc} -t -v -l -m {$skeletonFile} -p PHPParser_Parser {$tmpGrammarFile} 2>&1"));
    echo "Output: \"{$output}\"\n";
    moveFileWithDirCheck($tmpResultFile, $debugParserResultFile);
}
if (!$optionKeepTmpGrammar) {
    unlink($tmpGrammarFile);
}
///////////////////////////////
/// Preprocessing functions ///
///////////////////////////////
function resolveConstants($code)
{
    return preg_replace('~[A-Z][a-zA-Z_]++::~', 'PHPParser_Node_$0', $code);
}
function resolveNodes($code)
{
    return preg_replace_callback('~(?<name>[A-Z][a-zA-Z_]++)\\s*' . PARAMS . '~', function ($matches) {
        // recurse
Ejemplo n.º 2
0
const ARGS = '\\((?<args>[^()]*+(?:\\((?&args)\\)[^()]*+)*+)\\)';
///////////////////
/// Main script ///
///////////////////
echo 'Building temporary preproprocessed grammar file.', "\n";
$grammarCode = file_get_contents($grammarFile);
$grammarCode = resolveConstants($grammarCode);
$grammarCode = resolveNodes($grammarCode);
$grammarCode = resolveMacros($grammarCode);
$grammarCode = resolveArrays($grammarCode);
file_put_contents($tmpGrammarFile, $grammarCode);
$additionalArgs = $optionDebug ? '-t -v' : '';
echo "Building parser.\n";
$output = trim(shell_exec("{$kmyacc} {$additionalArgs} -l -m {$skeletonFile} {$tmpGrammarFile} 2>&1"));
echo "Output: \"{$output}\"\n";
moveFileWithDirCheck($tmpResultFile, $parserResultFile);
if (!$optionKeepTmpGrammar) {
    unlink($tmpGrammarFile);
}
///////////////////////////////
/// Preprocessing functions ///
///////////////////////////////
function resolveConstants($code)
{
    return preg_replace('~[A-Z][a-zA-Z_\\\\]++::~', 'Node\\\\$0', $code);
}
function resolveNodes($code)
{
    return preg_replace_callback('~(?<name>[A-Z][a-zA-Z_\\\\]++)\\s*' . PARAMS . '~', function ($matches) {
        // recurse
        $matches['params'] = resolveNodes($matches['params']);