Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUTOMATED: WhiteSpace Removal #50

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ Version 0.9.4-dev
-----------------

* Syntax errors now include information on expected tokens and mimic the format of PHP's own (pre 5.4) error messages.
Example:
Example:

Old: Unexpected token T_STATIC on line 1
New: Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{'
Old: Unexpected token T_STATIC on line 1
New: Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{'

* `PHPParser_PrettyPrinter_Zend` was renamed to `PHPParser_PrettyPrinter_Default` as the default pretty printer only
very loosely applies the Zend Coding Standard. The class `PHPParser_PrettyPrinter_Zend` extends
`PHPParser_PrettyPrinter_Default` to maintain backwards compatibility.
very loosely applies the Zend Coding Standard. The class `PHPParser_PrettyPrinter_Zend` extends
`PHPParser_PrettyPrinter_Default` to maintain backwards compatibility.

* The pretty printer now prints namespaces in semicolon-style if possible (i.e. if the file does not contain a global
namespace declaration).
namespace declaration).

Version 0.9.3 (22.11.2012)
--------------------------

* [BC] As `list()` in `foreach` is now supported the structure of list assignments changed:

1. There is no longer a dedicated `AssignList` node; instead a normal `Assign` node is used with a `List` as `var`.
2. Nested lists are now `List` nodes too, instead of just arrays.
1. There is no longer a dedicated `AssignList` node; instead a normal `Assign` node is used with a `List` as `var`.
2. Nested lists are now `List` nodes too, instead of just arrays.

* [BC] As arbitrary expressions are allowed in `empty()` now its subnode was renamed from `var` to `expr`.

Expand All @@ -29,77 +29,77 @@ Version 0.9.3 (22.11.2012)
* [PHP 5.5] Add support for arbitrary expressions in `empty()`.

* [PHP 5.5] Add support for constant array / string dereferencing.
Examples: `"foo"[2]`, `[1, 2, 3][2]`
Examples: `"foo"[2]`, `[1, 2, 3][2]`

* [PHP 5.5] Add support for `yield` expressions. This adds a new `Yield` expression type, with subnodes `key` and
`value`.
`value`.

* [PHP 5.5] Add support for `finally`. This adds a new `finallyStmts` subnode to the `TryCatch` node. If there is no
finally clause it will be `null`.
finally clause it will be `null`.

* [PHP 5.5] Add support for `list()` destructuring of `foreach` values.
Example: `foreach ($coords as list($x, $y)) { ... }`
Example: `foreach ($coords as list($x, $y)) { ... }`

* Improve pretty printing of expressions by printing less unnecessary parentheses. In particular concatenations are now
printed as `$a . $b . $c . $d . $e` rather than `$a . ($b . ($c . ($d . $e)))`. This is implemented by taking operator
associativity into account. New protected methods added to the pretty printer are `pPrec()`, `pInfixOp()`,
`pPrefixOp()` and `pPostfixOp()`. This also fixes an issue with extraneous parentheses in closure bodies.
printed as `$a . $b . $c . $d . $e` rather than `$a . ($b . ($c . ($d . $e)))`. This is implemented by taking operator
associativity into account. New protected methods added to the pretty printer are `pPrec()`, `pInfixOp()`,
`pPrefixOp()` and `pPostfixOp()`. This also fixes an issue with extraneous parentheses in closure bodies.

* Fix formatting of fall-through `case` statements in the Zend pretty printer.

* Fix parsing of `$foo =& new Bar`. It is now properly parsed as `AssignRef` (instead of `Assign`).

* Fix assignment of `$endAttributes`. Sometimes the attributes of the token right after the node were assigned, rather
than the attributes of the last token in the node.
than the attributes of the last token in the node.

* `rebuildParser.php` is now designed to be run from the command line rather than from the browser.

Version 0.9.2 (07.07.2012)
--------------------------

* Add `Class->getMethods()` function, which returns all methods contained in the `stmts` array of the class node. This
does not take inherited methods into account.
does not take inherited methods into account.

* Add `isPublic()`, `isProtected()`, `isPrivate()`. `isAbstract()`, `isFinal()` and `isStatic()` accessors to the
`ClassMethod`, `Property` and `Class` nodes. (`Property` and `Class` obviously only have the accessors relevant to
them.)
`ClassMethod`, `Property` and `Class` nodes. (`Property` and `Class` obviously only have the accessors relevant to
them.)

* Fix parsing of new expressions in parentheses, e.g. `return(new Foo);`.

* [BC] Due to the below changes nodes now optionally accept an `$attributes` array as the
last parameter, instead of the previously used `$line` and `$docComment` parameters.
last parameter, instead of the previously used `$line` and `$docComment` parameters.

* Add mechanism for adding attributes to nodes in the lexer.

The following attributes are now added by default:
The following attributes are now added by default:

* `startLine`: The line the node started in.
* `endLine`: The line the node ended in.
* `comments`: An array of comments. The comments are instances of `PHPParser_Comment`
(or `PHPParser_Comment_Doc` for doc comments).
* `startLine`: The line the node started in.
* `endLine`: The line the node ended in.
* `comments`: An array of comments. The comments are instances of `PHPParser_Comment`
(or `PHPParser_Comment_Doc` for doc comments).

The methods `getLine()` and `setLine()` still exist and function as before, but internally
operator on the `startLine` attribute.
The methods `getLine()` and `setLine()` still exist and function as before, but internally
operator on the `startLine` attribute.

`getDocComment()` also continues to exist. It returns the last comment in the `comments`
attribute if it is a doc comment, otherwise `null`. As `getDocComment()` now returns a
comment object (which can be modified using `->setText()`) the `setDocComment()` method was
removed. Comment objects implement a `__toString()` method, so `getDocComment()` should
continue to work properly with old code.
`getDocComment()` also continues to exist. It returns the last comment in the `comments`
attribute if it is a doc comment, otherwise `null`. As `getDocComment()` now returns a
comment object (which can be modified using `->setText()`) the `setDocComment()` method was
removed. Comment objects implement a `__toString()` method, so `getDocComment()` should
continue to work properly with old code.

* [BC] Use inject-once approach for lexer:

Now the lexer is injected only once when creating the parser. Instead of
Now the lexer is injected only once when creating the parser. Instead of

$parser = new PHPParser_Parser;
$parser->parse(new PHPParser_Lexer($code));
$parser->parse(new PHPParser_Lexer($code2));
$parser = new PHPParser_Parser;
$parser->parse(new PHPParser_Lexer($code));
$parser->parse(new PHPParser_Lexer($code2));

you write:
you write:

$parser = new PHPParser_Parser(new PHPParser_Lexer);
$parser->parse($code);
$parser->parse($code2);
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$parser->parse($code);
$parser->parse($code2);

* Fix `NameResolver` visitor to also resolve class names in `catch` blocks.

Expand All @@ -108,18 +108,18 @@ Version 0.9.1 (24.04.2012)

* Add ability to add attributes to nodes:

It is now possible to add attributes to a node using `$node->setAttribute('name', 'value')` and to retrieve them using
`$node->getAttribute('name' [, 'default'])`. Additionally the existance of an attribute can be checked with
`$node->hasAttribute('name')` and all attributes can be returned using `$node->getAttributes()`.
It is now possible to add attributes to a node using `$node->setAttribute('name', 'value')` and to retrieve them using
`$node->getAttribute('name' [, 'default'])`. Additionally the existance of an attribute can be checked with
`$node->hasAttribute('name')` and all attributes can be returned using `$node->getAttributes()`.

* Add code generation features: Builders and templates.

For more infos, see the [code generation documentation][1].
For more infos, see the [code generation documentation][1].

* [BC] Don't traverse nodes merged by another visitor:

If a NodeVisitor returns an array of nodes to merge, these will no longer be traversed by all other visitors. This
behavior only caused problems.
If a NodeVisitor returns an array of nodes to merge, these will no longer be traversed by all other visitors. This
behavior only caused problems.

* Fix line numbers for some list structures.
* Fix XML unserialization of empty nodes.
Expand Down
18 changes: 9 additions & 9 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.
* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Expand Down
74 changes: 37 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,43 @@ You'll get a syntax tree looking roughly like this:

```
array(
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hi
)
1: Scalar_String(
value: World
)
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: hello
1: world
)
)
args: array(
0: Arg(
value: Scalar_String(
value: foo
)
byRef: false
)
1: Arg(
value: Expr_Concat(
left: Scalar_String(
value: bar
)
right: Scalar_String(
value: baz
)
)
byRef: false
)
)
)
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hi
)
1: Scalar_String(
value: World
)
)
)
1: Expr_FuncCall(
name: Name(
parts: array(
0: hello
1: world
)
)
args: array(
0: Arg(
value: Scalar_String(
value: foo
)
byRef: false
)
1: Arg(
value: Expr_Concat(
left: Scalar_String(
value: bar
)
right: Scalar_String(
value: baz
)
)
byRef: false
)
)
)
)
```

Expand Down
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "nikic/php-parser",
"description": "A PHP parser written in PHP",
"keywords": ["php", "parser"],
"type": "library",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Nikita Popov"
}
],
"require": {
"php": ">=5.2"
},
"autoload": {
"psr-0": { "PHPParser": "lib/" }
}
"name": "nikic/php-parser",
"description": "A PHP parser written in PHP",
"keywords": ["php", "parser"],
"type": "library",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Nikita Popov"
}
],
"require": {
"php": ">=5.2"
},
"autoload": {
"psr-0": { "PHPParser": "lib/" }
}
}
26 changes: 13 additions & 13 deletions doc/0_Introduction.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ roughly looking like this:

```
array(
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hi
)
1: Scalar_String(
value: World
)
)
)
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hi
)
1: Scalar_String(
value: World
)
)
)
)
```

Expand All @@ -68,11 +68,11 @@ What else can it do?
Apart from the parser itself this package also bundles support for some other, related features:

* Support for pretty printing, which is the act of converting an AST into PHP code. Please note
that "pretty printing" does not imply that the output is especially pretty. It's just how it's
called ;)
that "pretty printing" does not imply that the output is especially pretty. It's just how it's
called ;)
* Support for serializing and unserializing the node tree to XML
* Support for dumping the node tree in a human readable form (see the section above for an
example of how the output looks like)
example of how the output looks like)
* Infrastructure for traversing and changing the AST (node traverser and node visitors)
* A node visitor for resolving namespaced names

Expand Down
20 changes: 10 additions & 10 deletions doc/1_Installation.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ Installing via Composer

Create a `composer.json` file in your project root and use it to define your dependencies:

{
"require": {
"nikic/php-parser": "0.9.3"
}
}
{
"require": {
"nikic/php-parser": "0.9.3"
}
}

Then install Composer in your project (or [download the composer.phar][1] directly):

curl -s http://getcomposer.org/installer | php
curl -s http://getcomposer.org/installer | php

And finally ask Composer to install the dependencies:

php composer.phar install
php composer.phar install

Installing as a PEAR package
----------------------------

Run the following two commands:

pear channel-discover nikic.github.com/pear
pear install channel://nikic.github.com/pear/PHPParser-0.9.3
pear channel-discover nikic.github.com/pear
pear install channel://nikic.github.com/pear/PHPParser-0.9.3

Installing as a Git Submodule
-----------------------------

Run the following command to install the parser into the `vendor/PHP-Parser` folder:

git submodule add git://github.com/nikic/PHP-Parser.git vendor/PHP-Parser
git submodule add git://github.com/nikic/PHP-Parser.git vendor/PHP-Parser



Expand Down
Loading