mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Use moriyoshi's fork of kmyacc, which fixes most of the issues of kmyacc with PHP
This commit is contained in:
parent
e0fe21287d
commit
297c9ac290
@ -5,10 +5,10 @@ What do all those files mean?
|
||||
* `zend_language_parser.phpy`: PHP grammer written in a pseudo language
|
||||
* `analyzer.php`: Analyzes the `.phpy`-grammer and outputs some info about it
|
||||
* `rebuildParser.php`: Preprocesses the `.phpy`-grammar and builds the parser using `kmyacc`
|
||||
* `php.kmyacc`: A `kmyacc` parser prototype file for PHP
|
||||
* `kmyacc.php.parser`: A `kmyacc` parser prototype file for PHP
|
||||
|
||||
.phpy pseudo language
|
||||
=========================
|
||||
=====================
|
||||
|
||||
The `.phpy` file is a normal grammer in `kmyacc` (`yacc`) style, with some transformations
|
||||
applied to it:
|
||||
@ -17,3 +17,9 @@ applied to it:
|
||||
`new PHPParser_Node_Name(array('subNode1' => ..., 'subNode2' => ...), $line, $docComment)`
|
||||
* `Name::abc` is transformed to `PHPParser_Node_Name::abc`
|
||||
* Some function-like constructs are resolved (see `rebuildParser.php` for a list)
|
||||
|
||||
Building the parser
|
||||
===================
|
||||
|
||||
In order to rebuild the parser, you need [moriyoshi's fork of kmyacc](https://github.com/moriyoshi/kmyacc-forked).
|
||||
After you compiled/installed it, run the `rebuildParser.php` file.
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
const GRAMMAR_FILE = './zend_language_parser.phpy';
|
||||
const TMP_FILE = './tmp_parser.phpy';
|
||||
const RESULT_FILE = './tmp_parser.php';
|
||||
|
||||
///////////////////////////////
|
||||
/// Utility regex constants ///
|
||||
@ -30,54 +32,22 @@ $grammarCode = file_get_contents(GRAMMAR_FILE);
|
||||
$grammarCode = preg_replace('~[A-Z][a-zA-Z_]++::~', 'PHPParser_Node_$0', $grammarCode);
|
||||
$grammarCode = resolveNodes($grammarCode);
|
||||
$grammarCode = resolveMacros($grammarCode);
|
||||
$grammarCode = preg_replace('~\$([a-zA-Z_]++)~', '#$1', $grammarCode);
|
||||
|
||||
$tmpGrammarFile = tempnam('.', 'tmpGrammarFile');
|
||||
file_put_contents($tmpGrammarFile, $grammarCode);
|
||||
file_put_contents(TMP_FILE, $grammarCode);
|
||||
|
||||
echo 'Building parser. Output: "',
|
||||
trim(`kmyacc -l -L c -m php.kmyacc -p PHPParser_Parser $tmpGrammarFile 2>&1`),
|
||||
trim(shell_exec('kmyacc -l -m kmyacc.php.parser -p PHPParser_Parser ' . TMP_FILE . ' 2>&1')),
|
||||
'"', "\n";
|
||||
|
||||
$code = file_get_contents('y.tab.c');
|
||||
$code = str_replace(
|
||||
array(
|
||||
'"$EOF"',
|
||||
'#',
|
||||
),
|
||||
array(
|
||||
'\'$EOF\'',
|
||||
'$',
|
||||
),
|
||||
$code
|
||||
);
|
||||
|
||||
file_put_contents(dirname(__DIR__) . '/lib/PHPParser/Parser.php', $code);
|
||||
unlink(__DIR__ . '/y.tab.c');
|
||||
rename(RESULT_FILE, '../lib/PHPParser/Parser.php');
|
||||
|
||||
echo 'Building debug parser. Output: "',
|
||||
trim(`kmyacc -l -t -L c -m php.kmyacc -p PHPParser_ParserDebug $tmpGrammarFile 2>&1`),
|
||||
trim(shell_exec('kmyacc -t -l -m kmyacc.php.parser -p PHPParser_ParserDebug ' . TMP_FILE . ' 2>&1')),
|
||||
'"', "\n";
|
||||
|
||||
$code = file_get_contents('y.tab.c');
|
||||
$code = str_replace(
|
||||
array(
|
||||
'"$EOF"',
|
||||
'"$start : start"',
|
||||
'#',
|
||||
),
|
||||
array(
|
||||
'\'$EOF\'',
|
||||
'\'$start : start\'',
|
||||
'$',
|
||||
),
|
||||
$code
|
||||
);
|
||||
rename(RESULT_FILE, '../lib/PHPParser/ParserDebug.php');
|
||||
|
||||
file_put_contents(dirname(__DIR__) . '/lib/PHPParser/ParserDebug.php', $code);
|
||||
unlink(__DIR__ . '/y.tab.c');
|
||||
|
||||
unlink($tmpGrammarFile);
|
||||
unlink(TMP_FILE);
|
||||
|
||||
echo 'The following temporary preproprocessed grammar file was used:', "\n", $grammarCode;
|
||||
|
||||
|
@ -147,7 +147,7 @@ class PHPParser_Parser
|
||||
// }}}
|
||||
|
||||
private static $yyterminals = array(
|
||||
'$EOF',
|
||||
"EOF",
|
||||
"error",
|
||||
"T_INCLUDE",
|
||||
"T_INCLUDE_ONCE",
|
||||
|
@ -147,7 +147,7 @@ class PHPParser_ParserDebug
|
||||
// }}}
|
||||
|
||||
private static $yyterminals = array(
|
||||
'$EOF',
|
||||
"EOF",
|
||||
"error",
|
||||
"T_INCLUDE",
|
||||
"T_INCLUDE_ONCE",
|
||||
@ -296,7 +296,7 @@ class PHPParser_ParserDebug
|
||||
);
|
||||
|
||||
private static $yyproduction = array(
|
||||
'$start : start',
|
||||
"start : start",
|
||||
"start : top_statement_list",
|
||||
"top_statement_list : top_statement_list top_statement",
|
||||
"top_statement_list : /* empty */",
|
||||
|
Loading…
Reference in New Issue
Block a user