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

584 Commits

Author SHA1 Message Date
Nikita Popov
57bc42517b Move IdentifierTest where it belongs
Ooops...
2017-10-06 15:07:35 +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
69aec6fb5b Add implementation of Myers differ
Intended to be used in the format-preserving pretty printer for
handling changes in node lists.
2017-10-05 21:53:45 +02:00
Nikita Popov
65de924493 Add Identifier::toString()
For symmetry with the Name API.

Also add some missing unit tests.
2017-10-03 20:57:48 +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
4b1d9667af Add constant expression evaluator (#402) 2017-09-30 18:56:44 +02:00
Nikita Popov
cc328a4c9c Add get{Start,End}{Line,TokenPos,FilePos}() methods 2017-09-29 17:34:15 +02:00
Nikita Popov
3d4621bbea Don't return by ref from getAttribute()
This is not worth the few times where it might be useful.
2017-09-29 17:14:27 +02:00
Nikita Popov
d8f9173390 Add Node::getComments() method 2017-09-29 17:09:16 +02:00
Nikita Popov
df334eacaa Add back commented test
We're not testing HHVM anymore, and I've already fixed this bug
upstream.
2017-09-26 18:47:47 +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
Nikita Popov
ec8692fb9e Fix InlineHTML indentation 2017-09-03 19:02:07 +02:00
Nikita Popov
31065389f1 Remove workarounds for reserved keyword method names
No longer necessary in PHP 7.
2017-09-02 20:08:20 +02:00
Nikita Popov
efd39a67a2 Merge branch '3.x'
Conflicts:
	lib/PhpParser/Builder/Trait_.php
	test/PhpParser/Builder/TraitTest.php
2017-08-29 23:20:47 +02:00
Nikita Popov
d77e6cd6e9 Allow TraitUse statements in trait builder
Fixes #413.
2017-08-29 23:18:59 +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
9373a8e9f5 Implement JsonDecoder
Converts JSON representation back into node tree.
2017-08-18 23:56:12 +02:00
TomasVotruba
af12807451 [cs] apply same to tests 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
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
19dde1363e Treat special names correctly in getShortName()
Also change the API to accept a string rather than a FullyQualified
name instance, as this is not appropriate for symbols like "self".
2017-06-13 19:51:22 +02:00
Nikita Popov
7646b31907 Merge branch '3.x' 2017-06-03 15:18:44 +02:00
Nikita Popov
bc0bff3f87 Fix method name in tests 2017-06-03 15:18:23 +02:00
Romain Neutron
c28b8556f5 Fix Lexer errorHandling when there is no tokens
I encounter an issue when no tokens exist. An error `Undefined offset -1` is triggered.
2017-06-03 15:17:45 +02:00
Nikita Popov
73dc35cbbd Allow null in ClassMethod::getStmts() 2017-05-07 19:56:14 +02:00
Wes
b1af3d1f7d Add Node::setAttributes() (#385) 2017-05-05 18:18:44 +02:00
Nikita Popov
92275bdfa8 Remove Node::setLine() method 2017-04-29 13:01:02 +02:00
Nikita Popov
a32e3797d4 Generate PHP 7 type annotations 2017-04-28 21:40:59 +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
3b4abbfc97 Add BuilderFactors->args(Add BuilderFactors->args()) 2017-04-28 18:13:06 +02:00
Nikita Popov
56b810e91d Add getShortName() API
PHP's name resolution rules are f'ing complicated.
2017-04-28 17:10:30 +02:00
Ekin
3c44785e82 Bump phpunit version (#381) 2017-04-27 18:14:07 +02:00
Nikita Popov
8635365a30 Fix some typing issues 2017-04-26 21:50:40 +02:00
Nikita Popov
ceaed32e94 Fix typo in method name 2017-04-26 21:47:31 +02:00
Nikita Popov
5f7070e94f Added BuilderFactory->concat() method 2017-04-24 21:42:59 +02:00
Nikita Popov
8f40eec122 Add BuilderFactory->val() method 2017-04-24 21:28:03 +02:00
Andreev Sergey
9dc93aafaa Add ClassMethod::isMagic() method 2017-04-23 13:54:17 +02:00
Nikita Popov
55be521ff8 Merge branch '3.x'
Conflicts:
	lib/PhpParser/Builder/Param.php
2017-04-19 11:17:52 +02:00
SignpostMarv
c877c1a64f Add Builder\Param::makeVariadic() 2017-04-19 11:16:29 +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
90b6d7cb5b Remove XML serializer 2017-02-04 01:10:09 +01:00
Nikita Popov
987c61e935 Drop support for false return value in NodeTraverser 2017-02-03 22:36:57 +01:00
Nikita Popov
2b72bae3d9 Throw if NodeVisitor returns invalid value 2017-02-03 22:30:26 +01:00
Nikita Popov
2b6804aa50 Throw on nested array in NodeTraverser
The AST never uses deeply nested arrays, so don't support this in
the node traverser. Throw an exception instead.
2017-02-03 22:11:31 +01:00
Nikita Popov
d9911c8da5 Merge branch '3.x'
Conflicts:
	lib/PhpParser/Node/Expr/ClassConstFetch.php
	test/PhpParser/PrettyPrinterTest.php
2017-02-03 21:54:48 +01:00
Nikita Popov
d287c167bc Pretty print: Handle Error in ClassConstFetch 2017-02-03 21:53:02 +01:00
Nikita Popov
79afd56565 Add NodeFinder class
To simplify basic node finding operations.
2017-01-29 23:20:53 +01:00
Nikita Popov
5cc2750ebc Merge branch '3.x'
Conflicts:
	lib/PhpParser/NodeVisitor.php
2017-01-29 22:36:33 +01:00
Nikita Popov
58e7881e98 Implement NodeTraverser::STOP_TRAVERSAL
Conflicts:
	lib/PhpParser/NodeVisitor.php
2017-01-29 22:35:40 +01:00
Nikita Popov
e072c789d1 Merge branch '3.x'
Conflicts:
	test/PhpParser/PrettyPrinterTest.php
2017-01-29 21:57:37 +01:00
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
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
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
7623d20f69 Automatically wrap in Stmt\Expression in builders 2017-01-19 22:39:21 +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
b0c962911e Add test porting infrastructure 2017-01-19 22:24:48 +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
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
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
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
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
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
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
f6eb341b15 Fix GroupUse prefix attribute assignment 2016-10-08 23:55:46 +02:00
Nikita Popov
2e5ae28c39 Don't use deprecated getMock() 2016-09-30 20:42:19 +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
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
9e1c535b1d Update builder tests to use "flags" instead of "type" 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
f7cb00d6d3 Add missing canonicalization in test 2016-07-25 21:02:53 +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
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
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
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
Nikita Popov
e45e31c218 Fix new.test and code test runner
Using only the basename leads to collisions...
2016-04-20 15:03:18 +02:00
algo13
371c783344 Escape all low control characters in strings 2016-04-19 17:45:39 +02:00
Nikita Popov
5a6e7dd452 Avoid superfluous newline when printing Nops 2016-04-19 15:10:51 +02:00
Nikita Popov
90eb1165d1 Switch Exit kind attribute to flag
To be consistent with everything else.
2016-04-19 14:51:05 +02:00
Nikita Popov
e7869b9f14 Forbid invalid octals in PHP 7 mode 2016-04-18 13:59:18 +02:00
Nikita Popov
4c7ad7e194 Allow nop statements before namespace declaration 2016-04-16 21:39:49 +02:00
lvht
39f93f09f9 Add setReturnType() method to function/method builders
Also support scalar type hints in existing setTypeHint() method on params.
2016-04-09 18:41:38 +09:00
Nikita Popov
8cacc85913 "Fix" HHVM build 2016-04-07 12:27:08 +09:00
Nikita Popov
588e6a4d4c Add string kinds and doc string labels
Scalar\String_ and Scalar\Encapsed now have an additional "kind"
attribute, which may be one of:

 * String_::KIND_SINGLE_QUOTED
 * String_::KIND_DOUBLE_QUOTED
 * String_::KIND_NOWDOC
 * String_::KIND_HEREDOC

Additionally, if the string kind is one of the latter two, an
attribute "docLabel" is provided, which contains the doc string
label (STR in <<<STR) that was originally used.

The pretty printer will try to take the original kind of the string,
as well as the used doc string label into account.
2016-04-07 12:09:00 +09:00
Nikita Popov
52cb5ecec7 Fix comment reformatting for some cases
It did not correctly deal with non-standard comments containing
indented lines.
2016-04-07 11:47:40 +09:00
Nikita Popov
14de71898e Fix nop statement comment assignment
Keep around the start attributes on the lookahead token around in
a separate parser property.
2016-04-05 19:19:15 +09:00
Nikita Popov
5fa8493675 Make canonicalization less aggressive 2016-04-05 10:37:45 +09:00
Nikita Popov
b31a973fa7 Another fix for B"" handling
The lexer fix also need to account for uppercase B.
2016-04-04 22:07:50 +09:00
Nikita Popov
9ac3592190 Handle uppercase B"" prefix 2016-04-02 21:15:49 +09:00
Nikita Popov
35011d2e4d Deduplicate attribute assignment code a bit 2016-04-02 08:02:58 +09:00
Nikita Popov
15a2388d75 Add start file offset to Comments 2016-04-02 07:54:01 +09:00
Nikita Popov
68b4c0388a Fix Serializer/XML test output indent
This causes a failure here, but not on another machine, not sure
why.
2016-04-02 07:27:01 +09:00
Nikita Popov
eb4bfe1366 Add sanity check for leaveNode() return value 2016-03-27 14:52:15 +02:00
Nikita Popov
f493219c7d Move "kind" attribute handling out of lexer
Doesn't belong there and will cause issue with multiple assignments.
2016-03-10 12:55:15 +01:00
Nikita Popov
aa199120c7 Add kind attribute for arrays
To distinguish array() and [] syntax. The pretty printer respects
this attribute. The shortArraySyntax pretty printer option acts as
a default in case the attribute is not specified.
2016-03-09 21:31:54 +01:00
Nikita Popov
ae30f97af6 Add "kind" attribute to LNumbers
Kind specifies whether the number was formatted as decimal, octal,
binary or hex. The pretty printer reproduces the number kind (but
not necessarily the exact formatting).
2016-03-09 21:10:55 +01:00
Nikita Popov
47c342a3e4 Add "kind" attribute to Stmt\Exit_
Attribute specifies whether this is a "die" or an "exit" and the
pretty printer behaves accordingly.
2016-03-09 20:20:36 +01:00
Nikita Popov
7eac2cfd8b Introduce Nop statement to collect dangling comments
A Nop statement will be inserted into statement lists if there are
any trailing comments in the list (which would otherwise not be
associated with any node).

The pretty printer output currently still contains a superfluous
newline.
2016-03-09 19:48:36 +01:00
Nikita Popov
a0c216bf4b Add dumpComments option to NodeDumper
Adding this as an option to avoid breaking people's tests.

Some of the test results show pretty clearly that we are incorrectly
assigning the same comment multiple times for nested nodes (mentioned
in #36).
2016-03-09 19:48:36 +01:00
Nikita Popov
9829bf69cd Fix issue #251 2016-02-28 20:28:32 +01:00
Nikita Popov
a73aa7eec1 Pretty printer test coverage
Our output for yield / yield from is currently not very nice, but
also not easy to change.
2016-02-20 21:49:21 +01:00
Nikita Popov
1fe8f09caa Fix __halt_compiler() pretty printing edge case
We can't strip the <?php at the end of a __halt_compiler() segment
in file mode.

Fixed by being a bit more explicit in prettyPrintFile() about what
we want to do...
2016-02-20 18:24:32 +01:00
Nikita Popov
d6361136e1 Update semi-reserved keyword list
Magic constant names have been added after the PHP 7 release.

We do not support and likely will not support __halt_compiler here
due to lexer limitations.
2016-02-09 13:30:39 +01:00
Nikita Popov
6dffb72ce0 Merge branch '1.x' 2016-01-15 22:02:35 +01:00
Nikita Popov
eb73441032 Support hashbang before namespace declaration
Fixes issue #243.
2016-01-15 22:01:51 +01:00
Nikita Popov
719ca71d4a Distinguish declare(); and declare(){}
It makes semantic difference and the latter form is actually
forbidden for strict_types.

This sets Declare->stmts to null for the body-less case.
2015-12-07 12:12:00 +01:00
Nikita Popov
a9074c7444 Introduce Scalar\EncapsedStringPart 2015-12-03 22:55:07 +01:00
Nikita Popov
98d28d7aa0 Drop test failing on HHVM
Can readd if Travis ever updates the HHVM version again, I
remember this being fixed ages ago.
2015-10-03 12:17:41 +02:00
Nikita Popov
e4b837e0c4 Split up pretty printer test in stmt/expr
The list was getting unweildly.

Also improve error message when parsing fails in pretty printer
test and extend some tests.
2015-10-02 11:16:12 +02:00
Aydin
2b9c5a62cb Multiple init test for for loop 2015-10-02 11:03:33 +02:00
Aydin
99e89743bd More PrettyPrinter tests 2015-10-02 11:03:32 +02:00
Nikita Popov
39a039fa42 Add option for short array syntax in pretty printer 2015-09-21 15:12:59 +08:00
Nikita Popov
b2961915a6 Fix XML serialization test
I have no idea why this suddenly turned up *now*
2015-09-21 14:29:24 +08:00
Nikita Popov
eecaf1e93b Merge branch '1.x'
Conflicts:
	grammar/rebuildParsers.php
	lib/PhpParser/Parser.php
2015-09-19 22:07:29 +08:00
Nikita Popov
950ada4cba Fix issue #227
Use \z instead of $.
2015-09-19 22:05:23 +08:00
Dmitry Patsura
e3a9356178 Use composer PSR-4 autoloader 2015-09-16 22:02:00 +09:00
Nikita Popov
fe6755ff4c Use more helpful code test names 2015-08-25 21:36:08 +02:00
Nikita Popov
f57d217e91 Update group use support
To conform with current PHP 7 implementation

* Allow use \Foo\{Bar};
* Disallow use Foo\{\Bar};
* Disallow missing trailing semicolon (that was a bug)
2015-08-20 16:42:49 +02:00
Nikita Popov
dc85742034 Merge branch '1.x'
Conflicts:
	CHANGELOG.md
	composer.json
	test/PhpParser/ParserTest.php
2015-07-14 19:43:49 +02:00