Skip to content

Commit

Permalink
Bump php-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasReschke committed Jul 3, 2015
1 parent e7d5a8c commit 77dc392
Show file tree
Hide file tree
Showing 129 changed files with 3,827 additions and 3,047 deletions.
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 89 additions & 2 deletions nikic/php-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,102 @@
Version 1.1.1-dev
Version 1.3.1-dev
-----------------

Nothing yet.

Version 1.3.0 (2015-05-02)
--------------------------

### Added

* Errors can now store the attributes of the node/token where the error occurred. Previously only the start line was
stored.
* If file positions are enabled in the lexer, errors can now provide column information if it is available. See
[documentation](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Error.markdown#column-information).
* The parser now provides an experimental error recovery mode, which can be enabled by disabling the `throwOnError`
parser option. In this mode the parser will try to construct a partial AST even if the code is not valid PHP. See
[documentation](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Error.markdown#error-recovery).
* Added support for PHP 7 `yield from` expression. It is represented by `Expr\YieldFrom`.
* Added support for PHP 7 anonymous classes. These are represented by ordinary `Stmt\Class_` nodes with the name set to
`null`. Furthermore this implies that `Expr\New_` can now contain a `Stmt\Class_` in its `class` subnode.

### Fixed

* Fixed registration of PHP 7 aliases, for the case where the old name was used before the new name.
* Fixed handling of precedence when pretty-printing `print` expressions.
* Floating point numbers are now pretty-printed with a higher precision.
* Checks for special class names like `self` are now case-insensitive.

Version 1.2.2 (2015-04-03)
--------------------------

* The `NameResolver` now resolves parameter type hints when entering the function/method/closure node. As such other
visitors running after it will be able to make use of the resolved names at that point already.
* The autoloader no longer sets the `unserialize_callback_func` ini option on registration - this is not necessary and
may cause issues when running PhpUnit tests with process isolation.

Version 1.2.1 (2015-03-24)
--------------------------

* Fixed registration of the aliases introduced in 1.2.0. Previously the old class names could not be used in
`instanceof` checks under some circumstances.

Version 1.2.0 (2015-03-22)
--------------------------

### Changed

* To ensure compatibility with PHP 7, the following node classes have been renamed:

OLD => NEW
PhpParser\Node\Expr\Cast\Bool => PhpParser\Node\Expr\Cast\Bool_
PhpParser\Node\Expr\Cast\Int => PhpParser\Node\Expr\Cast\Int_
PhpParser\Node\Expr\Cast\Object => PhpParser\Node\Expr\Cast\Object_
PhpParser\Node\Expr\Cast\String => PhpParser\Node\Expr\Cast\String_
PhpParser\Node\Scalar\String => PhpParser\Node\Scalar\String_

**The previous class names are still supported as aliases.** However it is strongly encouraged to use the new names
in order to make your code compatible with PHP 7.

* Subnodes are now stored using real properties instead of an array. This improves performance and memory usage of the
initial parse and subsequent node tree operations. The `NodeAbstract` class still supports the old way of specifying
subnodes, however this is *deprecated*. In any case properties that are assigned to a node after creation will no
longer be considered as subnodes.

* Methods and property declarations will no longer set the `Stmt\Class_::MODIFIER_PUBLIC` flag if no visibility is
explicitly given. However the `isPublic()` method will continue to return true. This allows you to distinguish whether
a method/property is explicitly or implicitly public and control the pretty printer output more precisely.

* The `Stmt\Class_`, `Stmt\Interface_` and `Stmt\Trait_` nodes now inherit from `Stmt\ClassLike`, which provides a
`getMethods()` method. Previously this method was only available on `Stmt\Class_`.

* Support including the `bootstrap.php` file multiple times.

* Make documentation and tests part of the release tarball again.

* Improve support for HHVM and PHP 7.

### Added

* Added support for PHP 7 return type declarations. This adds an additional `returnType` subnode to `Stmt\Function_`,
`Stmt\ClassMethod` and `Expr\Closure`.

* Added support for the PHP 7 null coalesce operator `??`. The operator is represented by `Expr\BinaryOp\Coalesce`.

* Added support for the PHP 7 spaceship operator `<=>`. The operator is represented by `Expr\BinaryOp\Spaceship`.

* Added use builder.

* Added global namespace support to the namespace builder.

* Added a constructor flag to `NodeTraverser`, which disables cloning of nodes.

Version 1.1.0 (2015-01-18)
--------------------------

* Methods that do not specify an explicit visibility (e.g. `function method()`) will now have the `MODIFIER_PUBLIC`
flag set. This also means that their `isPublic()` method will return true.

* Declaring a property as abstract or static is now an error.
* Declaring a property as abstract or final is now an error.

* The `Lexer` and `Lexer\Emulative` classes now accept an `$options` array in their constructors. Currently only the
`usedAttributes` option is supported, which determines which attributes will be added to AST nodes. In particular
Expand Down
15 changes: 13 additions & 2 deletions nikic/php-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PHP Parser
This is a PHP 5.2 to PHP 5.6 parser written in PHP. Its purpose is to simplify static code analysis and
manipulation.

[**Documentation for version 1.0.x**][doc_master] (stable; for running on PHP >= 5.3).
[**Documentation for version 1.x**][doc_master] (stable; for running on PHP >= 5.3).

[Documentation for version 0.9.x][doc_0_9] (unsupported; for running on PHP 5.2).

Expand Down Expand Up @@ -70,7 +70,18 @@ programming errors or security issues).
Additionally, you can convert a syntax tree back to PHP code. This allows you to do code preprocessing
(like automatedly porting code to older PHP versions).

So, that's it, in a nutshell. You can find everything else in the [docs][doc_master].
Documentation
-------------

1. [Introduction](doc/0_Introduction.markdown)
2. [Installation](doc/1_Installation.markdown)
3. [Usage of basic components](doc/2_Usage_of_basic_components.markdown)
4. [Other node tree representations](doc/3_Other_node_tree_representations.markdown)
5. [Code generation](doc/4_Code_generation.markdown)

Component documentation:

1. [Lexer](doc/component/Lexer.markdown)

[doc_0_9]: https://github.com/nikic/PHP-Parser/tree/0.9/doc
[doc_master]: https://github.com/nikic/PHP-Parser/tree/master/doc
2 changes: 1 addition & 1 deletion nikic/php-parser/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "1.3-dev"
}
}
}
7 changes: 3 additions & 4 deletions nikic/php-parser/grammar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ The `.phpy` file is a normal grammer in `kmyacc` (`yacc`) style, with some trans
applied to it:

* Nodes are created using the syntax `Name[..., ...]`. This is transformed into
`new Node\Name(..., ..., $attributes)`
* `Name::abc` is transformed to `Node\Name::abc`
`new Name(..., ..., attributes())`
* Some function-like constructs are resolved (see `rebuildParser.php` for a list)
* Associative arrays are written as `[key: value, ...]`, which is transformed to
`array('key' => value, ...)`
Expand All @@ -25,5 +24,5 @@ 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` script.

By default only the `Parser.php` is built. If you want to additionally build `Parser/Debug.php` and `y.output` run the
script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`.
By default only the `Parser.php` is built. If you want to additionally emit debug symbols and create `y.output`, run the
script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`.
11 changes: 6 additions & 5 deletions nikic/php-parser/grammar/kmyacc.php.parser
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
$meta #
#semval($) $this->semValue
#semval($,%t) $this->semValue
#semval(%n) $this->semStack[$this->stackPos-(%l-%n)]
#semval(%n,%t) $this->semStack[$this->stackPos-(%l-%n)]
#include;
#semval(%n) $this->stackPos-(%l-%n)
#semval(%n,%t) $this->stackPos-(%l-%n)

namespace PhpParser;
#include;

/* This is an automatically GENERATED file, which should not be manually edited.
* Instead edit one of the following:
Expand All @@ -20,7 +20,8 @@ class Parser extends ParserAbstract
protected $actionTableSize = #(YYLAST);
protected $gotoTableSize = #(YYGLAST);

protected $invalidToken = #(YYBADCH);
protected $invalidSymbol = #(YYBADCH);
protected $errorSymbol = #(YYINTERRTOK);
protected $defaultAction = #(YYDEFAULT);
protected $unexpectedTokenRule = #(YYUNEXPECTED);

Expand Down Expand Up @@ -86,7 +87,7 @@ class Parser extends ParserAbstract
#endif
#reduce

protected function reduceRule%n($attributes) {
protected function reduceRule%n() {
%b
}
#noact
Expand Down
44 changes: 27 additions & 17 deletions nikic/php-parser/grammar/rebuildParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@

$grammarCode = file_get_contents($grammarFile);

$grammarCode = resolveConstants($grammarCode);
$grammarCode = resolveNodes($grammarCode);
$grammarCode = resolveMacros($grammarCode);
$grammarCode = resolveArrays($grammarCode);
$grammarCode = resolveStackAccess($grammarCode);

file_put_contents($tmpGrammarFile, $grammarCode);

Expand All @@ -52,7 +52,12 @@
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile $tmpGrammarFile 2>&1"));
echo "Output: \"$output\"\n";

moveFileWithDirCheck($tmpResultFile, $parserResultFile);
$resultCode = file_get_contents($tmpResultFile);
$resultCode = removeTrailingWhitespace($resultCode);

ensureDirExists(dirname($parserResultFile));
file_put_contents($parserResultFile, $resultCode);
unlink($tmpResultFile);

if (!$optionKeepTmpGrammar) {
unlink($tmpGrammarFile);
Expand All @@ -62,10 +67,6 @@
/// 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 . '~',
Expand All @@ -83,7 +84,7 @@ function($matches) {
$paramCode .= $param . ', ';
}

return 'new Node\\' . $matches['name'] . '(' . $paramCode . '$attributes)';
return 'new ' . $matches['name'] . '(' . $paramCode . 'attributes())';
},
$code
);
Expand All @@ -102,10 +103,9 @@ function($matches) {
$matches['args']
);

if ('error' == $name) {
assertArgs(1, $args, $name);

return 'throw new Error(' . $args[0] . ')';
if ('attributes' == $name) {
assertArgs(0, $args, $name);
return '$this->startAttributeStack[#1] + $this->endAttributes';
}

if ('init' == $name) {
Expand Down Expand Up @@ -139,16 +139,16 @@ function($matches) {
if ('parseEncapsed' == $name) {
assertArgs(2, $args, $name);

return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String::parseEscapeSequences($s, ' . $args[1] . '); } }';
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, ' . $args[1] . '); } }';
}

if ('parseEncapsedDoc' == $name) {
assertArgs(1, $args, $name);

return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String::parseEscapeSequences($s, null); } } $s = preg_replace(\'~(\r\n|\n|\r)$~\', \'\', $s); if (\'\' === $s) array_pop(' . $args[0] . ');';
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, null); } } $s = preg_replace(\'~(\r\n|\n|\r)$~\', \'\', $s); if (\'\' === $s) array_pop(' . $args[0] . ');';
}

throw new Exception(sprintf('Unknown macro "%s"', $name));
return $matches[0];
},
$code
);
Expand Down Expand Up @@ -191,12 +191,22 @@ function ($matches) {
);
}

function moveFileWithDirCheck($fromPath, $toPath) {
$dir = dirname($toPath);
function resolveStackAccess($code) {
$code = preg_replace('/\$\d+/', '$this->semStack[$0]', $code);
$code = preg_replace('/#(\d+)/', '$$1', $code);
return $code;
}

function removeTrailingWhitespace($code) {
$lines = explode("\n", $code);
$lines = array_map('rtrim', $lines);
return implode("\n", $lines);
}

function ensureDirExists($dir) {
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
rename($fromPath, $toPath);
}

//////////////////////////////
Expand Down

0 comments on commit 77dc392

Please sign in to comment.