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
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
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
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
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
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
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
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
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
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
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
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
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
d18dcc0c7f
Implement UVS
2015-06-13 14:59:24 +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
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
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
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
Gerrit Addiks
33a39fae06
added column-numbers to syntax errors
2015-04-18 10:14:49 +02:00
Nikita Popov
592836c4dc
Add support for T_HASHBANG (HHVM)
2015-03-14 19:53:08 +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
4dbf067b4b
Add a few more string interpolation tests
...
Originally wanted to simplify the pretty-printer output, but ...
edge cases everywhere :/
2015-03-11 20:01:26 +01:00
Thomas Ruiz
73cace360d
Implicit public should not generate as explicit public
2015-03-08 20:21:01 +01:00
Nikita Popov
91295a0790
Make tests compatible with PHP 7
...
When parsing on PHP 7 we will no longer be able to deal with
code that contains invalid octal literals. Currently we'll fatal,
after engine exceptions land we'll throw an exception instead.
2015-02-26 16:26:29 +01:00
Nikita Popov
6930feac43
Add some tests for pretty printing expressions
2015-01-18 19:57:09 +01:00
nikic
e26e63e9b0
Error on final or abstract properties
2014-11-13 20:25:52 +01:00
nikic
0f69f12b94
Use "public" visibility when not explicitly given
...
Fixes issue #143
2014-11-13 20:21:21 +01:00
nikic
7fbdb79a08
Fix whitespace when printing trait alias modifiers
2014-11-03 16:16:15 +01:00
nikic
69701430c1
Cover remaining constant scalar expressions
2014-09-28 13:05:23 +02:00
nikic
3e1665bbbd
Disallow new without a class name
...
Fixes #137 .
2014-09-28 12:41:35 +02:00
nikic
452e1c0180
Add constant dereferencing, a list-minute 5.6 change
2014-08-31 16:14:36 +02:00
nikic
1f143393e5
Rewrite namespace handling code
...
Add a check for disallowed statements between braced namespaces
while at it.
2014-04-21 15:16:00 +02:00
nikic
4743e9b0b8
Update constant scalar expression support
2014-04-19 22:53:13 +02:00
nikic
91f6880734
Improve pretty printing of empty statement lists
...
The pStmts() method now also includes the leading \n, however only
if the statement list is non-empty.
2014-03-27 12:31:21 +01:00
nikic
3b7829b011
Add support for function and constant import (PHP 5.6)
2014-03-26 22:33:45 +01:00
nikic
bea89a0bf2
Add support for constant scalar expressions (PHP 5.6)
2014-03-26 21:48:12 +01:00
nikic
cda6f575f0
Add support for pow operator (PHP 5.6)
2014-03-26 19:18:16 +01:00
nikic
b5bcfa1168
Add support for argument unpacking (PHP 5.6)
2014-03-26 18:42:46 +01:00
nikic
96f1151ab2
Add support for variadic parameters (PHP 5.6)
2014-03-26 18:23:30 +01:00
nikic
f5be0d30f7
Guarantee that subnodes are always in the right order
2014-03-22 14:49:56 +01:00
Tomáš Polomský
c8c233f900
Correctly pretty print negative floats
2014-03-22 14:24:35 +01:00
nikic
1c8481bff6
Merge branch '0.9'
...
Conflicts:
lib/PhpParser/Lexer.php
lib/PhpParser/Node/Stmt/Class.php
lib/PhpParser/Node/Stmt/ClassMethod.php
lib/PhpParser/Node/Stmt/Interface.php
lib/PhpParser/Node/Stmt/Namespace.php
lib/PhpParser/Node/Stmt/UseUse.php
lib/PhpParser/Parser.php
2014-02-12 20:23:12 +01:00
Martin Hasoň
118f28344d
Synchronized error messages with native php error messages
2014-02-12 20:19:48 +01:00
nikic
f82862ec9c
Port library to use namespaces, with BC for old names
2014-02-06 20:29:35 +01:00
nikic
77c08a75c9
Fix pretty printing of include
expressions
2013-07-27 16:23:27 +02:00
nikic
08f0cde6f9
Add prettyPrintFile() method
2013-04-15 20:53:23 +02:00
nikic
75ec7a3e78
Looks like I forgot to git add some files...
2013-02-14 21:49:08 +01:00
nikic
81d20bf10e
Pretty print namespaces in semicolon-style if possible
2013-01-15 18:21:42 +01:00
nikic
fbaa1e5fc3
Add information on expected tokens to syntax errors
...
This now mimics the error messages provided by PHP itself (pre 5.4).
2013-01-15 17:30:14 +01:00
nikic
df17d62b40
Fix switch formatting
...
The switch cases were not indented and fall-through cases had an
unnecessary additional newline.
Patch by @pscheit (PR #39 ).
2012-10-31 17:46:48 +01:00
nikic
ac6f221c50
Better prededence and associativity handling in pretty printer
...
Previously the pretty printer added unnecessary and odd-looking parentheses
when several operators with the same precedence were chained:
'a' . 'b' . 'c' . 'd' . 'e'
// was printed as
'a' . ('b' . ('c' . ('d' . 'e')))
Another issue reported as part of #39 was that assignments inside closures
were wrapped in parentheses:
function() {
$a = $b;
}
// was printed as
function() {
($a = $b);
}
This was caused by the automatic precedence handling, which just regarded
the closure as an ordinal nested expression.
With the new system the $predenceMap of PrettyPrinterAbstract contains both
precedence and associativity and there is a new method pPrec() which prints
a node taking precedence and associativity into account.
For simpler usage there are additional function pInfixOp(), pPrefixOp() and
pPostfixOp().
Prints not going through pPrec() do not have any precedence handling (fixing
the closure issue).
2012-10-31 17:34:06 +01:00
nikic
9d8e13b4a9
Fix Switch subnode order
...
Not that it makes much of a difference, but could have caused issues with
"out of order" visiting of nodes.
2012-10-19 14:54:56 +02:00
nikic
af5d288fb3
Add support for expressions in empty (PHP 5.5)
...
Apart from the grammar modifications this also renames the Empty subnode
from var to expr. This breaks BC.
2012-09-07 23:42:01 +02:00
nikic
f6c1ab6657
Adjust list and yield parsing, update prettyprinter
...
* nested list()s will now create nested List nodes (instead of just
nested arrays)
* yield $k => $v was parsed with key and value swapped. This is now fixed
* the pretty printer now works with the newly added language constructs
2012-09-07 23:41:59 +02:00