882 Commits

Author SHA1 Message Date
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
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
2d589921f2 Fix incorrect doc type 2022-06-04 12:44:36 +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
Tomas Votruba
678ccbe072
[PHP 8.2] Add readonly class support (#834)
RFC: https://wiki.php.net/rfc/readonly_classes

PHP implementation: php/php-src#7305
2022-05-15 23:19:31 +02:00
Tomas Votruba
5d83adcc0e
[String_] Add rawValue attribute (#831) 2022-05-15 23:04:59 +02:00
Tomas Votruba
3bf0082455
[DNumber] Add rawValue attribute to hold the original value (#833) 2022-05-15 18:12:28 +02:00
Tomas Votruba
d3eb10aca1
[LNumber] Add rawValue attribute to LNumber to allow numeric separator etc. (#832) 2022-05-15 18:09:05 +02:00
Ondrej Mirtes
f4b835f7d8 Fix PHPDoc type of namespacedName properties 2021-12-06 21:33:02 +01:00
Nikita Popov
f09f22760e Declare namespacedName property
For historical reasons, this property is used by the NameResolver
(in default mode). Declare it explicitly, rather than using a doc
comment.
2021-11-27 21:02:58 +01:00
Nikita Popov
4122ff3a91 Make NullsafeMethodCall extend from CallLike 2021-11-14 17:43:29 +01:00
Hassan Tariq
6f1f206862 Fix minor typo 2021-11-13 22:39:16 +01:00
Jaroslav Hanslík
99a24b6a55 Added builders for enum and enum case 2021-11-05 22:26:04 +01:00
Nikita Popov
4bfc4595ed Support reserved keywords as enum cases
Fixes #807.
2021-10-17 20:20:35 +02:00
Jaroslav Hanslík
54f19a0a66 Fixed array value evaluation with unpacked array 2021-10-11 21:35:21 +02:00
Jaroslav Hanslík
8da6d7ac62 Fixed ArrowFunction::$expr 2021-10-09 11:26:27 +02:00
Jaroslav Hanslík
0a20979a62 Unified builder methods for setting types 2021-09-14 18:09:07 +02:00
Nikita Popov
a45fb2a621 Add CallLike parent class
This provides a helper to determine whether a call is a first-class
callable, and a way to strip the args type to Arg[] if it isn't.
2021-09-12 22:29:08 +02:00
Nikita Popov
08501991d4 Don't make VariadicPlaceholder an expression
And don't store it in an Arg.
2021-09-12 21:59:26 +02:00
Nikita Popov
b5234eacd0 Tweak coding style 2021-09-12 21:54:03 +02:00
Shalvah
632ead3a82
Print comma before comments for new array item (#805)
Print comma before rather than after comments. Also switch to multiline mode if inserting an item with comments.

Fixes #804.
2021-09-12 21:51:25 +02:00
Nikita Popov
13549aa794 Add support for first-class callables
I'm somewhat unsure about the AST structure here.
VariadicPlaceholder is not a general expression. Maybe Arg->expr
should be Expr|VariadicPlaceholder? Or possibly the call arguments
should be an array of Arg|VariadicPlaceholder?
2021-09-03 17:18:40 +02:00
Nikita Popov
d2c645f163 Adjust token count in octal emulator 2021-09-03 16:35:10 +02:00
Nikita Popov
def24f2224 Add support for explicit octal literals 2021-09-03 16:29:30 +02:00
Nikita Popov
ace6c67a8a Add support for intersection types 2021-09-03 15:06:33 +02:00
Nikita Popov
0483391aca Introduce ComplexType base class
With the upcoming addition of intersection types, a type can
be Identifier|Name|NullableType|UnionType|IntersectionType, which
is quite the mouthful. Give NullableType and UnionType a common
base class ComplexType, which does not have any behavior, but
allows to write these types (and check them in instanceof) more
easily.
2021-09-02 18:35:05 +02:00
Nikita Popov
9aebf377fc Allow multiple modifiers for property promotion
Fixes issue #800.
2021-08-08 19:12:44 +02:00
simivar
5a43015499 Simplify BuilderHelpers::normalizeName() implementation
In order to get rid of the flag in `BuilderHelpers::normalizeNameCommon()` I have moved all the logic related to the normalization of the name to the `BuilderHelpers::normalizeName()` method and expr-related stuff to the `BuilderHelpers::normalizeNameOrExpr()` method which later calls the basic `normalizeName()` as well
2021-07-21 12:51:18 +02:00