Commit Graph

84 Commits

Author SHA1 Message Date
Iskander (Alex) Sharipov
f767b9fd9f ParserAbstract: add missing '*' to the phpdoc
Otherwise, it's somewhat incompatible with the phpdoc definition.
2021-04-25 12:38:52 +02:00
Nikita Popov
d3d1ee470a Fix #738 incorrect start line for traits
Empty productions are supposed to be assigned the start attributes
of the lookahead token. Currently, this happens by assigning above
the current stack position when the token it read.

This fails in a situation where we first reduce an empty production
higher up in the stack, and then again reduce an empty production
lower in the stack, without consuming the lookahead token in the
meantime.

Fix this by moving the assignment into the reduction phase. We
also need to do this for error productions, which are effectively
empty.
2020-12-20 10:52:47 +01:00
Nikita Popov
0cee2088ea Remove self/parent/static restriction for namespace names
This no longer applies as of PHP 8.0.
2020-08-09 21:21:22 +02:00
Máté Kocsis
32f89662f3 Add support for the mixed type 2020-05-28 23:39:04 +02:00
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
664c10121e Add support for union types
We definitely need to introduce a general "Type" abstraction in
the next major version.
2019-11-08 14:45:32 +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
0ef61b49bb add float/double/real KIND support to Cast\Double node 2019-01-05 19:23:00 +01:00
Nikita Popov
eebaa94647 Flexible doc strings: Fix some issues, add more tests 2018-09-22 10:09:00 +02:00
Nikita Popov
0ed9065b4c Flexible doc: Validate and strip indentation
If indentation is invalid, we strip on a best-effort basis.

The error position information is not great, but I don't want to
introduce sub-token error positioning at this point in time.
2018-09-21 21:47:01 +02: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
6121001576 Remove unused ParserAbstract::$errors property
Leftover from before ErrorHandler was introduced.
2018-03-30 21:45:52 +02:00
Nikita Popov
a75164c77e Rename YYNLSTATES to numNonLeafStates 2017-11-12 16:09:00 +01:00
Nikita Popov
c59e75f873 Clear parser state directly after parsing
I don't think this makes any difference in practical scenarios, but
it makes memory usage analysis simpler.
2017-11-11 16:54:52 +01:00
Nikita Popov
4392a7b164 Fix PHP5 static call fixup
Variable nodes directly store the variable name as a string, they
don't use VarLikeIdentifier. So remove this wrapper if it exists.
2017-11-11 12:23:14 +01:00
Nikita Popov
457fe049a8 Ensure nodes have full complement of location info 2017-11-04 18:13:00 +01:00
Nikita Popov
fa12dc8a22 Merge branch '3.x' 2017-08-29 23:15:04 +02:00
Nikita Popov
a10780ca0d Handle Nop statement after brace-style namespace
Fixes #412.
2017-08-29 23:14:27 +02:00
TomasVotruba
e2e99f269b Add strict_types to lib code 2017-08-18 23:00:13 +02:00
Nikita Popov
7b36ca3b6c Add isSpecialClassName() method to Identifier and Name 2017-08-15 22:59:52 +02:00
Nikita Popov
d97cc3d96e Add toLowerString() method to Name and Identifier
Avoids patterns like strtolower((string) $name) when using
strict types.
2017-08-15 22:49:16 +02:00
TomasVotruba
05e6725b7a [cs] use strict comparison where allowed 2017-08-13 21:14:28 +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
46e7fea72d Merge branch '3.x'
Conflicts:
	test/PhpParser/Builder/ParamTest.php
2017-06-28 23:13:33 +02:00
Nikita Popov
4a7d011317 Add support for object type 2017-06-28 23:12:13 +02:00
Nikita Popov
a32e3797d4 Generate PHP 7 type annotations 2017-04-28 21:40:59 +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
8635365a30 Fix some typing issues 2017-04-26 21:50:40 +02:00
Nikita Popov
2beb4e7fd6 Merge branch '3.x'
Conflicts:
	lib/PhpParser/ParserAbstract.php
	test/code/parser/errorHandling/recovery.test
2017-02-26 23:47:27 +01:00
Nikita Popov
d5873b177b Adjust the end attributes on the stack as well 2017-02-26 23:45:14 +01:00
Nikita Popov
da97f78e25 Merge branch '3.x'
Conflicts:
	lib/PhpParser/ParserAbstract.php
	test/code/parser/errorHandling/recovery.test
2017-02-26 23:40:32 +01:00
Nikita Popov
48ec654d0c Make Expr\Error nodes empty
Resolves issue #359.
2017-02-26 23:38:32 +01:00
Matthew Brown
329e90c239 Improve doc comments 2017-02-09 20:49:52 +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
bfea338d36 Update doc comments after previous comment
Make some of the type annotations more accurate, and complete the
generated doc-comments to be complete (with description and
parameter annotations.)
2017-01-26 00:16:54 +01:00
Matthew Brown
e3b87f40aa Add non-void return types 2017-01-25 23:32:50 +01:00
Nikita Popov
13304d5991 Drop attribute poisoning in parser 2017-01-23 01:13:34 +01:00
Matthew Brown
7b441d2142 Fix issues reported by psalm 2017-01-23 01:06:46 +01:00
Nikita Popov
414adfb146 Drop useNopStatements option 2017-01-20 22:29:41 +01:00
Nikita Popov
48d3243abe Drop last vestiges of consistent var mode flag 2017-01-19 23:46:25 +01:00
Nikita Popov
67274b9594 Enforce useConsistentVariableNames 2017-01-19 23:24:43 +01:00
Nikita Popov
ced914a3b7 Update doc comments to be more specific
Now $stmts arrays really only contains Stmt nodes.
2017-01-19 22:49:18 +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
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
c1e0bab4f8 Add support for negative interpolated offsets
A late addition to PHP 7.1 which I missed.
2016-12-11 13:44:17 +01:00