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

99 Commits

Author SHA1 Message Date
Nikita Popov
3b7d8e8b5d Enable basic error recovery
Adding only a single recovery rule for now.

The API is now:
 * throwOnError parser option must be disabled.
 * List of Errors is available through $parser->getErrors(). This
   method is available either way.
 * If no recovery is possible $parser->parse() will return null.
   (Obviously only if throwOnError is disabled).
2015-04-30 17:41:57 +02:00
Nikita Popov
a35c2a2067 Add column info to EOF errors
EOF errors are now located one past the end of the file.
2015-04-27 15:37:41 +02:00
Nikita Popov
55b2ead967 Make special class name checks case insensitive 2015-04-26 23:13:27 +02:00
Nikita Popov
e1a0ec3724 Add support for anonymous classes
Has not landed upstream yet, but syntax is unlikely to change.
2015-04-26 23:04:31 +02:00
Nikita Popov
66896dbde6 Poison attribute initializations in parser
Those should error if they end up being used.
2015-04-26 22:32:18 +02:00
Nikita Popov
338bc1f8e7 Fix "print" pretty-printing
Precedence was previously ignored.
2015-04-26 11:56:04 +02:00
Nikita Popov
ab80054e97 Add support for "yield from" 2015-04-26 11:56:02 +02:00
Nikita Popov
a6d2cd69f8 Clarify attribute assignment code
* Don't assign to attribute stack on reduce - why was that there
in the first place?
* Assign attributes to the position in the stack where the first
token of the production is, instead of one position earlier.
* Add a comment to clarify why we also assign attributes on read,
instead of just on shift.
2015-04-26 11:56:01 +02:00
Nikita Popov
6996db1e3a Build node attributes inside semantic action methods
Minor performance improvement for parsing, also allows to access
attributes with higher granulity in the parser, though this is not
currently done.

* #n can now be used to access the stack position of a token. $n
  is the same as $this->semStack[#n]. (Post-translate $n will
  actually be the stack position.)
* $attributeStack is now $this->startAttributeStack and
  $endAttributes is now $this->endAttributes.
* Attributes for a node are now computed inside the individual
  reduction methods, instead of being passed as a parameter.
  Accessible through the attributes() macro.
2015-04-26 11:55:59 +02:00
Nikita Popov
7a40498cb4 Regenerate parser
Also drop the error() parser macro.
2015-04-19 18:12:56 +02:00
Nikita Popov
65f1adbe65 Merge primary error recovery code
The grammar does not yet actually implement error recovery.
2015-04-19 18:11:05 +02:00
Nikita Popov
c8454271e1 Make column info 1-based 2015-04-18 21:20:45 +02:00
Nikita Popov
62f83a0dc2 Add column info for non-syntax errors where relatively precise
Should it also be added if only rough information is available? E.g.
spanning an entire class?
2015-04-18 13:27:58 +02:00
Nikita Popov
611fa5c7f1 Test parser position information (syntax errors) 2015-04-18 13:27:57 +02:00
Nikita Popov
4defbc2174 Make Error column info attribute based 2015-04-18 12:51:26 +02:00
Gerrit Addiks
33a39fae06 added column-numbers to syntax errors 2015-04-18 10:14:49 +02:00
Nikita Popov
e4eab9ec0c Simplify code
The new class couldn't already exist at that point - if it did, the
old name would have been aliased already and the autoloader wouldn't
trigger.
2015-04-03 22:30:30 +02:00
Nikita Popov
6aaa87f143 Fix PHP 7 alias registration
This fixes the case where the old name is used before the new one
is ever used, e.g. when manually constructing nodes, as opposed to
parsing them.

The previous approach would try to register the alias from OLD to
NEW. This would trigger autoloading on NEW and afterwards it would
register the alias from OLD to NEW. Afterwards the alias registration
which originally triggered the autoload would run, thus redeclaring
the class.

TL;DR aliases suck, closes #192.
2015-04-03 22:22:39 +02:00
Markus Malkusch
8d18848fb0 Don't set unserialize_callback_func in Autoloader::register() as it has side effects even when the library is not used 2015-04-03 16:25:33 +02:00
Nikita Popov
805078e0a9 Add missing type hints 2015-03-28 18:14:24 +01:00
Nikita Popov
52dafafd10 Resolve param type hints earlier
For convenience of concurrent visitors that want to perform
enterNode actions based on Stmt\Function_ etc.

Fixes #188.
2015-03-25 20:57:39 +01:00
Nikita Popov
617bf0aa41 Fix registering of PHP 7 aliases
The previous approach was causing issues, because "instanceof"
does not invoke the autoloader.
2015-03-24 20:04:50 +01:00
Nikita Popov
dce19b074b Strict type compliance
Were this library to be fully annotated with scalar types and
return types where possible and were strict types to be enabled
for all files, the test suite would now pass.
2015-03-24 11:19:17 +01:00
Nikita Popov
cea0c4a9d6 Don't register aliases on PHP 7 2015-03-22 16:03:57 +01:00
Matthieu Napoli
729c7bde0c #184 Add a flag to NodeTraverser to avoid cloning nodes 2015-03-22 11:19:04 +13:00
Nikita Popov
8982315b4e Rename Cast\Object as well
As it will very likely be soft-reserved in PHP 7.

Old alias is still available, as usual.
2015-03-21 18:57:55 +01:00
Nikita Popov
0f556c16f5 Fix a few more Scalar\String_ occurances
Totally forgot that the parser uses macros...
2015-03-21 18:54:52 +01:00
Nikita Popov
7ec277e1e1 Replace another Scalar\String occurance
Also canonicalize NameResover tests to avoid those pesky CRLF
issues.
2015-03-21 18:47:20 +01:00
Nikita Popov
1a627872f0 Rename nodes for compat with PHP 7
The old names will still be available on PHP 5.x.
2015-03-20 21:49:38 +01:00
Nikita Popov
592836c4dc Add support for T_HASHBANG (HHVM) 2015-03-14 19:53:08 +01:00
Andreas Lutro
d225555830 Ensure compatibility with multiple autoloaders
Running a .phar or regular PHP executable that requires and includes its own
version of php-parser will cause a "cannot redeclare class" error if said
executable also includes the autoloader of the current working directory.
2015-03-13 23:54:32 +01:00
Nikita Popov
251e689283 Add support for spaceship operator (<=>) [PHP 7]
Added as Expr\BinaryOp\Spaceship.
2015-03-12 23:13:31 +01:00
Nikita Popov
01f4be6b4d Add support for null coalesce operator (??) [PHP 7]
Added as Expr\BinaryOp\Coalesce.
2015-03-12 22:45:56 +01:00
Nikita Popov
dc28449d81 Drop whitespace after ... varargs collection
Also drop an obsolete pretty printer test.
2015-03-12 22:19:34 +01:00
Nikita Popov
3ad0d4b310 Add support for return type declarations [PHP 7]
This adds an additional "returnType" subnode to Stmt\Function_,
Stmt\ClassMethod and Expr\Closure, as well as the corresponding
support in the name resolver and pretty printer.
2015-03-12 22:16:12 +01:00
Nikita Popov
0c34706799 Add "use" builder 2015-03-10 16:05:55 +01:00
Nikita Popov
f9fc2fc9ee Add support for global namespace in NS builder
NULL argument can now be used to create a global namespace {} block.
2015-03-10 15:28:19 +01:00
Nikita Popov
a2d7e8977a Use real properties for storing subnodes
Instead of storing subnodes in a subNodes dictionary, they are
now stored as simple properties. This requires declarating the
properties, assigning them in the constructor, overriding
the getSubNodeNames() method and passing NULL to the first argument
of the NodeAbstract constructor.

[Deprecated: It's still possible to use the old mode of operation
for custom nodes by passing an array of subnodes to the constructor.]

The only behavior difference this should cause is that getSubNodeNames()
will always return the original subnode names and skip any additional
properties that were dynamically added. E.g. this means that the
"namespacedName" node added by the NameResolver visitor is not treated
as a subnode, but as a dynamic property instead.

This change improves performance and memory usage.
2015-03-09 08:54:20 +01:00
Thomas Ruiz
73cace360d Implicit public should not generate as explicit public 2015-03-08 20:21:01 +01:00
Markus Staab
ce5c76d79b prevent a unnecessary concat
analog to b7ffdbbb92
2015-02-13 16:02:54 +01:00
Nikita Popov
b7ffdbbb92 Optimize node dumper
For very deeply nested node trees this extra concatenation makes a
huge difference...
2015-02-13 15:20:25 +01:00
Tom Rochette
1366e833a1 Move getMethods() to new ClassLike node
Class_, Interface_ and Trait_ extend the ClassLike node, which
provides the getMethods() method.
2015-01-31 22:59:38 +01:00
Nikita Popov
a710f32a6a Make Node\Expr\BinOp an abstract class
Only the children should be used ...
2015-01-18 00:10:02 +01:00
Nikita Popov
4071c4645d Add NodeTraverser::DONT_TRAVERSE_CHILDREN support 2015-01-11 22:13:58 +01:00
Nikita Popov
4cd2b95a23 Fix 5.3 build and some small cleanups 2014-12-19 18:54:56 +01:00
Nikita Popov
7ab88416ac Enforce Name|string for names in builders
While array (with name components) could technically be allowed (as
they are supported by the Name node itself), more likely than not
an array would due to incorrect usage of the API (e.g. array instead
of variadics).
2014-12-19 18:50:16 +01:00
Nikita Popov
ba625063e7 Support fully-qualified and ns-relative names in builders 2014-12-19 18:48:21 +01:00
Stepan Anchugov
01643e06d3 Add namespace builder 2014-12-19 18:19:33 +01:00
Nikita Popov
4387454fe0 Add trait builder (for completeness...) 2014-12-19 17:59:23 +01:00
Nikita Popov
55fdbc6dbc Extract common builder methods to abstract classes
Declaration for fns/classes in general and FunctionLike for
functions/methods in particular.
2014-12-19 17:47:51 +01:00