Nikita Popov
d24745ddbc
Respect precedence during clone pretty printing
...
Clone is the prefix operator with the highest operator precedence,
but was not treated as an operator at all.
2023-02-26 14:58:17 +01:00
Nikita Popov
f6ddde6428
Perform end label check on escaped string
...
Escaping might convert a label character into an escape sequence
if it is not valid UTF-8.
2023-02-26 12:27:05 +01:00
Nikita Popov
47626c74ec
Handle interpolated variable after end label
...
Interpolated variables start with non-label characters, and as
such also count as end label terminators since PHP 7.3.
2023-02-26 12:20:32 +01:00
Nikita Popov
ce3337b0c2
Update allowed characters after doc string label
...
With the introduction of flexible doc strings, the ending label
is no longer required to be followed by a semicolon or newline.
We need to prevent doc string printing if the label is followed
by any non-label character.
2023-02-26 12:14:04 +01:00
Nikita Popov
d83562e6fe
Print INF as 1.0E+1000
...
This makes pretty printing round trip to another Float literal,
rather than a constant lookup. The 1e1000 form in particular is
chosen because that seems to be the typical form used in various
tests.
2023-02-26 09:47:19 +01:00
Nikita Popov
2df8878f5d
[PHP 8.3] Support dynamic class const fetch
...
RFC: https://wiki.php.net/rfc/dynamic_class_constant_fetch
2023-01-29 20:49:00 +01:00
Nikita Popov
4bcdf74b8b
Add support for perserving formatting for static modifier change
...
Closes GH-891.
2022-09-21 18:56:58 +02:00
Nikita Popov
f98341f688
Specify more types
2022-09-17 18:48:56 +02:00
Nikita Popov
43d6332dce
Add return types to PrettyPrinter\Standard
2022-09-11 17:49:41 +02:00
Nikita Popov
b9fe3449e8
Add missing parameter types
2022-09-11 15:22:23 +02:00
Nikita Popov
f59f226f65
Fix some phpstan warnings
2022-09-11 12:16:12 +02:00
Nikita Popov
4917c71a91
Rename Stmt\UseUse to UseItem
2022-09-03 18:59:48 +02:00
Nikita Popov
e1345f0c09
Rename Stmt\PropertyProperty to PropertyItem
2022-09-03 18:55:22 +02:00
Nikita Popov
03ccfa3dd4
Rename Stmt\DeclareDeclare to DeclareItem
2022-09-03 18:45:28 +02:00
Nikita Popov
a44faa6328
Rename Scalar\Encapsed to Scalar\InterpolatedString
2022-09-03 15:14:04 +02:00
Nikita Popov
f4ec6a1e53
Rename Scalar\EncapsedStringPart to InterpolatedStringPart
...
It is no longer an expression node, which unfortunately does
require a more awkward type for the Encaps node.
2022-09-03 13:25:23 +02:00
Nikita Popov
23835d20ef
Rename Scalar\LNumber to Scalar\Int_
2022-09-03 12:07:38 +02:00
Nikita Popov
66b20bd6bc
Rename Scalar\DNumber to Scalar\Float_
2022-09-03 11:56:06 +02:00
Nikita Popov
035c1c7cd2
Rename Stmt\StaticVar to StaticVar
...
This is part of a statement, not a statement by itself.
2022-09-02 22:51:13 +02:00
Nikita Popov
8be56afd2d
Rename Expr\ArrayItem to ArrayItem
...
Array items are not expressions by themselves.
2022-09-02 22:41:10 +02:00
Nikita Popov
dd63ddbc24
Add php-cs-fixer config and reformat
...
The formatting in this project has become something of a mess,
because it changed over time. Add a CS fixer config and reformat
to the desired style, which is PSR-12, but with sane brace placement.
2022-08-28 22:57:06 +02:00
Nikita Popov
68fc1ba4cb
Always use List_ node for array destructuring
...
Fixes #471 .
2022-08-28 18:48:26 +02:00
George Peter Banyard
9b2a01aa0c
Add support for DNF types ( #862 )
2022-08-07 17:10:11 +02:00
Nikita Popov
652fb0c6c1
Print trailing comma in param list if supported
2022-08-07 16:43:53 +02:00
Anton
ea9d6b2238
Always use pMaybeMultiline() for function parameters
...
Closes GH-861.
2022-08-07 16:34:26 +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
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
MathiasReker
4021a63cef
No superfluous elseif
...
Replaces superfluous elseif with if.
2022-07-04 20:36:22 +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
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
27fe7a68c0
Include space after closure use
2022-06-04 13:22:58 +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
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
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
ace6c67a8a
Add support for intersection types
2021-09-03 15:06:33 +02:00
Bob Weinand
3fb73520c1
Add handling for Enum(Case)s in NameResolver
2021-07-03 15:09:11 +02:00
Nikita Popov
ce91d139b5
Make sure match is one character long
2021-04-25 21:47:07 +02:00
Nikita Popov
33d7c8d3d8
Escape invalid UTF-8 in strings
...
To be friendlier to tooling that expects PHP files to be UTF-8
encoded, escape any sequences that are not legal under UTF-8.
2021-04-25 21:37:01 +02:00
Nikita Popov
6b409b96bb
Use hex escaping for special characters in strings
...
Apart from \0, using the \xHH notation is more typical.
2021-04-25 21:22:15 +02:00
Tomas Votruba
f68e1a43ff
[PHP 8.1] Add support for enums ( #758 )
...
RFC: https://wiki.php.net/rfc/enumerations
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-04-25 21:11:36 +02:00
Anders Jürisoo
1d1bc8a364
Upgrade some PrettyPrinter methods to protected
...
I noticed some methods in the Standard PrettyPrinter is private, can they be upgraded to `protected` to ease when extending it?
2020-10-17 22:04:40 +02:00
Tomas Votruba
4c22c62783
[PHP 8.0] Add attributes support ( #661 )
...
Adds support for PHP 8 attributes, represented using `AttrGroup` nodes
containing `Attribute` nodes. The `attrGroup` subnode is added to all
nodes that can have attributes.
This is still missing FPPP support.
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-09-13 21:01:17 +02:00
Nikita Popov
f9d35fe11e
Fix casing of class name
2020-08-10 11:21:16 +02:00
Nikita Popov
8bcaa4261e
Add parens for new/instanceof with complex expression
...
This is not fully accurate because the rules for "new variables"
are different than the rules for dereferenceable LHS.
2020-08-09 22:07:33 +02:00
Nikita Popov
feb6bf7a0c
Wrap class const LHS in parens if necessary
...
This looks like a very old bug in the pretty printer that showed
up in PHP 8 tests.
2020-08-09 21:41:30 +02:00
Nikita Popov
a98350581c
Add support for throw expression
2020-08-09 20:52:55 +02:00
Nikita Popov
98f7f39d1c
Add named argument support
...
Not adding any explicit FPPP support, as I don't think add/remove
of names can be handled any better than full reformatting.
2020-08-09 17:37:44 +02:00