Add a new "indent" option for the pretty printer, which can be
use to control the indentation width, or switch it to use tabs.
Tab width is currenlty hardcoded to 4, but also shouldn't matter
much.
Possibly the formatting-preserving printer should auto-detect
the indentation in the future.
For backwards-compatibility, parse the simple single argument
case into an Exit_ node as previously. For more complex
expressions generate a function call.
Add hooks subnode to Stmt\Property and Param, which contains an
array of PropertyHook.
The property hook support is considered experimental and subject
to change.
RFC: https://wiki.php.net/rfc/property-hooks
By default parser uses newest supported and pretty printer uses
its default version. If version is specified, it's used for both
parser and printer. Additionally, parserVersion can be used to
specify a different version for parser and printer.
We cannot support both this syntax and property hooks. Drop
support for the alternative syntax in the PHP 8 parser. The
PHP 7 parser still supports it.
The precedence table set the LHS and RHS precedence for the
ternary to -1, which is the dummy value used for unary operators.
Instead, it should be the same as the operator precedence, as
the ternary is non-associative since PHP 8.
Fixes#1009.
Don't try to keep backwards-compatibility with the old factory
style, which doesn't map cleanly onto supported options (we only
have ONLY_PHP7/PREFER_PHP7, which should probably create a Php8
parser in terms of how they are used, but this would no longer
match their names).
Instead, I have backported the new createForNewestSupportedVersion()
and createForHostVersion() methods to PHP-Parser 4.
When encountering a null statement (indicating that an error occurred),
retain the preceding statements. These were accidentally dropped
previously.
(cherry picked from commit 54103d838734be0499172026525e38cbf6af2711)
This fixes the long-standing issue where a comment would get assigned
to all nodes with the same starting position, instead of only the
outer-most one.
Fixes#253.
Stmt\Block will be created for { $a; } style blocks, unless these
occur directly inside some structure that is usually combined
with a block.
For example if ($a) { $b; } will continue to use the old
representation (plain array in in If_::$stmts), but a free-standing
{ $b; } will become a Stmt\Block.
Fixes#590.
For doc strings, the rawValue (on either the String_ or
InterpolatedStringPrts) does not include the leading indentation
(which is available as docIndentation) or the trailing newline on
the last part.
Append to a property instead of returning strings. This is
significantly faster when dumping large ASTs.
This also fixes an inconsistency where the indentation level for
strings and comments was off-by-one.
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.
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.