1449 Commits

Author SHA1 Message Date
Nikita Popov
1f504d2c7d Don't trim in Comment::getReformattedText()
In the past, single-line comments were stored together with the
trailing newline. Later we switched to the PHP8 comment
representation, where the trailing newline is not part of the
comment anymore. As such, there is also no need to trim here.

This is split out from GH-867.
2022-08-07 16:19:39 +02:00
Anton
c55c7a2ac3
Add json and ctype as required extensions in composer.json (#864) 2022-08-07 16:00:03 +02:00
Anton
9ef528f3f5 ParserAbstract: remove undefined class in use
Class `PhpParser\Parser\Tokens` not exists in current version
2022-08-07 15:59:06 +02:00
Nikita Popov
e61bb11989 Add additional upgrading notes for pretty printer 2022-07-24 23:06:20 +02:00
Nikita Popov
cf0cd6003e Improve heuristic for escaping in single quoted strings
It is idiomatic to not escape backslashes if they are followed by
a non-special character.
2022-07-24 22:56:44 +02:00
Nikita Popov
646b490735 Don't force newline after doc string when targeting PHP >= 7.3 2022-07-24 22:15:42 +02:00
Nikita Popov
c218db3e16 Add additional test case for assignment precedence
This is a case where the parentheses around the assignment *are*
important.
2022-07-23 22:18:37 +02:00
Nikita Popov
84813dc1e4 Avoid repeatedly downloading archive in run-php-src.sh
When doing local testing, chances are that the archive is already
present.
2022-07-23 22:17:33 +02:00
Nikita Popov
59145a4443 Treat assignments as unary operators
Assignment expressions can be viewed as unary operators where
the whole "$x =" part is the operator.
2022-07-23 21:53:48 +02:00
Nikita Popov
7bf6348240 Remove inc/dec from precedence map
Inc/dec are primitive expressions that only accept a variable
operand, rather than a general expression operand.
2022-07-23 21:48:10 +02:00
Nikita Popov
a73c8ee03b Add a phpVersion option to the pretty printer
This is currently just used to initialize the default for short
array syntax.

The default target version in 7.0, which also means that the
default for short arrays is flipped to on.
2022-07-23 18:23:39 +02:00
Nikita Popov
1e89658cae Add PhpVersion class 2022-07-23 17:52:59 +02:00
MathiasReker
050342b5df Add visibility modifiers to constants
Closes GH-848.
2022-07-23 16:04:21 +02:00
Anton
a3f2bb634d Add __serialize/__unserialize to ClassMethod::$magicNames 2022-07-23 12:58:49 +02:00
MathiasReker
de4ac93023 Single blank line at eof
A PHP file without end tag must always end with a single empty line feed.
2022-07-04 20:38:51 +02:00
MathiasReker
4021a63cef No superfluous elseif
Replaces superfluous elseif with if.
2022-07-04 20:36:22 +02:00
MathiasReker
653757bec6 Nullable type declaration for default null value
Adds ? before type declarations for parameters with a default null value
2022-07-04 20:34:31 +02:00
MathiasReker
572af7fff2 No unused imports
Unused use statements must be removed.
2022-07-04 17:53:10 +02:00
MathiasReker
0086a261d0 Short scalar cast
Cast (boolean) and (integer) should be written as (bool) and (int), (double) and (real) as (float), (binary) as (string).
2022-07-04 17:50:40 +02:00
Nikita Popov
5aae65e627 Add Parser::getLexer() method
Not sure if this is going to stick, but for now this makes it
easier to obtain the Lexer instance when creating the parser via
ParserFactory.
2022-06-19 21:05:31 +02:00
Nikita Popov
0ea134a507 Add PHP 8 parser with correct concatenation precedence
The PHP 7 and PHP 8 parsers use the same grammar file and only
differ in token precedence.
2022-06-19 20:07:17 +02:00
Nikita Popov
a38a60b7dd Move Tokens::T_* to Php7::T_*
Drop the separate tokens class, move them into the parser.
2022-06-19 18:12:20 +02:00
Nikita Popov
c878d7195d Move token mapping from lexer to parser
This allows a different token mapping per parser.
2022-06-19 18:05:52 +02:00
Nikita Popov
6e0eec807e Move definition of compatibility tokens into separate file 2022-06-19 17:29:24 +02:00
Nikita Popov
71ed641cd4 Handle true/false/null types in builder APIs 2022-06-19 11:10:43 +02:00
Nikita Popov
e3ff8cf035 Add support for true type
The null/false types were alread accepted previously, even though
they are only legal as standalone types since PHP 8.2.
2022-06-19 11:06:39 +02:00
Nikita Popov
b0469d127e Rename Expr\ClosureUse -> ClosureUse
This is not a real expression, treat it similarly to Node\Arg
or Node\Param.

The old name is retained as an alias for compatibility.
2022-06-12 21:55:56 +02:00
Nikita Popov
23be1f9bd1 Update doc references 2022-06-12 21:18:11 +02:00
Nikita Popov
3fd30f64bc Remove deprecated param builder method 2022-06-12 21:14:22 +02:00
Nikita Popov
55f29b152c Improve ParserFactory version targeting
Most users will want to pick createForNewestSupportedVersion()
or getForHostVersion(). The currently default is the former,
which can lead to unwanted surprised due to PHP BC breaks for
users that actually want the latter. Make this choice more
explicit.
2022-06-12 18:56:18 +02:00
Nikita Popov
d3d1297c0d Remove PHP 5 parser 2022-06-12 18:18:50 +02:00
Romain
b4902cefe4 optimization haveTokenImmediatelyAfter performance 2022-06-10 22:07:58 +02:00
Nikita Popov
b6d11da541 Add space after "use" during empty list insertion as well 2022-06-05 22:59:08 +02:00
Nikita Popov
bdd131d3ec Add missing strict_types=1 directive to parser 2022-06-05 22:51:45 +02:00
Nikita Popov
472e163ffa Use extends instead of class_alias
Apparently we can't alias an internal class.
2022-06-05 18:26:12 +02:00
Nikita Popov
fe9db376a1 Perform token position adjustment during emulator patching 2022-06-05 18:20:24 +02:00
Nikita Popov
aff98bbf16 Use PHP 8.0 token representation
Migrate everything to use PhpToken-compatible token representation,
rather than the legacy array/string representation.
2022-06-05 17:44:42 +02:00
Tomas Votruba
7c445bb608
Remove space before return type in insertionMap (#841)
* remove space before colon in PrettyPrinterAbstract

* update tests
2022-06-04 23:23:07 +02:00
Nikita Popov
5af93eee52 Use nullable type instead of null default
Fixes #752.
2022-06-04 16:50:19 +02:00
Nikita Popov
27fe7a68c0 Include space after closure use 2022-06-04 13:22:58 +02:00
Dominik Peters
6c0b63d9af Change print order of modifiers
Print abstract/final before visibility modifiers, in line with
PSR-12.

Closes #826.
2022-06-04 13:19:07 +02:00
Nikita Popov
87387caf8f Remove space before return type in pretty printer 2022-06-04 13:01:02 +02:00
Nikita Popov
9c5eb3ccba Add some missing type annotations 2022-06-04 12:48:12 +02:00
Nikita Popov
e70541f136 Merge branch '4.x' 2022-06-04 12:44:47 +02:00
Nikita Popov
2d589921f2 Fix incorrect doc type 2022-06-04 12:44:36 +02:00
Nikita Popov
5466ee365f Drop support for running on PHP 7.0 2022-06-04 12:27:41 +02:00
Nikita Popov
1f416d9052 Target PHP-Parser 5.0 2022-06-04 12:20:42 +02:00
Nikita Popov
cdb731fa8b Update integration test target to 8.1 2022-05-31 23:18:52 +02:00
Nikita Popov
e727475d08 Support readonly as function name
This special case was added after the PHP 8.1 release.
2022-05-31 23:18:52 +02:00
Nikita Popov
34bea19b6e Release PHP-Parser 4.14.0 v4.14.0 2022-05-31 22:59:12 +02:00