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
1cdb280a30
Merge branch '3.x'
2018-01-25 22:28:08 +01:00
Nikita Popov
d01fafcb40
Handle +(++$x) and -(--$x) as well
2018-01-25 22:27:37 +01:00
Nikita Popov
b85b6b3519
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/PrettyPrinter/Standard.php
2018-01-25 22:18:32 +01:00
Nikita Popov
94c715d97e
Fix pretty printing of -(-$x) and +(+$x)
...
Fixes #459 .
2018-01-25 22:17:35 +01:00
Nikita Popov
4dacbb8d39
FPPP: Fix indentation on list insertion
...
Use indentation of last list element, instead of indentation
before the insertion point.
Fixes #466 .
2018-01-25 22:08:40 +01:00
Nikita Popov
92b39e3d1f
Fix nNextFreeElement for arrays with trailing comma
...
Ugh.
2017-12-26 21:17:36 +01:00
Nikita Popov
1c7fd314d1
FPPP: Add heuristic for multi-line lists
2017-12-26 21:14:36 +01:00
Nikita Popov
8d3cb5f57b
FPPP: Fallback if we must insert a block
2017-12-26 15:41:38 +01:00
Nikita Popov
de82a40d04
FPPP: Add broken InlineHTML test cases
2017-12-26 15:08:30 +01:00
Nikita Popov
a86151f24f
FPPP: Fix fallback for inline HTML
2017-12-26 15:08:29 +01:00
Nikita Popov
4fcdac40d1
FPPP: Fix insertion of multiple elems at start
2017-12-02 15:10:15 +01:00
Nikita Popov
04feb90d79
Rename abc1.test to basic.test
...
And split off fixup.test.
2017-12-01 23:15:50 +01:00
Nikita Popov
dc3ace55c3
FPPP: Support insert at start of list node ( #446 )
2017-12-01 22:09:51 +01:00
Nikita Popov
e5453f0d46
Extract pSingleQuotedString as an extension point
...
And add some more string formatting tests.
2017-12-01 18:31:21 +01:00
Nikita Popov
336a49b428
FPPP: Fix comment indentation ( #443 )
2017-11-13 13:27:27 +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
6a2e1ae440
FPPP: Graceful handling of comment changes
2017-11-04 17:56:11 +01:00
Nikita Popov
56bc8ebb9b
FPPP: Add support for removal from list nodes
2017-11-04 17:23:17 +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
5900d78cc9
FPPP: Support anonymous classes ( #432 )
...
This is a huge hack... We temporarily create a new node with the
correct structure and use that for printing.
I think it would be better to always use a separate node type for
NewAnonClass, rather than using a combination of New and Class,
but this would require some larger changes, as this node type would
have to be both Expr and ClassLike, which is not possible right now,
as the latter is a class rather than an interface...
2017-10-29 12:26:12 +01:00
Nikita Popov
776275361a
FPPP: Support modifier changes ( #428 )
...
I decided against introducing a node type for this. In the end it
would require special handling anyway.
2017-10-25 22:27:29 +02:00
Nikita Popov
f5de7f9894
FPPP: Check that nodes are nodes in pArray()
2017-10-18 15:42:01 +02:00
Nikita Popov
bbec051e51
FPPP: Consolidate indentation levels
...
A bit annoying that we have to keep $this->nl always synchronized.
2017-10-06 18:21:08 +02:00
Nikita Popov
f071b66013
Print comments of inserted statements
2017-10-06 17:58:56 +02:00
Nikita Popov
bb2ac91115
Move leading space out of pStmt_Else
...
Same as previous commit. Also add support for pStmt_If->else
insertion.
2017-10-06 14:56:59 +02:00
Nikita Popov
310155832a
FPPP: Support insertion into list subnodes
...
With some rough edges...
2017-10-06 14:43:41 +02:00
Nikita Popov
ed8a744cd5
FPPP: Switch pArray() to use node list diffing
2017-10-06 12:02:00 +02:00
Nikita Popov
f6cc85a796
FPPP: Fall back if comment in list node changes ( #420 )
2017-10-02 21:18:13 +02: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
ec8692fb9e
Fix InlineHTML indentation
2017-09-03 19:02:07 +02: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
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
4fea054ee0
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Parser/Php7.php
2017-06-28 23:06:38 +02:00
Nikita Popov
7f862ac21c
Add support for trailing comma in group use
2017-06-28 23:05:28 +02:00
Nikita Popov
3da189769c
Distinguish between implicit/explicit alias
...
The UseUse::$alias node can now be null if an alias is not
explicitly given. As such "use Foo\Bar" and "use Foo\Bar as Bar"
are now represented differently.
The UseUse->getAlias() method replicates the previous semantics,
by returning "Bar" in both cases.
2017-04-28 21:05:01 +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
bc75ac2990
Merge branch '3.x'
2017-04-09 19:51:18 +02:00
Nikita Popov
c3cbf07946
Pretty printer: Preserve comments in arrays and calls
...
If call arguments or array contains comments, print it in multiline
form, so that comments may be preserved.
2017-04-09 19:49:47 +02:00
Nikita Popov
1ec5591574
Tweak node insertion formatting
2017-04-08 23:11:46 +02:00
Tyson Andre
b5935a4aff
Fix a typo in NodeDumper for REQUIRE_ONCE ( #367 )
2017-03-17 11:35:48 +01: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
Nikita Popov
f291a19fd5
Merge branch '3.x'
...
Conflicts:
lib/PhpParser/Parser/Php7.php
2017-02-26 23:13:21 +01:00
Nikita Popov
c12a4c8239
Fix start attribute assignment for Error in ClassConstFetch
2017-02-26 23:00:38 +01: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
a8eb2fc675
Support recovery from invalid trailing commas
2017-02-09 00:35:12 +01:00
Nikita Popov
865bfb2acf
Merge branch '3.x'
...
Conflicts:
grammar/php7.y
lib/PhpParser/Parser/Php7.php
test/code/parser/expr/uvs/globalNonSimpleVarError.test
test/code/parser/stmt/namespace/groupUseErrors.test
2017-02-05 17:50:54 +01:00
Nikita Popov
62877b5d14
Recover from missing semicolons on statements
2017-02-05 17:47:56 +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
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
67274b9594
Enforce useConsistentVariableNames
2017-01-19 23:24:43 +01:00
Nikita Popov
33552764ad
Perform manual test updates
2017-01-19 22:31:29 +01:00
Nikita Popov
953f8c9631
Perform automated test update
2017-01-19 22:25:22 +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
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
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
27281e9130
Fix attribute assignment for Error nodes
2016-11-23 22:51:32 +01:00
Nikita Popov
098294beec
Support !!positions parser test mode
...
And use it for the group use prefix position test that was
previously implemented as a separate test.
2016-11-23 22:36:48 +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
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
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
c5e0c3d7e2
Catch lexer errors in throwOnError=0 mode
2016-09-30 13:49:34 +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
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
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
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
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