mirror of
https://github.com/danog/PHP-Parser.git
synced 2025-01-22 13:51:12 +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
|
<?php
|
||||||
|
|
||||||
$grammarFile = __DIR__ . '/php5.y';
|
$grammarToResultFile = [
|
||||||
|
__DIR__ . '/php5.y' => __DIR__ . '/../lib/PhpParser/Parser/Php5.php',
|
||||||
|
__DIR__ . '/php7.y' => __DIR__ . '/../lib/PhpParser/Parser/Php7.php',
|
||||||
|
];
|
||||||
|
|
||||||
$skeletonFile = __DIR__ . '/kmyacc.php.parser';
|
$skeletonFile = __DIR__ . '/kmyacc.php.parser';
|
||||||
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
|
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
|
||||||
$tmpResultFile = __DIR__ . '/tmp_parser.php';
|
$tmpResultFile = __DIR__ . '/tmp_parser.php';
|
||||||
$parserResultFile = __DIR__ . '/../lib/PhpParser/Parser/Php5.php';
|
|
||||||
|
|
||||||
// check for kmyacc.exe binary in this directory, otherwise fall back to global name
|
// check for kmyacc.exe binary in this directory, otherwise fall back to global name
|
||||||
$kmyacc = __DIR__ . '/kmyacc.exe';
|
$kmyacc = __DIR__ . '/kmyacc.exe';
|
||||||
@ -35,6 +38,7 @@ const ARGS = '\((?<args>[^()]*+(?:\((?&args)\)[^()]*+)*+)\)';
|
|||||||
/// Main script ///
|
/// Main script ///
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
|
foreach ($grammarToResultFile as $grammarFile => $resultFile) {
|
||||||
echo 'Building temporary preproprocessed grammar file.', "\n";
|
echo 'Building temporary preproprocessed grammar file.', "\n";
|
||||||
|
|
||||||
$grammarCode = file_get_contents($grammarFile);
|
$grammarCode = file_get_contents($grammarFile);
|
||||||
@ -54,13 +58,14 @@ echo "Output: \"$output\"\n";
|
|||||||
$resultCode = file_get_contents($tmpResultFile);
|
$resultCode = file_get_contents($tmpResultFile);
|
||||||
$resultCode = removeTrailingWhitespace($resultCode);
|
$resultCode = removeTrailingWhitespace($resultCode);
|
||||||
|
|
||||||
ensureDirExists(dirname($parserResultFile));
|
ensureDirExists(dirname($resultFile));
|
||||||
file_put_contents($parserResultFile, $resultCode);
|
file_put_contents($resultFile, $resultCode);
|
||||||
unlink($tmpResultFile);
|
unlink($tmpResultFile);
|
||||||
|
|
||||||
if (!$optionKeepTmpGrammar) {
|
if (!$optionKeepTmpGrammar) {
|
||||||
unlink($tmpGrammarFile);
|
unlink($tmpGrammarFile);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
/// Preprocessing functions ///
|
/// Preprocessing functions ///
|
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
|
* This parser is based on a skeleton written by Moriyoshi Koizumi, which in
|
||||||
* turn is based on work by Masato Bito.
|
* turn is based on work by Masato Bito.
|
||||||
*/
|
*/
|
||||||
abstract class ParserAbstract
|
abstract class ParserAbstract implements ParserInterface
|
||||||
{
|
{
|
||||||
const SYMBOL_NONE = -1;
|
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…
x
Reference in New Issue
Block a user