Nikita Popov
a513ccabb7
Improve constant evaluation and add docs
...
Split into evaluateDirectly() and evaluateSilently(), to be able
to treat errors more gracefully. Add documentation for constant
evaluation.
2018-01-27 17:47:45 +01:00
Nikita Popov
d817818b5d
Move TokenStream into Internal namespace
2018-01-27 13:40:20 +01:00
Nikita Popov
6a273c9fbd
Remove Autoloader class
2018-01-25 23:13:53 +01:00
Nikita Popov
1cdb280a30
Merge branch '3.x'
2018-01-25 22:28:08 +01:00
Nikita Popov
d01fafcb40
Handle +(++$x) and -(--$x) as well
2018-01-25 22:27:37 +01:00
Nikita Popov
b85b6b3519
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/PrettyPrinter/Standard.php
2018-01-25 22:18:32 +01:00
Nikita Popov
94c715d97e
Fix pretty printing of -(-$x) and +(+$x)
...
Fixes #459 .
2018-01-25 22:17:35 +01:00
Nikita Popov
4dacbb8d39
FPPP: Fix indentation on list insertion
...
Use indentation of last list element, instead of indentation
before the insertion point.
Fixes #466 .
2018-01-25 22:08:40 +01:00
Gabriel Caruso
68d07c4662
[CS] New line in the end of file
2018-01-13 16:08:26 +01:00
Gabriel Caruso
f6617e6d25
[CS] Space after ternary operator
2018-01-13 16:04:00 +01:00
Gabriel Caruso
2499534729
[CS] Whitespace before return type
2018-01-13 16:03:59 +01:00
Gabriel Caruso
e0a2043089
[CS] Space before casting
2018-01-13 16:03:57 +01:00
Gabriel Caruso
e6e52abae7
[CS] Trim whitespaces
2018-01-13 16:03:56 +01:00
Gabriel Caruso
7f72c84122
[CS] Open class brackets in new line
2018-01-13 16:03:55 +01:00
Gabriel Caruso
fc8ac71e76
[CS] Trim whitespaces inside arrays
2018-01-13 16:03:54 +01:00
Gabriel Caruso
a8968caa5b
[CS] Remove extra lines
2018-01-13 16:03:53 +01:00
Nikita Popov
5285df8f22
[CS] Use elseif instead of else if
...
Conflicts:
lib/PhpParser/TokenStream.php
2018-01-13 16:03:36 +01:00
Gabriel Caruso
bf7d811cda
Add methods visibility ( #464 )
...
* [PSR-2] Visibility before static
* [PSR-2] Declare method Visibility
2018-01-10 19:07:41 +01:00
Gabriel Caruso
248b29ecf6
Add public visibility to getType method ( #463 )
2018-01-10 18:57:48 +01:00
Gabriel Caruso
3bc31488ce
Combine issets ( #460 )
2018-01-04 13:36:01 +01:00
Nikita Popov
92b39e3d1f
Fix nNextFreeElement for arrays with trailing comma
...
Ugh.
2017-12-26 21:17:36 +01:00
Nikita Popov
1c7fd314d1
FPPP: Add heuristic for multi-line lists
2017-12-26 21:14:36 +01:00
Nikita Popov
fb8175567e
Simplify delayed add code
...
$insertStr always stays the same, so no reason to store it
separately.
2017-12-26 17:53:36 +01:00
Nikita Popov
8d3cb5f57b
FPPP: Fallback if we must insert a block
2017-12-26 15:41:38 +01:00
Nikita Popov
a86151f24f
FPPP: Fix fallback for inline HTML
2017-12-26 15:08:29 +01:00
Gabriel Caruso
e6e8791848
Missing # in method description
2017-12-25 14:28:33 +01:00
Gabriel Caruso
4dbb02c57b
Use Null Coalesce Operator
2017-12-15 21:41:41 +01:00
Nikita Popov
4fcdac40d1
FPPP: Fix insertion of multiple elems at start
2017-12-02 15:10:15 +01:00
Nikita Popov
dc3ace55c3
FPPP: Support insert at start of list node ( #446 )
2017-12-01 22:09:51 +01:00
Nikita Popov
e5453f0d46
Extract pSingleQuotedString as an extension point
...
And add some more string formatting tests.
2017-12-01 18:31:21 +01:00
Nikita Popov
b507fa43da
Ensure names are not empty
2017-12-01 18:13:55 +01:00
Nikita Popov
336a49b428
FPPP: Fix comment indentation ( #443 )
2017-11-13 13:27:27 +01:00
Nikita Popov
fa174b093f
Merge branch '3.x'
2017-11-13 01:15:38 +01:00
Nikita Popov
94ca9a7ab9
Use Tokens::class in lexer
...
Ref #441 .
2017-11-13 01:14:55 +01:00
Nikita Popov
0bb74e03aa
Drop two more getType() usages in builders
2017-11-13 00:24:01 +01:00
Nikita Popov
8d3f48ab75
Switch some auxiliary pretty printer tables away from getType()
...
Instead use class names via ::class.
2017-11-13 00:18:44 +01:00
Nikita Popov
1c11626f0a
Add explicit getType() methods
...
Rather than automatically deriving getType() from the class name.
2017-11-12 21:27:14 +01:00
Nikita Popov
05e2cd287e
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/NodeAbstract.php
2017-11-12 21:12:27 +01:00
Maks Rafalko
bac91b426e
Correctly determine Type of Node when PHP-Parser's namespaces are prefixed
...
Hi there,
I'm working on mutation testing framework ([Infection](https://github.com/infection/infection/ )) that is distributed as a PHAR. One of this goal is to run target project's test suite against mutated code. Since we use reflection and load project's autoloader, we want to avoid potential conflicts between vendor files of Infection itself and the target project.
To avoid this issue, there is a project calld [PHP-Scoper](https://github.com/humbug/php-scoper ). What it does is it prefixes all the namespaces of the library (including vendor folder) with some character(s), for example namespace `Infection\Mutator\PublicVisibility` is transformed to `ScoperAbc123\Infection\Mutant\PublicVisibility`.
But since it also prefixes vendor folder, PHP-Parser's classes are prefixed as well and `NodeAbstract::getType()` after this prefixing works incorrectly.
There is a hardcoded number `15` which means to remove `'PhpParser\Node'` (length=15) substring from the FQCN.
Code:
```php
// PHPParser\Node\Stmt\Declare_ -> Stmt_Declare
return strtr(substr(rtrim(get_class($this), '_'), 15), '\\', '_');
```
What I suggest is a little be more dynamic solution, to correctly extract class name (type) from the ***prefixed*** FQCL:
`ScoperAbc123\PHPParser\Node\Stmt\Declare_` -> `Stmt_Declare`
2017-11-12 21:11:41 +01:00
Nikita Popov
a75164c77e
Rename YYNLSTATES to numNonLeafStates
2017-11-12 16:09:00 +01:00
Nikita Popov
c59e75f873
Clear parser state directly after parsing
...
I don't think this makes any difference in practical scenarios, but
it makes memory usage analysis simpler.
2017-11-11 16:54:52 +01:00
Nikita Popov
4392a7b164
Fix PHP5 static call fixup
...
Variable nodes directly store the variable name as a string, they
don't use VarLikeIdentifier. So remove this wrapper if it exists.
2017-11-11 12:23:14 +01:00
Nikita Popov
68e9b91e9c
Use fully-qualified names for global constant references
2017-11-10 23:33:12 +01:00
Nikita Popov
e2c0c598a3
FPPP: Optimize indentation calculation
...
Precalculate the indentation for every position. The previous
implementation was quadratic for long lines.
2017-11-04 22:43:53 +01:00
Nikita Popov
9b6a2577fa
FPPP: Convert some checks to assertions
...
Don't just silently fall back if we receive illegal input.
2017-11-04 18:14:12 +01:00
Nikita Popov
457fe049a8
Ensure nodes have full complement of location info
2017-11-04 18:13:00 +01:00
Nikita Popov
6a2e1ae440
FPPP: Graceful handling of comment changes
2017-11-04 17:56:11 +01:00
Nikita Popov
47c973b3aa
Store start token position in comments
2017-11-04 17:45:14 +01:00
Nikita Popov
56bc8ebb9b
FPPP: Add support for removal from list nodes
2017-11-04 17:23:17 +01:00
Nikita Popov
fd6e8d7ea8
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Builder/Namespace_.php
lib/PhpParser/Node/Stmt/ClassMethod.php
test/PhpParser/Builder/NamespaceTest.php
2017-11-04 12:45:04 +01:00
Nikita Popov
0ba710affa
Add setDocComment() to namespace build ( #437 )
2017-11-04 12:43:02 +01:00
Alexander Miertsch
72231abe6d
ClassMethod stmts property can be null ( #435 )
...
Conflicts:
lib/PhpParser/Node/Stmt/ClassMethod.php
2017-11-04 12:38:45 +01:00
TomasVotruba
57bf378412
add missing strict_types to lib
2017-11-03 13:24:19 +01:00
Alexander Miertsch
ab596db285
ClassMethod stmts property can be null ( #435 )
2017-11-01 20:26:21 +01:00
Nikita Popov
b241a121a3
Fix trait alias to semi-reserved name parsing
...
This was missing the explicit construction of an Identifier node.
2017-10-29 14:15:48 +01:00
Nikita Popov
5054a68bfb
Reset origTokens in resetState()
...
In case one pretty printer is used in both preserving and
non-preserving mode.
2017-10-29 13:28:46 +01:00
Nikita Popov
5900d78cc9
FPPP: Support anonymous classes ( #432 )
...
This is a huge hack... We temporarily create a new node with the
correct structure and use that for printing.
I think it would be better to always use a separate node type for
NewAnonClass, rather than using a combination of New and Class,
but this would require some larger changes, as this node type would
have to be both Expr and ClassLike, which is not possible right now,
as the latter is a class rather than an interface...
2017-10-29 12:26:12 +01:00
Nikita Popov
776275361a
FPPP: Support modifier changes ( #428 )
...
I decided against introducing a node type for this. In the end it
would require special handling anyway.
2017-10-25 22:27:29 +02:00
Nikita Popov
f5de7f9894
FPPP: Check that nodes are nodes in pArray()
2017-10-18 15:42:01 +02:00
Wes
3193f7aae7
Fix documentation for "replaceNodes" option in NameResolver ( #425 )
2017-10-15 22:20:52 +02:00
Nikita Popov
bbec051e51
FPPP: Consolidate indentation levels
...
A bit annoying that we have to keep $this->nl always synchronized.
2017-10-06 18:21:08 +02:00
Nikita Popov
f071b66013
Print comments of inserted statements
2017-10-06 17:58:56 +02:00
Nikita Popov
57bc42517b
Move IdentifierTest where it belongs
...
Ooops...
2017-10-06 15:07:35 +02:00
Nikita Popov
bb2ac91115
Move leading space out of pStmt_Else
...
Same as previous commit. Also add support for pStmt_If->else
insertion.
2017-10-06 14:56:59 +02:00
Nikita Popov
e3888cbe02
Move leading space out of pStmt_ElseIf
...
This is not part of the elseif itself and as such belongs in the
pStmt_If printer.
2017-10-06 14:52:52 +02:00
Nikita Popov
310155832a
FPPP: Support insertion into list subnodes
...
With some rough edges...
2017-10-06 14:43:41 +02:00
Nikita Popov
ed8a744cd5
FPPP: Switch pArray() to use node list diffing
2017-10-06 12:02:00 +02:00
Nikita Popov
69aec6fb5b
Add implementation of Myers differ
...
Intended to be used in the format-preserving pretty printer for
handling changes in node lists.
2017-10-05 21:53:45 +02:00
Nikita Popov
75880fbe2d
Make code more explicit
2017-10-05 18:50:48 +02:00
Nikita Popov
65de924493
Add Identifier::toString()
...
For symmetry with the Name API.
Also add some missing unit tests.
2017-10-03 20:57:48 +02:00
Nikita Popov
f6cc85a796
FPPP: Fall back if comment in list node changes ( #420 )
2017-10-02 21:18:13 +02:00
Nikita Popov
cc600b67f6
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Parser/Php5.php
lib/PhpParser/Parser/Php7.php
2017-10-01 16:55:54 +02:00
Nikita Popov
d418bf3951
Preserve comments on empty blocks ( #382 )
2017-10-01 16:54:43 +02:00
Nikita Popov
4b1d9667af
Add constant expression evaluator ( #402 )
2017-09-30 18:56:44 +02:00
Nikita Popov
a02990a39a
Remove PHP 5 substr() workaround
...
In PHP 7 it no longer returns false instead of '' in this case.
2017-09-29 17:51:44 +02:00
Nikita Popov
cc328a4c9c
Add get{Start,End}{Line,TokenPos,FilePos}() methods
2017-09-29 17:34:15 +02:00
Nikita Popov
3d4621bbea
Don't return by ref from getAttribute()
...
This is not worth the few times where it might be useful.
2017-09-29 17:14:27 +02:00
Nikita Popov
d8f9173390
Add Node::getComments() method
2017-09-29 17:09:16 +02:00
Nikita Popov
5cfdc2e0a7
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Parser/Php5.php
lib/PhpParser/Parser/Php7.php
test/PhpParser/ParserTest.php
2017-09-26 18:46:44 +02:00
Nikita Popov
5a9fbca54a
Add attribute for namespace kinds ( #417 )
...
One of KIND_SEMICOLON or KIND_BRACED.
2017-09-26 18:45:05 +02:00
markbook2
4f8f773b9f
Remove leftover property intialization in pretty printer ( #416 )
2017-09-17 15:25:14 +08:00
markbook2
69ed40e401
Don't continue of searching if a global namespace declaration is found
2017-09-15 21:53:21 +08:00
Nikita Popov
ec8692fb9e
Fix InlineHTML indentation
2017-09-03 19:02:07 +02:00
Nikita Popov
b1cd07a7b5
Extract TokenStream class from pretty printer
2017-09-03 18:54:22 +02:00
Nikita Popov
61e624bc9d
Replace noIndent mechanism in pretty printer
...
Instead store newline with indentation in $nl property and use it
where needed.
The implementation should be changed to compilet indentLevel and
fpIndentLevel, I don't think these need to be kept separate.
2017-09-03 18:11:25 +02:00
Nikita Popov
31065389f1
Remove workarounds for reserved keyword method names
...
No longer necessary in PHP 7.
2017-09-02 20:08:20 +02:00
Nikita Popov
efd39a67a2
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Builder/Trait_.php
test/PhpParser/Builder/TraitTest.php
2017-08-29 23:20:47 +02:00
Nikita Popov
d77e6cd6e9
Allow TraitUse statements in trait builder
...
Fixes #413 .
2017-08-29 23:18:59 +02:00
Nikita Popov
fa12dc8a22
Merge branch '3.x'
2017-08-29 23:15:04 +02:00
Nikita Popov
a10780ca0d
Handle Nop statement after brace-style namespace
...
Fixes #412 .
2017-08-29 23:14:27 +02:00
Nikita Popov
9373a8e9f5
Implement JsonDecoder
...
Converts JSON representation back into node tree.
2017-08-18 23:56:12 +02:00
TomasVotruba
e2e99f269b
Add strict_types to lib code
2017-08-18 23:00:13 +02:00
Nikita Popov
7b36ca3b6c
Add isSpecialClassName() method to Identifier and Name
2017-08-15 22:59:52 +02:00
Nikita Popov
d97cc3d96e
Add toLowerString() method to Name and Identifier
...
Avoids patterns like strtolower((string) $name) when using
strict types.
2017-08-15 22:49:16 +02:00
TomasVotruba
9d599040b7
[cs] spaces
2017-08-13 21:14:28 +02:00
TomasVotruba
05e6725b7a
[cs] use strict comparison where allowed
2017-08-13 21:14:28 +02:00
TomasVotruba
ec535ea14e
[cs] use PHP 5.4 short array, since PHP 7.0 is min version
2017-08-13 21:14:28 +02:00
TomasVotruba
58bf92e4f7
[cs] remove unused imports
2017-08-13 21:14:28 +02:00
Nikita Popov
d11ef05aaf
Merge branch '3.x'
2017-07-19 17:14:23 +02:00
Nikita Popov
6fa073879e
Remove deprecation of Name::$parts
...
It doesn't look like this is going away for now, and we currently
don't have the APIs to cover all existing usages elegantly.
2017-07-19 17:13:10 +02:00