Nikita Popov
fd7ac25108
Throw if pretty-printing Error node
2017-01-29 21:56: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
70f86cb6cb
Update NodeVisitor doc comments
2017-01-25 23:28:44 +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
cb5dd28985
Don't include whitespace directly in catch/finally print
2017-01-21 21:25:48 +01:00
Nikita Popov
5e565e8046
Support insertion of nullable nodes
...
Still incomplete in some places and the formatting is not always
ideal.
2017-01-21 21:20:42 +01:00
Nikita Popov
b9b6aeeed9
Support format-preserving node removal
...
Take care of stripping surrouding tokens appropriately.
2017-01-21 17:52:50 +01:00
Nikita Popov
0607450f78
Add FinderVisitor
...
Allows finding nodes based on a filter callback.
2017-01-21 15:41:24 +01:00
Nikita Popov
aea3a9efe4
Add @property annotations for namespacedName
2017-01-20 23:45:54 +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
d7f3c4f9d3
Renamve Param::$name to Param::$var
...
As it now contains a Variable node.
2017-01-19 23:39:15 +01:00
Nikita Popov
a79306ccd9
Rename StaticVar::$name to $var
...
As it now holds a Variable
2017-01-19 23:35:31 +01:00
Nikita Popov
6238f5f9f9
Adjust code for constitent var mode
2017-01-19 23:32:49 +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
7623d20f69
Automatically wrap in Stmt\Expression in builders
2017-01-19 22:39:21 +01:00
Nikita Popov
1bfbd7bcc8
Make useExpressionStatement only supported mode
2017-01-19 21:15:26 +01:00
Nikita Popov
065c720c28
Merge branch 'formatPreservingPrint'
2017-01-19 21:06:32 +01:00
Nikita Popov
0c9c8d58ab
Drop deprecated $type subnodes
...
These have been replaced by $flags in 3.0
2017-01-19 21:00:44 +01:00
Nikita Popov
3b4dd387b8
Comment out code for handling new keywords
2017-01-19 20:58:45 +01:00
Nikita Popov
61574a1818
Drop support for PHP 5.5
2017-01-19 20:55:08 +01:00
algo13
ba57202ed7
Fixed method name casing ( #336 )
...
Make it match the parent class.
2017-01-14 12:01:25 +01:00
Nikita Popov
f21309f52f
Add NameResolver mode that does not modify nodes
2016-12-26 21:45:33 +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
Felix Becker
3e8c8d248d
Add originalName attribute in NameResolver
...
For now gated behind a preserveOriginalNames option.
2016-12-22 20:25:02 +01:00
Nikita Popov
58970e2a37
Improve LNumber/DNumber pretty printing
...
* Support PHP_INT_MIN
* Support negative binary/octal/hex numbers
* Support INF/-INF/NAN in namespaces
2016-12-11 16:31:59 +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
Nikita Popov
70319e27ee
Parse 0 in "$a[0]" as LNumber ( #325 )
2016-12-07 20:24:00 +01:00
Nikita Popov
5219f75719
Fix pretty-printing of nullable types
2016-12-06 12:26:21 +01:00
Ondrej Mirtes
a485ecd7ba
NameResolver - resolve Name in NullableType
2016-12-06 12:21:30 +01:00
Matthew Brown
030de805e1
Add NullableType to types of properties/args that offer it ( #323 )
2016-12-05 13:30:29 +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
bcdfb703d5
Cleanup imports
...
Thanks PhpStorm :)
2016-11-23 22:58:18 +01:00
Nikita Popov
27281e9130
Fix attribute assignment for Error nodes
2016-11-23 22:51:32 +01:00
Nikita Popov
b02f8ac07d
Add support for dumping positions in NodeDumper
2016-11-23 22:25:17 +01:00
Nikita Popov
e52ffc4447
Support recovery from Foo::
2016-11-22 19:47:04 +01:00
Nikita Popov
c5cdd5ad73
Support recovery from free-standing $
2016-11-21 17:01:39 +01:00
Nikita Popov
c0630f8169
Support recovery for new without class name
2016-11-21 16:51:53 +01:00
Nikita Popov
c0f0edf044
Mark Name::$parts as deprecated
2016-10-22 17:05:00 +02:00
Nikita Popov
fa7357b483
Represent empty Name::slice() using null
...
Instead of a Name([]) dummy value, that is invalid in other
contexts.
2016-10-22 17:02:38 +02:00
Nikita Popov
91cb82d3d2
Explicitly support Name copy construction
...
It already worked beforehand by accident ... make clear it's
actually supported.
2016-10-22 16:41:58 +02:00
Nikita Popov
7672b974ff
Remove Name::append() and Name::prepend()
2016-10-22 00:25:15 +02:00
Nikita Popov
0d0accfa9f
Add setDocComment() to Node interface
...
Previously it was only part of NodeAbstract.
2016-10-21 23:26:51 +02:00
Matthew Brown
623bad2c8b
Type encapsulated string parts specifically
2016-10-21 11:46:54 +02:00
Matthew Brown
f66cf8f0dd
$name can be null for PHP 7 anonymous classes
2016-10-21 11:46:14 +02:00
Nikita Popov
a46b309975
Move constants into NodeTraverser class
...
Not that the interface makes much sense anyway, but these are
implementation details of a specific traverser.
2016-10-16 22:13:09 +02:00
Nikita Popov
f99a96e0a2
Introduce ErrorHandler
...
Add ErrorHandler interface, as well as ErrorHandler\Throwing
and ErrorHandler\Collecting. The error handler is passed to
Parser::parse(). This supersedes the throwOnError option.
NameResolver now accepts an ErrorHandler in the ctor.
2016-10-16 22:12:46 +02:00
Nikita Popov
90834bff8e
Add namespacedName attribute on runtime-resolved names
...
The NameResolver now adds a namespacedName attribute on function/
const names which cannot be statically resolved.
2016-10-11 19:44:22 +02:00
Nikita Popov
a910f6a247
Remove $separator arg from Name::toString()
2016-10-09 12:45:15 +02: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
5e5cb86e83
Remove support for node cloning in traverser
2016-10-09 00:41:55 +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
b2fe43cf7a
Next try...
2016-09-30 21:06:48 +02:00
Nikita Popov
648a246be0
Next try to fix HHVM build
2016-09-30 20:57:21 +02:00
Nikita Popov
5025d75160
Try to fix HHVM build
2016-09-30 20:33:56 +02:00
Nikita Popov
c79ea6d1d3
Support recovery from lexer errors
...
Lexer::startLexing() no longer throws, instead errors can be fetched
using Lexer::getErrors().
Lexer errors now also contain full line and position information.
2016-09-30 20:23:36 +02:00
Nikita Popov
e926efd62e
Fix regex
2016-09-30 19:17:10 +02:00
Nikita Popov
17d1e738fa
Don't use ~__EMU sequences in emulative lexer
...
These were necessary back in the day when we had to emulate some
complex functionality such as nowdoc strings. Now we can simply
directly translate certain token sequences.
The motivation for this change is to avoid preprocessing of the source
code, which would complicate offset-aware error handling inside the
lexer as offsets would no longer be correct.
2016-09-30 19:10:16 +02:00
Nikita Popov
9e5d3bbe25
Remove Error::(get|set)RawLine()
...
These have been superseded by Error::(get|set)StartLine().
2016-09-30 18:30:01 +02:00
Nikita Popov
f3c7dc9d89
Add Error::getMessageWithColumnInfo()
2016-09-30 18:24:43 +02:00
Nikita Popov
c5e0c3d7e2
Catch lexer errors in throwOnError=0 mode
2016-09-30 13:49:34 +02:00
Nikita Popov
ea47b6e0d6
Add NodeAbstract::setDocComment()
2016-09-17 20:51:22 +02:00
Nikita Popov
1ab24d26ee
Add support for PHP 7.1 types to builders
...
This adds support for void, iterable and nullable types.
2016-09-16 13:53:13 +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
d0cfb98133
Merge branch '2.x'
...
Conflicts:
lib/PhpParser/Parser/Php7.php
2016-08-30 22:14:09 +02:00
Nikita Popov
13f7321def
Forbid "=& new" in PHP 7 mode
2016-08-30 22:12:01 +02:00
Nikita Popov
7dae6c7a6b
Implement JsonSerializable for Nodes and Comments
...
Exposes the properties and adds an additional nodeType property.
2016-07-25 20:59:09 +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
ec614c95dd
Add hasLeadingNewline attribute to InlineHTML
...
Use this attribute to not print an extra newline if the original
code did not have it.
2016-07-25 16:44:25 +02:00
Nikita Popov
b740076ab1
Remove deprecated Name::set*() methods
2016-07-25 14:50:37 +02:00
Nikita Popov
c9fea2ef67
Extend Name::slice() to support negative length+offset
2016-07-25 14:47:24 +02:00
Nikita Popov
818ef2e692
Make PrettyPrinter\Standard methods protected
...
I'm not sure how these ever ended up being public.
2016-07-25 14:27:03 +02:00
Nikita Popov
5f97b12576
Introduce explicit Finally node
2016-07-25 14:25:04 +02:00
Nikita Popov
1dea9111a2
NodeDumper: Resolve type for include/use as well
2016-07-25 14:04:04 +02:00
Nikita Popov
174e6c3cab
NodeDumper: Print modifiers as strings
2016-07-25 13:53:49 +02:00
Nikita Popov
18129480ae
Rename $type subnode to $flags
...
Type makes it sound like a type-hint, and on a number of other nodes
$type is used for exactly that. Use $flags to hold modifiers instead.
2016-07-25 13:33:19 +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
7ff12b8fcb
Remove deprecated Comment methods
2016-07-09 22:00:39 +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
437890d386
PHP 7: Short destructuring syntax
...
Potentially the pretty printer should force use of [] in assignment
context, instead of relying on the existance of the right attribute.
2016-07-06 23:43:23 +02:00
Nikita Popov
1edf72c040
PHP 7: Support nullable types
...
Using a new NullableType node.
2016-07-06 18:36:18 +02:00
Nikita Popov
7a54aca468
Merge branch '2.x'
2016-07-06 02:21:57 +02:00
Nikita Popov
81f7da3b23
Fix computation of expected tokens in parse errors
2016-07-06 02:21:48 +02:00
Nikita Popov
5ea2a76d80
PHP 7.1: Class constant visibility support
2016-07-05 23:01:06 +02:00
Nikita Popov
5044fce1ff
PHP 7.1: Add void+iterable support
...
In PHP 7 mode, these will now be represented as strings 'void'
and 'iterable'.
2016-07-05 22:35:27 +02:00