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
Nikita Popov
b9afcdfd92
Revert "Make tests compatible with PHP 7"
...
This reverts commit 91295a0790
.
This should no longer be necessary.
Conflicts:
test/PhpParser/ParserTest.php
2015-07-14 19:21:57 +02:00
Nikita Popov
feb82eed33
Disable cloning in traverser by default
2015-07-14 17:39:56 +02:00
Nikita Popov
0ef15c111a
Merge branch '1.x'
2015-07-14 17:08:28 +02:00
Nikita Popov
d341d94976
Add ClassLike::getMethod($name)
...
To allow getting individual method with a given name.
2015-07-14 17:07:45 +02:00
Nikita Popov
0265c28e6e
Switch NameResolver resolve methods to be immutable
...
To make it theoretically possible to expose this as API.
Add slice() method to Name to allow this. Deprecate existing mutable
Name APIs.
2015-07-12 23:56:57 +02:00
Nikita Popov
5bd8cb84de
Add dummy ParserFactory test
...
:/
2015-07-12 22:53:17 +02:00
Nikita Popov
ebeeae19a6
Merge branch '1.x'
2015-07-12 22:12:28 +02:00
Nikita Popov
5ede167835
Fix infinite recursion in Use builder __call
2015-07-12 22:11:43 +02:00
Nikita Popov
21e51c8cf6
Add some tests for Multiple parser
2015-07-12 22:00:02 +02:00
Nikita Popov
e7a2abb03b
Merge branch '1.x'
2015-07-11 22:33:19 +02:00
Nikita Popov
b862de1f5b
Support properties in trait builder
2015-07-11 22:31:45 +02:00
Nikita Popov
8090531acd
Fix pretty printing of const derefs for 5.x
...
(FOO)[0] is only supported on 7.x
2015-07-09 12:38:30 +02:00
Nikita Popov
1d62e9d8cc
Fix implicit visibility for properties as well
...
Also switch to using PPP mask.
2015-07-05 20:17:52 +02:00
Lisachenko Alexander
2a3bc608dc
Add broken test for implicit public nodes
2015-07-05 20:17:49 +02:00
Nikita Popov
90ab32f046
Merge branch '1.x'
2015-07-05 20:16:41 +02:00
Nikita Popov
7434a682e5
Fix implicit visibility for properties as well
...
Also switch to using PPP mask.
2015-07-05 20:16:21 +02:00
Lisachenko Alexander
5e6627c895
Add broken test for implicit public nodes
2015-07-05 20:10:47 +02:00
Nikita Popov
f872fa9b0b
Merge branch '1.x'
2015-07-04 14:40:53 +02:00
Nikita Popov
d5668f536d
Fix __HALT_COMPILER_OFFSET__ support on HHVM
2015-07-04 13:15:48 +02:00
Nikita Popov
9c9a8cddce
Merge branch '1.x'
2015-06-20 12:34:36 +02:00
Nikita Popov
fd7ee2e083
Add missing regex anchor
2015-06-20 12:34:10 +02:00
Nikita Popov
f2b7a31509
Rename ParserInterface to Parser
...
And drop the alias of Parser to Parser\Php5.
2015-06-20 11:47:25 +02:00
Nikita Popov
d8312a09a3
Split parsing tests into code tests and other stuff
...
And run the other stuff against Php5 and Php7 parsers.
Also move canonicalize() from CodeTestAbstract into a free-standing
function.
2015-06-20 11:44:29 +02:00
Nikita Popov
ef9a154d09
Add support for unicode escape sequences
...
Only parsed if the PHP 7 parser is used.
2015-06-13 20:51:02 +02:00
Nikita Popov
0da72fad00
Support scalar type declarations
2015-06-13 20:16:09 +02:00
Nikita Popov
71fa7c6674
Support UVS in pretty printer
...
Try to generate interoperable code where possible (but not
everything can be expressed in PHP 5).
2015-06-13 20:01:01 +02:00
Nikita Popov
f3f24e03ae
Support running against PHP 7 testsuite
2015-06-13 19:09:24 +02:00
Nikita Popov
bc21514ecf
Move token constants into separate class
...
As these are shared between Php5 and Php7 parsers they should be
in some common place, otherwise we'd have to always reference either
one or the other.
2015-06-13 18:39:55 +02:00
Nikita Popov
04e05907c3
Fix CRLF issue in Serializer\XML test
...
No idea why this suddenly turned up now.
2015-06-13 18:20:05 +02:00
Nikita Popov
61e060694d
Implement generalized yield operator
...
And split tokens.y off, so I don't waste time debugging this again...
2015-06-13 18:11:40 +02:00
Nikita Popov
602b9807eb
Import some UVS tests
2015-06-13 15:42:09 +02:00
Nikita Popov
f372a4c4ab
Move modeline handling into CodeTestAbstract
2015-06-13 15:10:46 +02:00
Nikita Popov
d18dcc0c7f
Implement UVS
2015-06-13 14:59:24 +02:00
Nikita Popov
74c57eef0e
Test PHP 5 and PHP 7 parsers
...
At this point they should return the same result.
2015-06-13 13:56:45 +02:00
Nikita Popov
dca46febc9
Implement semi-reserved identifiers
2015-06-13 12:47:13 +02:00
Nikita Popov
1a1bd1448d
Support mixed group use declarations
2015-06-13 11:27:38 +02:00
Nikita Popov
9620f79cdc
Add partial group use support
...
Supported via Stmt\GroupUse which has Name $prefix in addition to
the usual.
Still missing: Mixed group uses.
2015-06-12 23:05:28 +02:00
Nikita Popov
5d1e3be7d4
Anonymize some callbacks
2015-05-02 22:35:15 +02:00
Nikita Popov
cc75dd3612
Drop support for PHP 7 aliases
2015-05-02 22:21:12 +02:00
Nikita Popov
5f621c5adc
Drop support for legacy aliases from v0.9
2015-05-02 22:19:25 +02:00
Nikita Popov
29b9015f51
Drop support for old Node format
2015-05-02 22:17:34 +02:00
Nikita Popov
8b64195cf2
Try .17G print if .16G is not enough
...
This should be enough for all cases, because: A double has 53 bits
of mantissa (including the implicit 1 bit), which is 53*ln(2)/ln(10)
= 15.95 decimal digits. However the leading decimal digit may encode
less than the usual 3.32 bits, which will push this over the edge to
requiring 17 decimal digits.
2015-05-02 11:48:55 +02:00
Nikita Popov
9caa51b3a5
Add some more tests
2015-05-01 20:18:04 +02:00
Nikita Popov
648800f07f
Increase float pretty printing precision
...
This removes the reliance on the "precision" ini setting.
Furthermore the default of precision=14 is not sufficient.
2015-05-01 19:15:33 +02:00
Nikita Popov
23bf4f0c13
Add some error documentation
2015-04-30 21:58:45 +02:00
Nikita Popov
272ab6c8d8
Add some recovery tests
2015-04-30 19:02:51 +02:00
Nikita Popov
0731b47655
Don't distinguish test-fail / test
...
With error recovery this is fluid. Using .test for everything.
2015-04-30 17:45:36 +02:00
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
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
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
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