1740 Commits

Author SHA1 Message Date
Nikita Popov
d8e8065313 Don't parse unicode escapes for PHP < 7.0
We still had the option for this but were hardcoding it to true.
Make it conditional on the PHP version instead.
2023-09-23 17:35:51 +02:00
RainX
f4961b89ac
Add missing phpdoc annotations in AST nodes (#946) 2023-09-18 21:16:54 +02:00
Nikita Popov
8b9488e1e6 Explicit test new ParserFactory methods 2023-09-17 20:42:25 +02:00
Nikita Popov
21fa9c98b3 Drop some @covers annotations 2023-09-17 20:28:02 +02:00
Nikita Popov
0b3c762939 Update docs table of contents 2023-09-17 20:26:35 +02:00
Nikita Popov
edee19a5d2 Release PHP-Parser 5.0.0 Beta 1 v5.0.0beta1 2023-09-17 20:19:48 +02:00
Nikita Popov
ea5ba26749 Add upgrading notes for lexer changes 2023-09-17 20:17:54 +02:00
Nikita Popov
ab51e9d35a Remove superfluous phpdoc tags
These just specify a type that is already specified as a real PHP
type.
2023-09-17 18:24:05 +02:00
Nikita Popov
1873020bf7 Deprecate Node::getLine() in favor of Node::getStartLine() 2023-09-17 16:32:10 +02:00
Nikita Popov
1b346f7935 Remove deprecated Comment methods 2023-09-17 16:30:28 +02:00
Nikita Popov
2d3dd4e23e Don't align phpdoc tags
I did this to start with, but then alignment kept being broken
during refactorings, and at some point I switched to not aligning,
and now we have a big mess.

Add a php-cs-fixer rule to consistently not align phpdoc tags.
2023-09-17 16:00:10 +02:00
Nikita Popov
3c52ea9b6d Document phpVersion effect on pretty printer 2023-09-17 15:52:10 +02:00
Nikita Popov
5a7753a930 Update changelog 2023-09-17 15:28:40 +02:00
Nikita Popov
c91c8633a4 Add PHP 8.3 to CI matrix 2023-09-17 11:59:43 +02:00
Nikita Popov
e395f042d2 Add php-cs-fixer CI job 2023-09-17 11:08:23 +02:00
Nikita Popov
21ead39056 Update docs after lexer changes 2023-09-17 09:07:58 +02:00
Nikita Popov
b11fca0310 Run integration test against PHP 8.3 2023-09-16 09:54:10 +02:00
Nikita Popov
06c7ab51b7 Drop Lexer::getTokens() method
This doesn't make a lot of sense now that Lexer::tokenize() returns
the tokens.

The tokens for the last parse should be fetched via
Parser::getTokens() instead.
2023-09-16 09:50:50 +02:00
Markus Staab
263fa80b81
Use more precise Use_::TYPE_* types (#945)
For better static analysis support in consuming projects.
2023-09-14 10:03:42 +02:00
Nikita Popov
5da5231fde Indent heredoc/nowdoc when targeting PHP >= 7.3 2023-08-27 22:02:31 +02:00
Nikita Popov
8d58380108 Default pretty printer to PHP 7.4 2023-08-27 21:26:47 +02:00
Nikita Popov
efe93a171b Update PHP versions in workflow 2023-08-17 21:40:48 +02:00
Nikita Popov
ea77807592 Add more property types
Some of these are not maximally accurate due to lack of union
types.
2023-08-17 21:36:07 +02:00
Nikita Popov
9a68468fda Update phpstan baseline 2023-08-16 21:38:27 +02:00
Nikita Popov
502b090900 Add property types
Types omitted in two places where we violate them currently:
Namespace_::$stmts can be null during parsing, and Enum_::$scalarType
can be a complex type for invalid programs.
2023-08-16 21:37:02 +02:00
Nikita Popov
3c0432b09d Remove emulation for unsupported PHP versions 2023-08-16 21:09:51 +02:00
Nikita Popov
ee3e7db3fc Raise minimum PHP version to PHP 7.4 2023-08-16 21:06:38 +02:00
Nikita Popov
ba851243f4 Replace startLexing() with tokenize()
For now Lexer::getTokens() still exists, but should probably be
removed.
2023-08-13 16:06:10 +02:00
Nikita Popov
d1d784a5c6 Fixup line numbers when applying emulator patches
This fixes the test failures on PHP 7.2.
2023-08-13 12:59:26 +02:00
Nikita Popov
62853b179c Fix PhpStan errors 2023-08-13 12:45:21 +02:00
Nikita Popov
4b497045e0 Move attribute handling into parser
The Lexer now only provides the tokens to the parser, while the
parser is responsible for determining which attributes are placed
on notes. This only needs to be done when the attributes are
actually needed, rather than for all tokens.

This removes the usedAttributes lexer option (and lexer options
entirely). The attributes are now enabled unconditionally. They
have less overhead now, and the need to explicitly enable them for
some use cases (e.g. formatting-preserving printing) doesn't seem
like a good tradeoff anymore.

There are some additional changes to the Lexer interface that
should be done after this, and the docs / upgrading guide haven't
been adjusted yet.
2023-08-13 10:40:21 +02:00
Nikita Popov
b20267c5ad Make use of default actions
For the default action $$ = $1, save the closure invocation.
2023-07-09 21:18:21 +02:00
Nikita Popov
748aab3365 Don't set start attributes for whitespace
These will get overwritten later anyway.
2023-07-09 15:47:37 +02:00
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