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.
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.
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.
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.
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.
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)
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.
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.
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.
By making flags on the Param builder configurable by providing make(Public|Protected|Private) methods we can promote parameters to properties from the constructor
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.