mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Fork separate PHP 7 parser
Also add ParserInterface
This commit is contained in:
parent
dca46febc9
commit
ca3b44bf60
1044
grammar/php7.y
Normal file
1044
grammar/php7.y
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
$grammarFile = __DIR__ . '/php5.y';
|
||||
$skeletonFile = __DIR__ . '/kmyacc.php.parser';
|
||||
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
|
||||
$tmpResultFile = __DIR__ . '/tmp_parser.php';
|
||||
$parserResultFile = __DIR__ . '/../lib/PhpParser/Parser/Php5.php';
|
||||
$grammarToResultFile = [
|
||||
__DIR__ . '/php5.y' => __DIR__ . '/../lib/PhpParser/Parser/Php5.php',
|
||||
__DIR__ . '/php7.y' => __DIR__ . '/../lib/PhpParser/Parser/Php7.php',
|
||||
];
|
||||
|
||||
$skeletonFile = __DIR__ . '/kmyacc.php.parser';
|
||||
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
|
||||
$tmpResultFile = __DIR__ . '/tmp_parser.php';
|
||||
|
||||
// check for kmyacc.exe binary in this directory, otherwise fall back to global name
|
||||
$kmyacc = __DIR__ . '/kmyacc.exe';
|
||||
@ -35,31 +38,33 @@ const ARGS = '\((?<args>[^()]*+(?:\((?&args)\)[^()]*+)*+)\)';
|
||||
/// Main script ///
|
||||
///////////////////
|
||||
|
||||
echo 'Building temporary preproprocessed grammar file.', "\n";
|
||||
foreach ($grammarToResultFile as $grammarFile => $resultFile) {
|
||||
echo 'Building temporary preproprocessed grammar file.', "\n";
|
||||
|
||||
$grammarCode = file_get_contents($grammarFile);
|
||||
$grammarCode = file_get_contents($grammarFile);
|
||||
|
||||
$grammarCode = resolveNodes($grammarCode);
|
||||
$grammarCode = resolveMacros($grammarCode);
|
||||
$grammarCode = resolveStackAccess($grammarCode);
|
||||
$grammarCode = resolveNodes($grammarCode);
|
||||
$grammarCode = resolveMacros($grammarCode);
|
||||
$grammarCode = resolveStackAccess($grammarCode);
|
||||
|
||||
file_put_contents($tmpGrammarFile, $grammarCode);
|
||||
file_put_contents($tmpGrammarFile, $grammarCode);
|
||||
|
||||
$additionalArgs = $optionDebug ? '-t -v' : '';
|
||||
$additionalArgs = $optionDebug ? '-t -v' : '';
|
||||
|
||||
echo "Building parser.\n";
|
||||
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile $tmpGrammarFile 2>&1"));
|
||||
echo "Output: \"$output\"\n";
|
||||
echo "Building parser.\n";
|
||||
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile $tmpGrammarFile 2>&1"));
|
||||
echo "Output: \"$output\"\n";
|
||||
|
||||
$resultCode = file_get_contents($tmpResultFile);
|
||||
$resultCode = removeTrailingWhitespace($resultCode);
|
||||
$resultCode = file_get_contents($tmpResultFile);
|
||||
$resultCode = removeTrailingWhitespace($resultCode);
|
||||
|
||||
ensureDirExists(dirname($parserResultFile));
|
||||
file_put_contents($parserResultFile, $resultCode);
|
||||
unlink($tmpResultFile);
|
||||
ensureDirExists(dirname($resultFile));
|
||||
file_put_contents($resultFile, $resultCode);
|
||||
unlink($tmpResultFile);
|
||||
|
||||
if (!$optionKeepTmpGrammar) {
|
||||
unlink($tmpGrammarFile);
|
||||
if (!$optionKeepTmpGrammar) {
|
||||
unlink($tmpGrammarFile);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////
|
3218
lib/PhpParser/Parser/Php7.php
Normal file
3218
lib/PhpParser/Parser/Php7.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ namespace PhpParser;
|
||||
* This parser is based on a skeleton written by Moriyoshi Koizumi, which in
|
||||
* turn is based on work by Masato Bito.
|
||||
*/
|
||||
abstract class ParserAbstract
|
||||
abstract class ParserAbstract implements ParserInterface
|
||||
{
|
||||
const SYMBOL_NONE = -1;
|
||||
|
||||
|
24
lib/PhpParser/ParserInterface.php
Normal file
24
lib/PhpParser/ParserInterface.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser;
|
||||
|
||||
interface ParserInterface {
|
||||
/**
|
||||
* Parses PHP code into a node tree.
|
||||
*
|
||||
* @param string $code The source code to parse
|
||||
*
|
||||
* @return Node[]|null Array of statements (or null if the 'throwOnError' option is disabled and the parser was
|
||||
* unable to recover from an error).
|
||||
*/
|
||||
public function parse($code);
|
||||
|
||||
/**
|
||||
* Get array of errors that occurred during the last parse.
|
||||
*
|
||||
* This method may only return multiple errors if the 'throwOnError' option is disabled.
|
||||
*
|
||||
* @return Error[]
|
||||
*/
|
||||
public function getErrors();
|
||||
}
|
Loading…
Reference in New Issue
Block a user