1607 Commits

Author SHA1 Message Date
Nikita Popov
c48ee36f54 Allow passing visitors to NodeTraverser constructor 2023-07-09 15:34:31 +02:00
Nikita Popov
8b1371990c Minor documentation updates 2023-07-09 15:34:31 +02:00
Abdul Malik Ikhsan
eaa1d91b4e
Early return false after VariadicPlaceholder check on CallLike::isFirstClassCallable() (#924)
VariadicPlaceholder can only occur as the first (and only) argument, so avoid a loop to check for it.
2023-06-25 18:38:11 +02:00
Danny van der Sluijs
3fb4b92f59 Update main.yml to use GitHub Actions V3
Updates the GitHub Actions from V2 to V3

(cherry picked from commit 1d0748ad35201d483816634dd4bfe55a6f26d857)
2023-06-24 17:59:49 +02:00
Nikita Popov
571ca90b7e Release PHP-Parser 5.0.0-alpha3 v5.0.0alpha3 2023-06-24 17:48:52 +02:00
Nikita Popov
16c766eae1 Don't take subnodes by reference when traversing
Explicitly assign the property where necessary to avoid the
creation of unnecessary reference-wrappers everywhere.
2023-05-28 21:54:07 +02:00
Nikita Popov
53f6717329 Remove unnecessary Node return value from traverseNode()
The node always stays the same: We may only change subnodes.
2023-05-28 21:51:45 +02:00
Nikita Popov
5b65f9fc92 Some documentation updates 2023-05-27 21:35:10 +02:00
Nikita Popov
69993a181a Update CHANGELOG and UPGRADING 2023-05-27 16:26:36 +02:00
Nikita Popov
23647573e8 Represent names using string rather than array of parts
In most circumstances we are interested in the whole string, not
the parts split by namespace separator. As names are common, this
representation measurably improves memory usage and performance.
2023-05-21 21:25:49 +02:00
Nikita Popov
df3a7057ab Add Name::getParts(), deprecate Name::$parts
In preparation for switching this to a plain string in
PHP-Parser 5, deprecate direct access to the property and
provide an API that will work on both versions.

(cherry picked from commit c9e5a13d68486e9fd75f9be1b4639644e54e7f4f)
2023-05-21 21:24:13 +02:00
Nikita Popov
d43edfbb31 Support CRLF newlines in pretty printer
Can be enabled using the "newlines" option.
2023-05-21 20:56:56 +02:00
Nikita Popov
ad8daa12b2 Normalize newlines in Comment::getReformattedText()
Normalize CRLF to LF in getReformattedText(). That was, if the
comment is pretty-printed, we will use proper LF newlines, rather
than inserting indentation between the CR and LF.

At the same time, this also makes it easier to emit actual CRLF
newlines with a custom pretty printer.

Fixes #599.
2023-05-21 17:38:56 +02:00
Nikita Popov
5883189d61 Fix return type of Comment::getReformattedText() 2023-05-21 15:51:27 +02:00
Nikita Popov
afe1628a72 Add support for NodeVisitor::REPLACE_WITH_NULL
Fixes #716.
2023-05-21 15:41:41 +02:00
Nikita Popov
289756d056 Gracefully handle non-contiguous arrays in Differ
Fixes #909.
2023-05-21 15:15:36 +02:00
Nikita Popov
8490c0e82d Call leaveNode() on visitors in reverse order
Node visitation is now properly nested. The call sequence will
now be

    $visitor1->enterNode($n);
    $visitor2->enterNode($n);
    $visitor2->leaveNode($n);
    $visitor1->leaveNode($n);

rather than

    $visitor1->enterNode($n);
    $visitor2->enterNode($n);
    $visitor1->leaveNode($n);
    $visitor2->leaveNode($n);

Fixes #899.
2023-05-21 12:31:15 +02:00
Nikita Popov
8bc698248d Ensure removing visitor does not leave holes 2023-05-21 12:07:21 +02:00
Nikita Popov
fb2c3ac97c Fix emulative lexer with default error handler
If no error handler is provided, explicitly create one, so we don't
end up calling handleError() on null.
2023-05-20 22:26:53 +02:00
Nikita Popov
c23976a299 Stop accepting strings as types
For types the use of a string is ambiguous -- it could be either
an Identifier or a Name. Don't guess.

Retain the implicit promotion to Identifier in places where only
Identifier is legal, e.g. various symbol names.
2023-05-20 22:13:04 +02:00
Nikita Popov
a9dad5c54e Fix type of ClassConst::$type 2023-05-20 22:01:01 +02:00
Nikita Popov
74caed6446 Fix labelCharMap for DEL character
This map is supposed to have string keys, not integer keys.
2023-05-20 21:55:53 +02:00
Nikita Popov
a5d4c1005c Remove some unused symbols 2023-05-20 21:40:55 +02:00
Nikita Popov
93731c5cfa Move constants from NodeTraverser to NodeVisitor
These are really part of the NodeVisitor API. Retain aliases for
compatibility.
2023-05-20 21:37:34 +02:00
Nikita Popov
0a8a333a4a Blacklist test with comments in intersection types 2023-05-20 21:21:45 +02:00
Nikita Popov
91da19147b Support readonly anonymous classes 2023-05-20 21:17:44 +02:00
Nikita Popov
5c267f55c9 Add support for typed constants
RFC: https://wiki.php.net/rfc/typed_class_constants
2023-05-20 21:02:03 +02:00
Nikita Popov
9a5d5c112c Add newline at end of file for many tests
Add the newline in reconstructTest() and run updateTests.php, to
reduce spurious diffs in the future.
2023-05-20 19:18:11 +02:00
Nikita Popov
779b6950c3 Fix coding style 2023-05-20 18:55:12 +02:00
Nikita Popov
b68fb76f14 Add makeReadonly() to param builder
(cherry picked from commit 11e2dcd96c830ee934fa7b0243f4d67d8a8821ab)
2023-05-19 22:17:50 +02:00
Cees-Jan Kiewiet
36a6dcd04e [5.x] Add constructor property promotion
By making flags on the Param builder configurable by providing make(Public|Protected|Private) methods we can promote parameters to properties from the constructor
2023-03-06 23:12:51 +01:00
Nikita Popov
bb4263ea1a Treat del as label character depending on PHP version
In formatting-preserving pretty printing, treat DEL as a label
character based on the target PHP version (the default of 7.1
implying it isn't one).

This avoids failure to round-trip an unchanged input.
2023-03-05 17:03:00 +01:00
Nikita Popov
4ce0de2d12 Use PHP 7.1 as default pretty printer target 2023-03-05 16:56:50 +01:00
Nikita Popov
a3bc900a41 Don't ltrim when preserving formatting
We shouldn't ltrim when printing a whole file, that way we will
not just fail to preserve formatting, but actually change semantics
by dropping meaningful whitespace.
2023-03-05 16:42:30 +01:00
Nikita Popov
7785d2b887 Remove garbage collection section from docs
The GC issue has been fixed in PHP 7.3 and is no longer relevant.
2023-03-05 16:12:50 +01:00
Nikita Popov
aa721520f9 Don't generate braces for "else if"
Mentioned in #915.
2023-03-05 11:30:39 +01:00
Nikita Popov
da65ae474d Release PHP-Parser 5.0.0 alpha 2 v5.0.0alpha2 2023-03-05 10:49:58 +01:00
Nikita Popov
8fb716841e Update upgrading documentation 2023-03-05 10:49:24 +01:00
Nikita Popov
b9974596e0 Update changelog 2023-03-04 23:25:31 +01:00
Anthony Ferrara
64484a4979 Add PrettyPrinter interface
Closes #423.
2023-03-04 21:56:58 +01:00
Nikita Popov
a0ed229b31 Revert "Rename PrettyPrinterAbstract to PrettyPrinter"
This reverts commit 2217f14d6e039f1c0572329e6fcc99f6c17178a3.
2023-03-04 21:54:56 +01:00
Nikita Popov
1286059998 Set allowed exceptions in fuzzer 2023-03-04 19:07:27 +01:00
Nikita Popov
698ff1ca46 Don't always omit parentheses for argument-less yield
We may need parentheses around an argument-less yield to distinguish
(yield) - $a from yield -$a and similar.

Treat argument-less yield like a prefix operator. This will print
parentheses a bit more often than is really required, because the
arity ambiguity only exists for certain operators. This seems like
a reasonably good approximation through, as it only affects
argument-less yield on the LHS of infix operators.
2023-03-04 12:06:35 +01:00
Nikita Popov
7877e0302d Handle group use special case in fuzzer
Same as for normal use.
2023-03-04 11:59:42 +01:00
Nikita Popov
b3158e0b53 Respect namespace style for enum scalar type printing
Doesn't matter in any practical sense because such types are always
invalid, but makes sure pretty printing round-trips.
2023-03-04 11:56:59 +01:00
Nikita Popov
bbec9db626 Handle overflowing \u escape sequence 2023-03-01 22:39:15 +01:00
Nikita Popov
a4728678fc Don't skip tests with evaluate segment when generating corpus
This code was adopted from test updating, but in this context
we're fine with just evaluating these.
2023-03-01 21:37:37 +01:00
Nikita Popov
6649012e6c Produce error if <?= used as identifier
Due to a peculiarity of how <?= is handled, it can get treated as
an echo identifier. Make sure it isn't, to match PHP behavior.
2023-03-01 21:35:27 +01:00
Nikita Popov
2217f14d6e Rename PrettyPrinterAbstract to PrettyPrinter 2023-03-01 21:25:02 +01:00
Nikita Popov
c62dda9507 Strip trailing doc string newline before parsing escape sequences
If the doc string ends on an escaped \r, it should not get eaten
as the "last newline".
2023-03-01 21:05:55 +01:00