1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-27 04:14:44 +01:00
Commit Graph

70 Commits

Author SHA1 Message Date
Nikita Popov
46cbd9393a Place Nop nodes more precisely
If the Nop is created to collect comments, place it directly after
the comment, instead of at the next non-whitespace character.
2020-02-09 17:10:33 +01:00
Nikita Popov
60d025a914 Fix attributes for zero-length nop nodes
Previously zero-length nop nodes used the lookahead start attributes
and current end attributes. This choice ends up being somewhat weird,
because the end attributes will be the at the last non-whitespace,
non-comment token, which might be quite far back. More problematically,
we may not have encountered any non-discarded token if we're at the
start of the file, in which case we will have no end attributes to
assign.

Change things to use a canonical "zero-length" node representation,
where the end position (token & file) will be exactly one before the
start position.

Fixes #589.
2019-05-11 20:01:25 +02:00
Tomas Votruba
8012faea54 [PHP 7.4] Add array spread 2019-05-09 19:15:35 +02:00
Tomáš Votruba
f3b19c19ef [PHP 7.4] Add support for arrow functions (#602)
Per RFC https://wiki.php.net/rfc/arrow_functions_v2.
2019-05-09 14:17:28 +02:00
Tomas Votruba
9de96821f7 Add support for ??= operator
Introduced in PHP 5.4, represented using an AssignOp\Coalesce node.
2019-02-09 11:16:26 +01:00
Tomas Votruba
0ef61b49bb add float/double/real KIND support to Cast\Double node 2019-01-05 19:23:00 +01:00
Nikita Popov
5f73c4de80 Flexible doc: Validate end label indentation
Move doc string parsing logic from rebuildParsers.php and
String_::parseDocString() into ParserAbstract. This stuff is
going to get complicated now.

For now only implement the validation of the indentation on the
end label.
2018-09-21 16:31:17 +02:00
Nikita Popov
8b1c9c0409 Store comment at end of class in Nop statement
Fixed #509.
2018-07-07 12:49:49 +02:00
Nikita Popov
ad9c42b66a Merge branch '3.x'
Conflicts:
	lib/PhpParser/Parser/Php5.php
	lib/PhpParser/Parser/Php7.php
2018-01-30 23:07:11 +01:00
Nikita Popov
08215e7646 Fix duplicate switch comment assignment
Fixes #469.
2018-01-30 23:06:20 +01:00
Nikita Popov
a75164c77e Rename YYNLSTATES to numNonLeafStates 2017-11-12 16:09:00 +01:00
Nikita Popov
b241a121a3 Fix trait alias to semi-reserved name parsing
This was missing the explicit construction of an Identifier node.
2017-10-29 14:15:48 +01:00
Nikita Popov
cc600b67f6 Merge branch '3.x'
Conflicts:
	lib/PhpParser/Parser/Php5.php
	lib/PhpParser/Parser/Php7.php
2017-10-01 16:55:54 +02:00
Nikita Popov
d418bf3951 Preserve comments on empty blocks (#382) 2017-10-01 16:54:43 +02:00
Nikita Popov
5cfdc2e0a7 Merge branch '3.x'
Conflicts:
	lib/PhpParser/Parser/Php5.php
	lib/PhpParser/Parser/Php7.php
	test/PhpParser/ParserTest.php
2017-09-26 18:46:44 +02:00
Nikita Popov
5a9fbca54a Add attribute for namespace kinds (#417)
One of KIND_SEMICOLON or KIND_BRACED.
2017-09-26 18:45:05 +02:00
TomasVotruba
e2e99f269b Add strict_types to lib code 2017-08-18 23:00:13 +02:00
TomasVotruba
ec535ea14e [cs] use PHP 5.4 short array, since PHP 7.0 is min version 2017-08-13 21:14:28 +02:00
Nikita Popov
a6846e3b71 Always use Identifier nodes
The parser will now always generate Identifier nodes (for
non-namespaced identifiers). This obsoletes the useIdentifierNodes
parser option.

Node constructors still accepts strings and will implicitly create
an Identifier wrapper. Identifier implement __toString(), so that
outside of strict-mode many things continue to work without changes.
2017-04-28 20:57:32 +02:00
Nikita Popov
9f5ec5a69a Merge branch '3.x'
Conflicts:
	lib/PhpParser/Parser/Php5.php
	lib/PhpParser/Parser/Php7.php
	test/code/parser/stmt/class/name.test
2017-02-09 20:38:33 +01:00
Nikita Popov
df98b0417b Handle "extends static" etc more gracefully
Use class_name production and emit the same error as for
"extends self" and "extends parent". It's weird that "extends
static" gives a different result than those two.
2017-02-09 18:43:09 +01:00
Nikita Popov
8f623fb241 Use closures instead of methods for semantic actions
The dispatch using $this->{'reduceRule' . $rule}() is very expensive
because it involves
 * One allocation when converting $rule to a string
 * Another allocation when concatenating the two strings
 * Lowercasing during the method call
 * Various uncached method checks, e.g. visibility.

Using an array of closures for semantic action dispatch is
significantly more efficient.
2017-02-05 11:58:45 +01:00
Nikita Popov
3bbf8d8f7a Use local var for $stackPos
We're accessing $this->stackPos a lot, and property accesses are
much more expensive than local variable acesses. Its cheaper to
use a local var and pass it as an argument to semantic actions.
2017-02-05 11:57:21 +01:00
Nikita Popov
414adfb146 Drop useNopStatements option 2017-01-20 22:29:41 +01:00
Nikita Popov
b5fb6f2d0a Don't require useNopStatements=false for format preservation
Instead assign attributes on Nop nodes and in the pretty printer
specially handle end<start offsets. It's a somewhat weird case,
but not wrong per se given the meaning the offsets have.
2017-01-20 22:27:51 +01:00
Nikita Popov
48d3243abe Drop last vestiges of consistent var mode flag 2017-01-19 23:46:25 +01:00
Nikita Popov
1bfbd7bcc8 Make useExpressionStatement only supported mode 2017-01-19 21:15:26 +01:00
Nikita Popov
4d2a4d02b0 Add first shot at format preserving pretty printer 2016-12-26 18:28:49 +01:00
Nikita Popov
9b2d35d1ac Add expression statement mode 2016-12-24 23:54:24 +01:00
Nikita Popov
0f582e1708 Add VarLikeIdentifier
For representing Identifiers that have an implicit leading $.

With this done, maybe go one step further?
 * Rename VarLikeIdentifier -> VarIdentifier / VarName
 * Use VarIdentifier / VarName also as an inner node in Variable.
   Not sure if this adds any real value.
2016-12-23 12:39:27 +01:00
Nikita Popov
d32d937d47 Use Identifier for property names as well 2016-12-23 00:25:45 +01:00
Nikita Popov
f46c909b5a Represent prop in static prop fetch using Identifier 2016-12-23 00:22:30 +01:00
Nikita Popov
a947e731c3 Add useConsistentVariableNodes mode
The parameter case is a bit weird, because the subnode is called
"name" here, rather than "var". Nothing we can do about that in
this version though.

The two parser options might be merged. I've kept it separate,
because I think this variable representation should become the
default (or even only representation) in the future, while I'm
less sure about the Identifier thing.
2016-12-23 00:10:59 +01:00
Nikita Popov
122f449960 Represent builtin types using Identifier as well 2016-12-22 22:23:30 +01:00
Nikita Popov
6bcc6c31dd Add useIdentifierNodes mode to parser
In this mode non-namespaced names that are currently represented
using strings will be represented using Identifier nodes instead.
Identifier nodes have a string $name subnode and coerce to string.

This allows preserving attributes and in particular location
information on identifiers.
2016-12-22 21:15:44 +01:00
Nikita Popov
70319e27ee Parse 0 in "$a[0]" as LNumber (#325) 2016-12-07 20:24:00 +01:00
Nikita Popov
3e158a2313 Wrap List_ in ArrayItem
This was correctly done for the 'key'=>list() form, but not for
unkeyed nested lists.
2016-12-01 13:32:37 +01:00
Nikita Popov
caa5c0cc76 Graceful handling for "special" errors
Nearly all special errors are now handled gracefully, i.e. the
parser will be able to continue after encountering them. In some
cases the associated error range has been improved using the new
end attribute stack.

To achieve this the error handling code has been moved out of the
node constructors and into special methods in the parser.
2016-10-09 12:38:18 +02:00
Nikita Popov
2be7838fc6 Correctly assign attrs for encaps vars 2016-10-08 23:58:39 +02:00
Nikita Popov
f6eb341b15 Fix GroupUse prefix attribute assignment 2016-10-08 23:55:46 +02:00
Nikita Popov
a7120116b0 Merge branch '2.x' 2016-08-30 22:38:34 +02:00
Nikita Popov
83f34e7fa4 Retain comments on blocks on first inner statement 2016-08-30 22:37:51 +02:00
Nikita Popov
977cbab8e7 Decrement errorState when recovering from -> error
It's likely that an error after -> will trigger another one due to
missing semicolon without shifting a single token. We prevent an
immediate failure in this case by manually setting errorState to 2,
which will suppress the duplicate error message, but allow error
recovery.
2016-07-25 17:37:54 +02:00
Nikita Popov
09086fbe0a Support partial parsing of $foo->
Introduce Error node for this purpose.
2016-07-25 17:03:58 +02:00
Nikita Popov
5f97b12576 Introduce explicit Finally node 2016-07-25 14:25:04 +02:00
Nikita Popov
867ae5148d Bring Trait constructor in line with Class/interface 2016-07-22 17:01:51 +02:00
Nikita Popov
537b59d4d1 PHP 7.1: Support multi-catch
Catch::$type is now an array Catch::$types.
2016-07-22 15:40:00 +02:00
Nikita Popov
574665b45b PHP 7.1: list() with keys
Expr\List will now contain ArrayItems instead of plain variables.
I'm reusing ArrayItem, because code handling list() must also handle
arrays, and this allows both to go through the same code path.

This also renames Expr\List->vars to ->items.

TODO: Should Expr\List be dropped in favor of Expr\Array with an
extra flag?
2016-07-09 21:55:55 +02:00
Nikita Popov
5ea2a76d80 PHP 7.1: Class constant visibility support 2016-07-05 23:01:06 +02:00
Nikita Popov
96cbd48df6 Improve error recovery quality
In particular, support recovering from a missing trailing semicolon,
while keeping the rest of the expression.
2016-04-20 16:47:50 +02:00