Compare commits

...

293 Commits

Author SHA1 Message Date
c542e5d86a Release PHP-Parser 2.0.0 2015-12-04 16:28:43 +01:00
a9074c7444 Introduce Scalar\EncapsedStringPart 2015-12-03 22:55:07 +01:00
b2f26d30ee Update README regarding PHP 7 compat 2015-11-21 22:30:40 +01:00
75cd4ab7a5 Use error_clear_last() on PHP 7
Instead of the ugly undefined variable hack
2015-11-21 22:27:56 +01:00
33602889c1 Release version 2.0.0 beta 1 2015-10-21 20:30:17 +02:00
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
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
2b9c5a62cb Multiple init test for for loop 2015-10-02 11:03:33 +02:00
99e89743bd More PrettyPrinter tests 2015-10-02 11:03:32 +02:00
39a039fa42 Add option for short array syntax in pretty printer 2015-09-21 15:12:59 +08:00
fcf23101dd Fix autoloader path in php-parse
Need to go up another directory...
2015-09-21 14:57:31 +08:00
c8898df3dd Add php-parse as composer bin
Renaming from php-parse.php to just php-parse to follow the usual
conventions.

Not tested.
2015-09-21 14:39:19 +08:00
b2961915a6 Fix XML serialization test
I have no idea why this suddenly turned up *now*
2015-09-21 14:29:24 +08:00
6f3fd7834a Specify phpunit dev dependency in composer.json
And use it for the travis build.
2015-09-20 21:17:42 +08:00
eecaf1e93b Merge branch '1.x'
Conflicts:
	grammar/rebuildParsers.php
	lib/PhpParser/Parser.php
2015-09-19 22:07:29 +08:00
950ada4cba Fix issue #227
Use \z instead of $.
2015-09-19 22:05:23 +08:00
0d4239ef56 Only advertize install via composer
Now that it's so small, move installation docs into readme.
2015-09-16 22:16:29 +09:00
e3a9356178 Use composer PSR-4 autoloader 2015-09-16 22:02:00 +09:00
5118e21c6e Add nightly to travis, use container based infra
Currently 7.0 and nightly are the same, but for the future...
2015-09-14 22:27:01 +09:00
40455b5c18 TravisCI - stop allowing to failture PHP7 2015-09-14 22:26:25 +09:00
fe6755ff4c Use more helpful code test names 2015-08-25 21:36:08 +02:00
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
e0a75ededa Release PHP-Parser 2.0 Alpha 1 2015-07-14 21:13:42 +02:00
2496cd38ad Various docs fixes 2015-07-14 21:11:54 +02:00
965e53a164 Update changelog 2015-07-14 20:13:26 +02:00
dc85742034 Merge branch '1.x'
Conflicts:
	CHANGELOG.md
	composer.json
	test/PhpParser/ParserTest.php
2015-07-14 19:43:49 +02:00
196f177cfe Prepare PHP-Parser 1.4.0 release 2015-07-14 19:31:05 +02:00
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
3bb874fcec Partial docs update 2015-07-14 19:19:32 +02:00
feb82eed33 Disable cloning in traverser by default 2015-07-14 17:39:56 +02:00
0ef15c111a Merge branch '1.x' 2015-07-14 17:08:28 +02:00
d341d94976 Add ClassLike::getMethod($name)
To allow getting individual method with a given name.
2015-07-14 17:07:45 +02:00
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
5bd8cb84de Add dummy ParserFactory test
:/
2015-07-12 22:53:17 +02:00
ebeeae19a6 Merge branch '1.x' 2015-07-12 22:12:28 +02:00
5ede167835 Fix infinite recursion in Use builder __call 2015-07-12 22:11:43 +02:00
49324ea412 Drop default values from Scalar ctor params 2015-07-12 22:02:18 +02:00
21e51c8cf6 Add some tests for Multiple parser 2015-07-12 22:00:02 +02:00
e7a2abb03b Merge branch '1.x' 2015-07-11 22:33:19 +02:00
b862de1f5b Support properties in trait builder 2015-07-11 22:31:45 +02:00
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
49253c5dbb Fix test_old/run.php error message 2015-07-09 12:38:30 +02:00
c5ac17711d Merge branch '1.x' 2015-07-05 20:18:05 +02:00
1d62e9d8cc Fix implicit visibility for properties as well
Also switch to using PPP mask.
2015-07-05 20:17:52 +02:00
e3195c246f Fix public modifier check for ClassMethod node 2015-07-05 20:17:50 +02:00
2a3bc608dc Add broken test for implicit public nodes 2015-07-05 20:17:49 +02:00
90ab32f046 Merge branch '1.x' 2015-07-05 20:16:41 +02:00
7434a682e5 Fix implicit visibility for properties as well
Also switch to using PPP mask.
2015-07-05 20:16:21 +02:00
0fbb5f90a1 Fix public modifier check for ClassMethod node 2015-07-05 20:10:48 +02:00
5e6627c895 Add broken test for implicit public nodes 2015-07-05 20:10:47 +02:00
f872fa9b0b Merge branch '1.x' 2015-07-04 14:40:53 +02:00
d5668f536d Fix __HALT_COMPILER_OFFSET__ support on HHVM 2015-07-04 13:15:48 +02:00
a5db176903 Merge branch '1.x' 2015-07-02 18:09:38 +02:00
7fbbf83011 Added syntax highlighting in README 2015-07-02 18:09:12 +02:00
42e368e964 Fix returnType typehints
Fixes issues #207
2015-07-02 18:06:41 +02:00
9c9a8cddce Merge branch '1.x' 2015-06-20 12:34:36 +02:00
fd7ee2e083 Add missing regex anchor 2015-06-20 12:34:10 +02:00
179d32cfaf Simplify handleHaltCompiler() implementation
Nowadays we're already tracking the filePos, no need to
recompute it.
2015-06-20 12:33:33 +02:00
f2b7a31509 Rename ParserInterface to Parser
And drop the alias of Parser to Parser\Php5.
2015-06-20 11:47:25 +02:00
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
813c9f1545 Add basic ParserFactory 2015-06-20 11:28:58 +02:00
ef9a154d09 Add support for unicode escape sequences
Only parsed if the PHP 7 parser is used.
2015-06-13 20:51:02 +02:00
0da72fad00 Support scalar type declarations 2015-06-13 20:16:09 +02:00
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
f3f24e03ae Support running against PHP 7 testsuite 2015-06-13 19:09:24 +02:00
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
04e05907c3 Fix CRLF issue in Serializer\XML test
No idea why this suddenly turned up now.
2015-06-13 18:20:05 +02:00
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
602b9807eb Import some UVS tests 2015-06-13 15:42:09 +02:00
f372a4c4ab Move modeline handling into CodeTestAbstract 2015-06-13 15:10:46 +02:00
d18dcc0c7f Implement UVS 2015-06-13 14:59:24 +02:00
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
fdbddc4b8c Add Multiple parser 2015-06-13 13:38:24 +02:00
ca3b44bf60 Fork separate PHP 7 parser
Also add ParserInterface
2015-06-13 13:09:34 +02:00
dca46febc9 Implement semi-reserved identifiers 2015-06-13 12:47:13 +02:00
1a1bd1448d Support mixed group use declarations 2015-06-13 11:27:38 +02:00
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
583b560f71 Drop {@inheritDoc}
Those are unnecessary and actually against the spec.
2015-06-12 20:37:43 +02:00
db3dafd64d Merge branch '1.x' 2015-06-05 18:57:04 +02:00
bb2c5303ae Add a FunctionLike interface to Methods, Functions and Closures.
The elements listed above share common elements like parameters, possible return types and bodies.
2015-06-05 18:56:25 +02:00
5038dcc251 Merge branch '1.x' 2015-05-03 19:12:09 +02:00
69c00ebbe4 Make help output help2man-friendly
These changes follow regular advices for CLI output and allow help2man
to produce a meaningful manpage out of it.
2015-05-03 19:11:04 +02:00
a0e7d5e0aa Set correct number of s/r conflicts 2015-05-02 22:51:38 +02:00
51ec2a25fe Move parser to Parser\Php5
Old name still exists.
2015-05-02 22:50:11 +02:00
5d1e3be7d4 Anonymize some callbacks 2015-05-02 22:35:15 +02:00
9d42e4a2e2 Drop short array simulation from .phpy syntax
Instead use real short array syntax.
2015-05-02 22:30:44 +02:00
cc75dd3612 Drop support for PHP 7 aliases 2015-05-02 22:21:12 +02:00
5f621c5adc Drop support for legacy aliases from v0.9 2015-05-02 22:19:25 +02:00
29b9015f51 Drop support for old Node format 2015-05-02 22:17:34 +02:00
e6619f5514 Drop 5.4 support from emulative lexer 2015-05-02 22:13:55 +02:00
6b4a17b3e0 Set version to 2.0-dev. Drop PHP 5.3 support 2015-05-02 22:08:03 +02:00
30abe062f2 Update documentation link 2015-05-02 22:03:33 +02:00
dff239267f Release PHP-Parser 1.3.0 2015-05-02 17:40:40 +02:00
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
9caa51b3a5 Add some more tests 2015-05-01 20:18:04 +02:00
5513073a53 Drop Lexer::getPosition()
This was a leftover from the original column info implementation.
2015-05-01 20:18:01 +02:00
659d26c231 Update changelog, fix typos 2015-05-01 19:57:10 +02:00
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
23bf4f0c13 Add some error documentation 2015-04-30 21:58:45 +02:00
57ac7e39bf Drop name magic from rebuildParser.php
Now using explicitly imported names, instead of magically
prepending Name\.

Also remove trailing whitespace from generated file.
2015-04-30 19:20:38 +02:00
272ab6c8d8 Add some recovery tests 2015-04-30 19:02:51 +02:00
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
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
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
55b2ead967 Make special class name checks case insensitive 2015-04-26 23:13:27 +02:00
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
66896dbde6 Poison attribute initializations in parser
Those should error if they end up being used.
2015-04-26 22:32:18 +02:00
338bc1f8e7 Fix "print" pretty-printing
Precedence was previously ignored.
2015-04-26 11:56:04 +02:00
ab80054e97 Add support for "yield from" 2015-04-26 11:56:02 +02:00
a6d2cd69f8 Clarify attribute assignment code
* Don't assign to attribute stack on reduce - why was that there
in the first place?
* Assign attributes to the position in the stack where the first
token of the production is, instead of one position earlier.
* Add a comment to clarify why we also assign attributes on read,
instead of just on shift.
2015-04-26 11:56:01 +02:00
6996db1e3a Build node attributes inside semantic action methods
Minor performance improvement for parsing, also allows to access
attributes with higher granulity in the parser, though this is not
currently done.

* #n can now be used to access the stack position of a token. $n
  is the same as $this->semStack[#n]. (Post-translate $n will
  actually be the stack position.)
* $attributeStack is now $this->startAttributeStack and
  $endAttributes is now $this->endAttributes.
* Attributes for a node are now computed inside the individual
  reduction methods, instead of being passed as a parameter.
  Accessible through the attributes() macro.
2015-04-26 11:55:59 +02:00
e30c3ac01b Merge pull request #195 from GrahamCampbell/patch-1
Bump version to 1.3
2015-04-19 20:52:51 +02:00
a5477a4eaf Version bump 2015-04-19 17:57:38 +01:00
7a40498cb4 Regenerate parser
Also drop the error() parser macro.
2015-04-19 18:12:56 +02:00
65f1adbe65 Merge primary error recovery code
The grammar does not yet actually implement error recovery.
2015-04-19 18:11:05 +02:00
c8454271e1 Make column info 1-based 2015-04-18 21:20:45 +02:00
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
611fa5c7f1 Test parser position information (syntax errors) 2015-04-18 13:27:57 +02:00
4defbc2174 Make Error column info attribute based 2015-04-18 12:51:26 +02:00
33a39fae06 added column-numbers to syntax errors 2015-04-18 10:14:49 +02:00
e4eab9ec0c Simplify code
The new class couldn't already exist at that point - if it did, the
old name would have been aliased already and the autoloader wouldn't
trigger.
2015-04-03 22:30:30 +02:00
6aaa87f143 Fix PHP 7 alias registration
This fixes the case where the old name is used before the new one
is ever used, e.g. when manually constructing nodes, as opposed to
parsing them.

The previous approach would try to register the alias from OLD to
NEW. This would trigger autoloading on NEW and afterwards it would
register the alias from OLD to NEW. Afterwards the alias registration
which originally triggered the autoload would run, thus redeclaring
the class.

TL;DR aliases suck, closes #192.
2015-04-03 22:22:39 +02:00
08f97eb4ef Release PHP-Parser 1.2.2 2015-04-03 16:33:59 +02:00
8d18848fb0 Don't set unserialize_callback_func in Autoloader::register() as it has side effects even when the library is not used 2015-04-03 16:25:33 +02:00
805078e0a9 Add missing type hints 2015-03-28 18:14:24 +01:00
52dafafd10 Resolve param type hints earlier
For convenience of concurrent visitors that want to perform
enterNode actions based on Stmt\Function_ etc.

Fixes #188.
2015-03-25 20:57:39 +01:00
dba7524b37 Release PHP-Parser 1.2.1 2015-03-24 20:10:28 +01:00
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
dce19b074b Strict type compliance
Were this library to be fully annotated with scalar types and
return types where possible and were strict types to be enabled
for all files, the test suite would now pass.
2015-03-24 11:19:17 +01:00
edbf162e4c Release PHP-Parser 1.2.0 2015-03-22 17:17:25 +01:00
b23c53df5f Update CHANGELOG 2015-03-22 16:03:59 +01:00
cea0c4a9d6 Don't register aliases on PHP 7 2015-03-22 16:03:57 +01:00
879e8dcd6d Merge pull request #186 from mnapoli/clone-nodes
Added a flag to NodeTraverser to avoid cloning nodes
2015-03-22 15:19:10 +01:00
729c7bde0c #184 Add a flag to NodeTraverser to avoid cloning nodes 2015-03-22 11:19:04 +13:00
8982315b4e Rename Cast\Object as well
As it will very likely be soft-reserved in PHP 7.

Old alias is still available, as usual.
2015-03-21 18:57:55 +01:00
0f556c16f5 Fix a few more Scalar\String_ occurances
Totally forgot that the parser uses macros...
2015-03-21 18:54:52 +01:00
7ec277e1e1 Replace another Scalar\String occurance
Also canonicalize NameResover tests to avoid those pesky CRLF
issues.
2015-03-21 18:47:20 +01:00
1a627872f0 Rename nodes for compat with PHP 7
The old names will still be available on PHP 5.x.
2015-03-20 21:49:38 +01:00
592836c4dc Add support for T_HASHBANG (HHVM) 2015-03-14 19:53:08 +01:00
68defc2c6a Merge pull request #183 from alprs/fix-autoloader
Ensure compatibility with multiple composer autoloaders
2015-03-14 09:07:35 +01:00
d225555830 Ensure compatibility with multiple autoloaders
Running a .phar or regular PHP executable that requires and includes its own
version of php-parser will cause a "cannot redeclare class" error if said
executable also includes the autoloader of the current working directory.
2015-03-13 23:54:32 +01:00
251e689283 Add support for spaceship operator (<=>) [PHP 7]
Added as Expr\BinaryOp\Spaceship.
2015-03-12 23:13:31 +01:00
01f4be6b4d Add support for null coalesce operator (??) [PHP 7]
Added as Expr\BinaryOp\Coalesce.
2015-03-12 22:45:56 +01:00
dc28449d81 Drop whitespace after ... varargs collection
Also drop an obsolete pretty printer test.
2015-03-12 22:19:34 +01:00
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
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
5567f0ab3b Add documentation TOC to readme 2015-03-10 21:32:21 +01:00
0c34706799 Add "use" builder 2015-03-10 16:05:55 +01:00
f9fc2fc9ee Add support for global namespace in NS builder
NULL argument can now be used to create a global namespace {} block.
2015-03-10 15:28:19 +01:00
a2d7e8977a Use real properties for storing subnodes
Instead of storing subnodes in a subNodes dictionary, they are
now stored as simple properties. This requires declarating the
properties, assigning them in the constructor, overriding
the getSubNodeNames() method and passing NULL to the first argument
of the NodeAbstract constructor.

[Deprecated: It's still possible to use the old mode of operation
for custom nodes by passing an array of subnodes to the constructor.]

The only behavior difference this should cause is that getSubNodeNames()
will always return the original subnode names and skip any additional
properties that were dynamically added. E.g. this means that the
"namespacedName" node added by the NameResolver visitor is not treated
as a subnode, but as a dynamic property instead.

This change improves performance and memory usage.
2015-03-09 08:54:20 +01:00
73cace360d Implicit public should not generate as explicit public 2015-03-08 20:21:01 +01:00
c96636d192 Revert "Create .gitattributes with basic export-ignores"
This reverts commit 0dd2b9a74c.

Not having tests available causes issues for downstream
distributors. See issue #178.
2015-03-08 19:38:13 +01:00
d56ff5a351 Fix lexer tests for HHVM
HHVM does not throw warnings from token_get_all()
for invalid chars and unterminated comments. This
is not really integral functionality, so I'm okay
to just skip it to get a passing HHVM build.
2015-02-26 19:19:40 +01:00
3028bc8081 And make it work on PHP 5 as well... 2015-02-26 16:40:21 +01:00
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
d600c60779 Add PHP 7 to travis build 2015-02-26 15:25:34 +01:00
e3bc5b564d Added php shebang 2015-02-24 21:43:12 +01:00
53eac36a3f Merge pull request #175 from staabm/patch-1
prevent a unnecessary concat
2015-02-13 18:03:18 +01:00
ce5c76d79b prevent a unnecessary concat
analog to b7ffdbbb92
2015-02-13 16:02:54 +01:00
b7ffdbbb92 Optimize node dumper
For very deeply nested node trees this extra concatenation makes a
huge difference...
2015-02-13 15:20:25 +01:00
8f1eacdab7 Increase recommended xdebug.max_nesting_level
Looks like 2000 is not quite enough for some cases...
2015-02-13 15:04:00 +01:00
1366e833a1 Move getMethods() to new ClassLike node
Class_, Interface_ and Trait_ extend the ClassLike node, which
provides the getMethods() method.
2015-01-31 22:59:38 +01:00
6930feac43 Add some tests for pretty printing expressions 2015-01-18 19:57:09 +01:00
54275ad181 Merge pull request #167 from GrahamCampbell/patch-1
Fixed branch alias
2015-01-18 12:54:05 +01:00
21ca7eaf1b Fixed branch alias 2015-01-18 11:46:36 +00:00
a86779198f Fix branch alias (maybe?) 2015-01-18 12:41:16 +01:00
ac05ef6f95 Release PHP-Parser 1.1 2015-01-18 12:29:59 +01:00
74251fca9f Update changelog 2015-01-18 00:11:19 +01:00
0a445c7656 Test lexer returning invalid token 2015-01-18 00:11:10 +01:00
a710f32a6a Make Node\Expr\BinOp an abstract class
Only the children should be used ...
2015-01-18 00:10:02 +01:00
9689763e20 Cover both DONT_TRAVERSE_CHILDREN cases 2015-01-18 00:10:01 +01:00
1a63a915f2 Merge pull request #163 from rmruano/gitattributes
Create .gitattributes with basic export-ignores
2015-01-11 22:34:05 +01:00
4071c4645d Add NodeTraverser::DONT_TRAVERSE_CHILDREN support 2015-01-11 22:13:58 +01:00
f56db26d8b Doc fixes 2015-01-11 21:39:02 +01:00
0dd2b9a74c Create .gitattributes with basic export-ignores 2015-01-09 21:19:19 +01:00
4cd2b95a23 Fix 5.3 build and some small cleanups 2014-12-19 18:54:56 +01:00
7ab88416ac Enforce Name|string for names in builders
While array (with name components) could technically be allowed (as
they are supported by the Name node itself), more likely than not
an array would due to incorrect usage of the API (e.g. array instead
of variadics).
2014-12-19 18:50:16 +01:00
ba625063e7 Support fully-qualified and ns-relative names in builders 2014-12-19 18:48:21 +01:00
b4b93ccb21 Add integration test for builders 2014-12-19 18:35:19 +01:00
01643e06d3 Add namespace builder 2014-12-19 18:19:33 +01:00
4387454fe0 Add trait builder (for completeness...) 2014-12-19 17:59:23 +01:00
55fdbc6dbc Extract common builder methods to abstract classes
Declaration for fns/classes in general and FunctionLike for
functions/methods in particular.
2014-12-19 17:47:51 +01:00
e69c9ee38c Fix attribute assigment test with crlf newlines 2014-12-19 17:28:22 +01:00
894c3f787d Add test for attribute assignment by parser
Weird that this wasn't tested yet...
2014-12-19 00:37:38 +01:00
a7797918b8 Update lexer docs for attribute options 2014-12-19 00:37:37 +01:00
46975107a7 Support token position attributes in lexer
Also change endFilePos semantics to refer to the last character that
is *included* in the token, rather than one past the last character.
This ensures that all end* attributes have the same semantics.
2014-12-19 00:37:36 +01:00
e0f3e8a492 Merge pull request #160 from jamiehannaford/patch-1
Fix apostrophe
2014-12-15 14:23:36 +01:00
158322e1e4 Fix apostrophe 2014-12-15 10:05:52 +00:00
2438848487 Add support for doc comments in builders 2014-12-13 13:44:40 +01:00
f5432a76b6 Add a a reference to PrettyPrinter to code generation doc
The `$prettyPrinter` variable was undefined in the doc.

Also, the PrettyPrinter was mentioned as `default`, but it's `Standard`, actually.
2014-12-13 13:06:36 +01:00
800d278369 Merge pull request #152 from Fullmetal5/master
Add line returns in php-parse help message
2014-11-27 21:30:29 +01:00
8507af6f4a Add missing require in tests
Test files aren't autoloaded, so this was order-dependent.
2014-11-27 21:01:56 +01:00
7c98ad6f9b Support file offsets in emulative lexer as well
Also run normal lexer tests against emulative lexer and fix a bug
in __halt_compiler() handling found as a result.
2014-11-27 20:57:38 +01:00
d774dbc1b7 Add optional startFilePos and endFilePos attributes
The lexer can now optionally add startFilePos and endFilePos
attributes, which are offsets in to the lexed code string.

The end offset currently points one past the last character of
the token - this is pending further discussion.

The attributes are not added by default and have to be enabled
using the new 'usedAttributes' lexer option:

	$lexer = new Lexer([
		'usedAttributes' => [
			'comments', 'startLine', 'endLine',
			'startFilePos', 'endFilePos'
		]
	]);
2014-11-27 20:38:29 +01:00
1a93cc3b9d Add line returns
Add line returns to the help message so that the terminal won't end up on the same line.
2014-11-25 19:03:35 -06:00
e26e63e9b0 Error on final or abstract properties 2014-11-13 20:25:52 +01:00
0f69f12b94 Use "public" visibility when not explicitly given
Fixes issue #143
2014-11-13 20:21:21 +01:00
a8ffc6fcfc Release PHP-Parser 1.0.2 2014-11-04 23:12:46 +01:00
7fbdb79a08 Fix whitespace when printing trait alias modifiers 2014-11-03 16:16:15 +01:00
6fad8ff32a Make NameResolver resolve trait alias and precedence names 2014-11-03 16:06:43 +01:00
b9a60372f2 Release version 1.0.1 2014-10-14 21:40:07 +02:00
eb20e32914 Update changelog 2014-10-14 21:37:04 +02:00
f41a4c9acb Fix wrong function name in docs 2014-10-14 21:31:29 +02:00
767f23c3a9 Update lexer docs
Remove some very questionable examples for changing startLexing()
to accept a file name.

Add token offset lexer implementation and usage example.
2014-10-11 21:47:11 +02:00
f8678ad7e9 Merge pull request #138 from jbrooksuk/patch-1
Fixed a spelling mistake
2014-10-01 12:18:18 +02:00
63c18b29e4 Fixed a spelling mistake 2014-10-01 09:18:01 +01:00
99df8b86ae Support HHVM T_ONUMBER token 2014-09-30 20:55:58 +02:00
66fd29cb58 Use stricter assertions where possible 2014-09-30 20:38:09 +02:00
3d40e2217d Annotate some APIs as @internal 2014-09-30 20:26:06 +02:00
16dff7c2e6 Add ability to pass code directly to php-parse.php 2014-09-28 13:14:37 +02:00
88e2d42ba4 Fix var_dump truncation with xdebug in php-parse.php 2014-09-28 13:08:59 +02:00
69701430c1 Cover remaining constant scalar expressions 2014-09-28 13:05:23 +02:00
6dc24fa9f5 Fix coverage annotations 2014-09-28 12:49:12 +02:00
3e1665bbbd Disallow new without a class name
Fixes #137.
2014-09-28 12:41:35 +02:00
2b96ab8edc Release PHP-Parser 1.0.0 2014-09-12 14:48:23 +02:00
7503356e03 Fix typos 2014-09-12 14:44:32 +02:00
22ef0de7ef Add migration guide for 0.9 -> 1.0 2014-09-12 14:40:17 +02:00
5d7fec2027 Mention that composer autoload.php will work as well 2014-09-12 13:51:17 +02:00
6423864160 Add Autoloader tests 2014-09-12 13:45:34 +02:00
fd064dac6c Very that node type is valid in XML unserializer 2014-09-12 00:39:59 +02:00
d9bd550414 Fix XML unserializer 2014-09-12 00:37:21 +02:00
94eca2ce44 Remove deprecated Template and TemplateLoader 2014-09-12 00:25:30 +02:00
e65fd664d1 Small docs touchups and typo fixes 2014-09-12 00:21:27 +02:00
7a3789f1a9 Remove "experimental" message 2014-08-31 17:05:11 +02:00
b31f36bf89 Release PHP-Parser 1.0.0 Beta 2 2014-08-31 16:54:25 +02:00
3d583ab19c Update changelog 2014-08-31 16:39:53 +02:00
616be1d0fc Use emulative lexer for < 5.6RC1
Earlier releases come with incorrect tokenizer data for T_POW and
T_POW_EQUAL.
2014-08-31 16:33:41 +02:00
7c81229261 Disable xdebug var_dump in php-parse script 2014-08-31 16:21:21 +02:00
452e1c0180 Add constant dereferencing, a list-minute 5.6 change 2014-08-31 16:14:36 +02:00
31bc022d0d Merge pull request #124 from sasezaki/patch-1
Add PHP 5.6 to .travis.yml
2014-08-30 12:12:32 +02:00
ce1078bc00 add PHP 5.6 to .travis.yml 2014-08-29 00:44:47 +09:00
6d0589d14f Ensure that special class names are unqualified
Replicates the PHP error message
2014-08-11 22:04:52 +02:00
ef121e690c Preserve case of "static" class name 2014-08-11 21:44:50 +02:00
c0340053d1 Fix case sensitivity for special class names 2014-08-11 21:41:54 +02:00
39f323b5ad Fix classname of Class_ in docblock of BuilderFactory 2014-08-11 20:53:18 +02:00
22c76a3da4 Update changelog 2014-07-23 21:35:24 +02:00
a332352dbc Merge branch '0.9' 2014-07-23 21:24:21 +02:00
ef70767475 Release version 0.9.5 2014-07-23 20:24:17 +02:00
1cecf9efc5 Revert change to NodeTraverserInterface
Only add this method in 1.0, to avoid any BC breaks.
2014-07-23 20:21:42 +02:00
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
6d1f77132c Move Stmt\Namespace_::postprocess() to parser 2014-04-21 12:30:55 +02:00
2e195d7cb2 Make sure that pretty printer preserves whitespace after <?php 2014-04-21 11:15:33 +02:00
947a897238 Make names in the parser more descriptive
And improve the code a tad bit in general.

I left YY2TBLSTATES and YYNLSTATES around, because I don't fully
understand their role in the action double indexing.
2014-04-20 23:05:51 +02:00
1edbc89749 Use normal properties instead of static ones 2014-04-20 00:34:31 +02:00
0faa844a75 Separate parser code from generated data 2014-04-20 00:19:35 +02:00
3db3ad7d1e Add experimental php-parse script
Script supporting dumping, pretty printing, serializing and resolving
names. Intended to help exploring and debugging the node tree.
2014-04-19 23:14:28 +02:00
4743e9b0b8 Update constant scalar expression support 2014-04-19 22:53:13 +02:00
8499696021 Add note about prettyPrintFile() to docs 2014-04-19 22:30:20 +02:00
e4e56511b9 Merge branch '0.9' 2014-04-19 22:26:35 +02:00
5960ecfc10 Disable xdebug.scream while lexing 2014-04-19 22:26:05 +02:00
c341ab2ecf Make autoloader for new names PSR-0 compliant 2014-04-02 09:44:45 +02:00
c62ffedfca Require file only if file exists
Allows usage of class_exists() on undefined classes.
2014-03-27 15:40:08 +01:00
a6d46c17b1 Release PHP-Parser 1.0.0 Beta 1 2014-03-27 14:12:13 +01:00
fa96086a49 Update changelog 2014-03-27 13:43:42 +01:00
4c06b0919a Merge branch '0.9'
Conflicts:
	lib/PhpParser/Template.php
	lib/PhpParser/TemplateLoader.php
2014-03-27 12:53:24 +01:00
8429157ab5 Deprecate templating functionality
Other projects cover this a lot better.
2014-03-27 12:51:13 +01:00
2605b8319e Added support for autoload $prepend 2014-03-27 12:39:30 +01:00
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
b3332184cf Minor cleanups to emulative lexer
Be consistent about version numbers. We'll only emulate until
beta1 of a release, as that's the feature freeze release.
2014-03-27 00:01:39 +01:00
1cb6e1407c Fix ** emulation wrt comments 2014-03-26 23:41:06 +01:00
a5e0bbcb62 Support use function/const in name resolver 2014-03-26 23:28:32 +01:00
3b7829b011 Add support for function and constant import (PHP 5.6) 2014-03-26 22:33:45 +01:00
bea89a0bf2 Add support for constant scalar expressions (PHP 5.6) 2014-03-26 21:48:12 +01:00
cda6f575f0 Add support for pow operator (PHP 5.6) 2014-03-26 19:18:16 +01:00
b5bcfa1168 Add support for argument unpacking (PHP 5.6) 2014-03-26 18:42:46 +01:00
96f1151ab2 Add support for variadic parameters (PHP 5.6) 2014-03-26 18:23:30 +01:00
f5be0d30f7 Guarantee that subnodes are always in the right order 2014-03-22 14:49:56 +01:00
c8c233f900 Correctly pretty print negative floats 2014-03-22 14:24:35 +01:00
8c59f41d02 Remove inline Name[] creations
This ensures that the attributes on the Name nodes are correct.
2014-03-22 14:24:33 +01:00
74efea91d1 Merge pull request #96 from Techworker/patch-1
Adjustment to documentation
2014-02-21 18:19:28 +01:00
70077039b4 Add Scalar\MagicConst->getName()
Return magic constant name, e.g. __CLASS__.

Resolves #95.
2014-02-21 18:16:18 +01:00
558087399f Adjustment to documentation 2014-02-19 23:06:39 +01:00
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
118f28344d Synchronized error messages with native php error messages 2014-02-12 20:19:48 +01:00
523e024ba0 Fix a number of other typos 2014-02-12 17:47:34 +01:00
99e44eb8e1 Merge pull request #94 from llaville/typo-1
Fix path in phpunit.xml.dist
2014-02-12 17:43:44 +01:00
4223e643dc fix typo (see also issue 93 already fixed) 2014-02-12 17:39:57 +01:00
26422257f5 Merge pull request #93 from hason/patch-1
Fix path in rebuildParser.php
2014-02-12 17:36:16 +01:00
d6eac28955 Fixed typo 2014-02-12 14:12:55 +01:00
5cab2a7844 Specify autoloader in composer.json 2014-02-06 21:39:57 +01:00
843aad4382 Fix readme 2014-02-06 20:54:49 +01:00
5e725df892 Update docs to use new names 2014-02-06 20:52:01 +01:00
f82862ec9c Port library to use namespaces, with BC for old names 2014-02-06 20:29:35 +01:00
10e1c1895c Remove 5.2 compatibilty code in some places 2014-02-05 22:37:07 +01:00
0ac054a74f Bump version to 1.0-dev, without PHP 5.2 support 2014-01-26 19:05:00 +01:00
6f36a88993 Ensure no registered error handler will see the 'reset' error 2014-01-24 20:27:42 +01:00
bf9956b634 Merge pull request #86 from GrahamCampbell/travis-tweaks
Run travis tests on hhvm as well
2014-01-20 08:24:18 -08:00
3a5f7d6cae Updated travis.yml 2014-01-20 11:20:54 +00:00
0353c921bd Merge pull request #81 from brikou/Elseif_to_ElseIf
Rename "Elseif" to "ElseIf"
2013-11-27 11:33:56 -08:00
72310dd5a3 s/Elseif/ElseIf/ 2013-11-27 15:05:37 +01:00
7f4ab26732 Fix name resolver (class names are case insensitive) 2013-11-15 20:27:56 +01:00
700847e295 Add NodeTraverser::removeVisitor() 2013-09-28 13:21:30 +02:00
52aa17fa68 Require ext/tokenizer in composer.json 2013-09-27 21:08:51 +02:00
540 changed files with 24441 additions and 12540 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
vendor/
composer.lock
grammar/kmyacc.exe
grammar/y.output

View File

@ -1,7 +1,20 @@
language: php
sudo: false
php:
- 5.2
- 5.3
- 5.4
- 5.5
- 5.4
- 5.5
- 5.6
- 7.0
- nightly
- hhvm
install: composer install --prefer-source
matrix:
allow_failures:
- php: nightly
fast_finish: true
script: vendor/bin/phpunit

View File

@ -1,155 +1,313 @@
Version 0.9.5-dev
Version 2.0.1-dev
-----------------
Nothing yet.
Version 0.9.4 (25.08.2013)
--------------------------
* [PHP 5.5] Add support for `ClassName::class`. This is parsed as an `Expr_ClassConstFetch` with `'class'` being the
constant name.
* Syntax errors now include information on expected tokens and mimic the format of PHP's own (pre 5.4) error messages.
Example:
Old: Unexpected token T_STATIC on line 1
New: Syntax error, unexpected T_STATIC, expecting T_STRING or T_NS_SEPARATOR or '{'
* `PHPParser_PrettyPrinter_Zend` was renamed to `PHPParser_PrettyPrinter_Default` as the default pretty printer only
very loosely applies the Zend Coding Standard. The class `PHPParser_PrettyPrinter_Zend` extends
`PHPParser_PrettyPrinter_Default` to maintain backwards compatibility.
* The pretty printer now prints namespaces in semicolon-style if possible (i.e. if the file does not contain a global
namespace declaration).
* Added `prettyPrintFile(array $stmts)` method which will pretty print a file of statements including the opening
`<?php` tag if it is required. Use of this method will also eliminate the unnecessary `<?php ?>` at the start and end
of files using inline HTML.
* There now is a builder for interfaces (`PHPParser_Builder_Interface`).
* An interface for the node traversation has been added: `PHPParser_NodeTraverserInterface`
* Fix pretty printing of `include` expressions (precedence information was missing).
* Fix "undefined index" notices when generating the expected tokens for a syntax error.
* Improve performance of `PrettyPrinter` construction by no longer using the `uniqid()` function.
Version 0.9.3 (22.11.2012)
Version 2.0.0 (2015-12-04)
--------------------------
* [BC] As `list()` in `foreach` is now supported the structure of list assignments changed:
### Changed
1. There is no longer a dedicated `AssignList` node; instead a normal `Assign` node is used with a `List` as `var`.
2. Nested lists are now `List` nodes too, instead of just arrays.
* String parts of encapsed strings are now represented using `Scalar\EncapsStringPart` nodes.
Previously raw strings were used. This affects the `parts` child of `Scalar\Encaps` and
`Expr\ShellExec`. The change has been done to allow assignment of attributes to encapsed string
parts.
* [BC] As arbitrary expressions are allowed in `empty()` now its subnode was renamed from `var` to `expr`.
Version 2.0.0-beta1 (2015-10-21)
--------------------------------
* [BC] The protected `pSafe()` method in `PrettyPrinterAbstract` was renamed to `pNoIndent()`.
### Fixed
* [PHP 5.5] Add support for arbitrary expressions in `empty()`.
* Fixed issue with too many newlines being stripped at the end of heredoc/nowdoc strings in some
cases. (#227)
* [PHP 5.5] Add support for constant array / string dereferencing.
Examples: `"foo"[2]`, `[1, 2, 3][2]`
### Changed
* [PHP 5.5] Add support for `yield` expressions. This adds a new `Yield` expression type, with subnodes `key` and
`value`.
* Update group use support to be in line with recent PHP 7.0 builds.
* Renamed `php-parse.php` to `php-parse` and registered it as a composer bin.
* Use composer PSR-4 autoloader instead of custom autoloader.
* Specify phpunit as a dev dependency.
* [PHP 5.5] Add support for `finally`. This adds a new `finallyStmts` subnode to the `TryCatch` node. If there is no
finally clause it will be `null`.
### Added
* [PHP 5.5] Add support for `list()` destructuring of `foreach` values.
Example: `foreach ($coords as list($x, $y)) { ... }`
* Added `shortArraySyntax` option to pretty printer, to print all arrays using short syntax.
* Improve pretty printing of expressions by printing less unnecessary parentheses. In particular concatenations are now
printed as `$a . $b . $c . $d . $e` rather than `$a . ($b . ($c . ($d . $e)))`. This is implemented by taking operator
associativity into account. New protected methods added to the pretty printer are `pPrec()`, `pInfixOp()`,
`pPrefixOp()` and `pPostfixOp()`. This also fixes an issue with extraneous parentheses in closure bodies.
Version 2.0.0-alpha1 (2015-07-14)
---------------------------------
* Fix formatting of fall-through `case` statements in the Zend pretty printer.
A more detailed description of backwards incompatible changes can be found in the
[upgrading guide](UPGRADE-2.0.md).
* Fix parsing of `$foo =& new Bar`. It is now properly parsed as `AssignRef` (instead of `Assign`).
### Removed
* Fix assignment of `$endAttributes`. Sometimes the attributes of the token right after the node were assigned, rather
than the attributes of the last token in the node.
* Removed support for running on PHP 5.4. It is however still possible to parse PHP 5.2 and PHP 5.3
code while running on a newer version.
* Removed legacy class name aliases. This includes the old non-namespaced class names and the old
names for classes that were renamed for PHP 7 compatibility.
* Removed support for legacy node format. All nodes must have a `getSubNodeNames()` method now.
* `rebuildParser.php` is now designed to be run from the command line rather than from the browser.
### Added
Version 0.9.2 (07.07.2012)
* Added support for remaining PHP 7 features that were not present in 1.x:
* Group use declarations. These are represented using `Stmt\GroupUse` nodes. Furthermore a `type`
attribute was added to `Stmt\UseUse` to handle mixed group use declarations.
* Uniform variable syntax.
* Generalized yield operator.
* Scalar type declarations. These are presented using `'bool'`, `'int'`, `'float'` and `'string'`
as the type. The PHP 5 parser also accepts these, however they'll be `Name` instances there.
* Unicode escape sequences.
* Added `PhpParser\ParserFactory` class, which should be used to create parser instances.
* Added `Name::concat()` which concatenates two names.
* Added `Name->slice()` which takes a subslice of a name.
### Changed
* `PhpParser\Parser` is now an interface, implemented by `Parser\Php5`, `Parser\Php7` and
`Parser\Multiple`. The `Multiple` parser will try multiple parsers, until one succeeds.
* Token constants are now defined on `PhpParser\Parser\Tokens` rather than `PhpParser\Parser`.
* The `Name->set()`, `Name->append()`, `Name->prepend()` and `Name->setFirst()` methods are
deprecated in favor of `Name::concat()` and `Name->slice()`.
* The `NodeTraverser` no longer clones nodes by default. The old behavior can be restored by
passing `true` to the constructor.
* The constructor for `Scalar` nodes no longer has a default value. E.g. `new LNumber()` should now
be written as `new LNumber(0)`.
Version 1.4.0 (2015-07-14)
--------------------------
* Add `Class->getMethods()` function, which returns all methods contained in the `stmts` array of the class node. This
does not take inherited methods into account.
### Added
* Add `isPublic()`, `isProtected()`, `isPrivate()`. `isAbstract()`, `isFinal()` and `isStatic()` accessors to the
`ClassMethod`, `Property` and `Class` nodes. (`Property` and `Class` obviously only have the accessors relevant to
them.)
* Added interface `PhpParser\Node\FunctionLike`, which is implemented by `Stmt\ClassMethod`,
`Stmt\Function_` and `Expr\Closure` nodes. This interface provides getters for their common
subnodes.
* Added `Node\Stmt\ClassLike::getMethod()` to look up a specific method on a class/interface/trait.
* Fix parsing of new expressions in parentheses, e.g. `return(new Foo);`.
### Fixed
* [BC] Due to the below changes nodes now optionally accept an `$attributes` array as the
last parameter, instead of the previously used `$line` and `$docComment` parameters.
* Fixed `isPublic()` return value for implicitly public properties and methods that define and
additional modifier like `static` or `abstract`.
* Properties are now accepted by the trait builder.
* Fixed `__HALT_COMPILER_OFFSET__` support on HHVM.
* Add mechanism for adding attributes to nodes in the lexer.
The following attributes are now added by default:
* `startLine`: The line the node started in.
* `endLine`: The line the node ended in.
* `comments`: An array of comments. The comments are instances of `PHPParser_Comment`
(or `PHPParser_Comment_Doc` for doc comments).
The methods `getLine()` and `setLine()` still exist and function as before, but internally
operator on the `startLine` attribute.
`getDocComment()` also continues to exist. It returns the last comment in the `comments`
attribute if it is a doc comment, otherwise `null`. As `getDocComment()` now returns a
comment object (which can be modified using `->setText()`) the `setDocComment()` method was
removed. Comment objects implement a `__toString()` method, so `getDocComment()` should
continue to work properly with old code.
* [BC] Use inject-once approach for lexer:
Now the lexer is injected only once when creating the parser. Instead of
$parser = new PHPParser_Parser;
$parser->parse(new PHPParser_Lexer($code));
$parser->parse(new PHPParser_Lexer($code2));
you write:
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$parser->parse($code);
$parser->parse($code2);
* Fix `NameResolver` visitor to also resolve class names in `catch` blocks.
Version 0.9.1 (24.04.2012)
Version 1.3.0 (2015-05-02)
--------------------------
* Add ability to add attributes to nodes:
### Added
It is now possible to add attributes to a node using `$node->setAttribute('name', 'value')` and to retrieve them using
`$node->getAttribute('name' [, 'default'])`. Additionally the existance of an attribute can be checked with
`$node->hasAttribute('name')` and all attributes can be returned using `$node->getAttributes()`.
* Errors can now store the attributes of the node/token where the error occurred. Previously only the start line was
stored.
* If file positions are enabled in the lexer, errors can now provide column information if it is available. See
[documentation](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Error.markdown#column-information).
* The parser now provides an experimental error recovery mode, which can be enabled by disabling the `throwOnError`
parser option. In this mode the parser will try to construct a partial AST even if the code is not valid PHP. See
[documentation](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Error.markdown#error-recovery).
* Added support for PHP 7 `yield from` expression. It is represented by `Expr\YieldFrom`.
* Added support for PHP 7 anonymous classes. These are represented by ordinary `Stmt\Class_` nodes with the name set to
`null`. Furthermore this implies that `Expr\New_` can now contain a `Stmt\Class_` in its `class` subnode.
* Add code generation features: Builders and templates.
### Fixed
For more infos, see the [code generation documentation][1].
* Fixed registration of PHP 7 aliases, for the case where the old name was used before the new name.
* Fixed handling of precedence when pretty-printing `print` expressions.
* Floating point numbers are now pretty-printed with a higher precision.
* Checks for special class names like `self` are now case-insensitive.
* [BC] Don't traverse nodes merged by another visitor:
If a NodeVisitor returns an array of nodes to merge, these will no longer be traversed by all other visitors. This
behavior only caused problems.
* Fix line numbers for some list structures.
* Fix XML unserialization of empty nodes.
* Fix parsing of integers that overflow into floats.
* Fix emulation of NOWDOC and binary floats.
Version 0.9.0 (05.01.2012)
Version 1.2.2 (2015-04-03)
--------------------------
First version.
* The `NameResolver` now resolves parameter type hints when entering the function/method/closure node. As such other
visitors running after it will be able to make use of the resolved names at that point already.
* The autoloader no longer sets the `unserialize_callback_func` ini option on registration - this is not necessary and
may cause issues when running PhpUnit tests with process isolation.
[1]: https://github.com/nikic/PHP-Parser/blob/master/doc/3_Code_generation.markdown
Version 1.2.1 (2015-03-24)
--------------------------
* Fixed registration of the aliases introduced in 1.2.0. Previously the old class names could not be used in
`instanceof` checks under some circumstances.
Version 1.2.0 (2015-03-22)
--------------------------
### Changed
* To ensure compatibility with PHP 7, the following node classes have been renamed:
OLD => NEW
PhpParser\Node\Expr\Cast\Bool => PhpParser\Node\Expr\Cast\Bool_
PhpParser\Node\Expr\Cast\Int => PhpParser\Node\Expr\Cast\Int_
PhpParser\Node\Expr\Cast\Object => PhpParser\Node\Expr\Cast\Object_
PhpParser\Node\Expr\Cast\String => PhpParser\Node\Expr\Cast\String_
PhpParser\Node\Scalar\String => PhpParser\Node\Scalar\String_
**The previous class names are still supported as aliases.** However it is strongly encouraged to use the new names
in order to make your code compatible with PHP 7.
* Subnodes are now stored using real properties instead of an array. This improves performance and memory usage of the
initial parse and subsequent node tree operations. The `NodeAbstract` class still supports the old way of specifying
subnodes, however this is *deprecated*. In any case properties that are assigned to a node after creation will no
longer be considered as subnodes.
* Methods and property declarations will no longer set the `Stmt\Class_::MODIFIER_PUBLIC` flag if no visibility is
explicitly given. However the `isPublic()` method will continue to return true. This allows you to distinguish whether
a method/property is explicitly or implicitly public and control the pretty printer output more precisely.
* The `Stmt\Class_`, `Stmt\Interface_` and `Stmt\Trait_` nodes now inherit from `Stmt\ClassLike`, which provides a
`getMethods()` method. Previously this method was only available on `Stmt\Class_`.
* Support including the `bootstrap.php` file multiple times.
* Make documentation and tests part of the release tarball again.
* Improve support for HHVM and PHP 7.
### Added
* Added support for PHP 7 return type declarations. This adds an additional `returnType` subnode to `Stmt\Function_`,
`Stmt\ClassMethod` and `Expr\Closure`.
* Added support for the PHP 7 null coalesce operator `??`. The operator is represented by `Expr\BinaryOp\Coalesce`.
* Added support for the PHP 7 spaceship operator `<=>`. The operator is represented by `Expr\BinaryOp\Spaceship`.
* Added use builder.
* Added global namespace support to the namespace builder.
* Added a constructor flag to `NodeTraverser`, which disables cloning of nodes.
Version 1.1.0 (2015-01-18)
--------------------------
* Methods that do not specify an explicit visibility (e.g. `function method()`) will now have the `MODIFIER_PUBLIC`
flag set. This also means that their `isPublic()` method will return true.
* Declaring a property as abstract or final is now an error.
* The `Lexer` and `Lexer\Emulative` classes now accept an `$options` array in their constructors. Currently only the
`usedAttributes` option is supported, which determines which attributes will be added to AST nodes. In particular
it is now possible to add information on the token and file positions corresponding to a node. For more details see
the [Lexer component](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Lexer.markdown) documentation.
* Node visitors can now return `NodeTraverser::DONT_TRAVERSE_CHILDREN` from `enterNode()` in order to skip all children
of the current node, for all visitors.
* Added builders for traits and namespaces.
* The class, interface, trait, function, method and property builders now support adding doc comments using the
`setDocComment()` method.
* Added support for fully-qualified and namespace-relative names in builders. No longer allow use of name component
arrays.
* Do not add documentation and tests to distribution archive files.
Version 1.0.2 (2014-11-04)
--------------------------
* The `NameResolver` visitor now also resolves names in trait adaptations (aliases and precedence declarations).
* Remove stray whitespace when pretty-printing trait adaptations that only change visibility.
Version 1.0.1 (2014-10-14)
--------------------------
* Disallow `new` expressions without a class name. Previously `new;` was accidentally considered to be valid code.
* Support T_ONUMBER token used by HHVM.
* Add ability to directly pass code to the `php-parse.php` script.
* Prevent truncation of `var_dump()` output in the `php-parse.php` script if XDebug is used.
Version 1.0.0 (2014-09-12)
--------------------------
* [BC] Removed deprecated `Template` and `TemplateLoader` classes.
* Fixed XML unserializer to properly work with new namespaced node names.
Version 1.0.0-beta2 (2014-08-31)
--------------------------------
* [PHP 5.6] Updated support for constant scalar expressions to comply with latest changes. This means that arrays
and array dimension fetches are now supported as well.
* [PHP 5.6] Direct array dereferencing of constants is supported now, i.e. both `FOO[0]` and `Foo::BAR[0]` are valid
now.
* Fixed handling of special class names (`self`, `parent` and `static`) in the name resolver to be case insensitive.
Additionally the name resolver now enforces that special class names are only used as unqualified names, e.g. `\self`
is considered invalid.
* The case of references to the `static` class name is now preserved. Previously `static` was always lowercased,
regardless of the case used in the source code.
* The autoloader now only requires a file if it exists. This allows usages like
`class_exists('PhpParser\NotExistingClass')`.
* Added experimental `bin/php-parse.php` script, which is intended to help exploring and debugging the node tree.
* Separated the parser implemention (in `lib/PhpParser/ParserAbstract.php`) and the generated data (in
`lib/PhpParser/Parser.php`). Furthermore the parser now uses meaningful variable names and contains comments
explaining their usage.
Version 1.0.0-beta1 (2014-03-27)
--------------------------------
* [BC] PHP-Parser now requires PHP 5.3 or newer to run. It is however still possible to *parse* PHP 5.2 source code,
while running on a newer version.
* [BC] The library has been moved to use namespaces with the `PhpParser` vendor prefix. However, the old names using
underscores are still available as aliases, as such most code should continue running on the new version without
further changes.
However, code performing dispatch operations on `Node::getType()` may be affected by some of the name changes. For
example a `+` node will now return type `Expr_BinaryOp_Plus` instead of `Expr_Plus`. In particular this may affect
custom pretty printers.
Due to conflicts with reserved keywords, some class names now end with an underscore, e.g. `PHPParser_Node_Stmt_Class`
is now `PhpParser\Node\Stmt\Class_`. (But as usual, the old name is still available)
* [PHP 5.6] Added support for the power operator `**` (node `Expr\BinaryOp\Pow`) and the compound power assignment
operator `**=` (node `Expr\AssignOp\Pow`).
* [PHP 5.6] Added support for variadic functions: `Param` nodes now have `variadic` as a boolean subnode.
* [PHP 5.6] Added support for argument unpacking: `Arg` nodes now have `unpack` as a boolean subnode.
* [PHP 5.6] Added support for aliasing of functions and constants. `Stmt\Use_` nodes now have an integral `type`
subnode, which is one of `Stmt\Use_::TYPE_NORMAL` (`use`), `Stmt\Use_::TYPE_FUNCTION` (`use function`) or
`Stmt\Use_::TYPE_CONSTANT` (`use const`).
The `NameResolver` now also supports resolution of such aliases.
* [PHP 5.6] Added support for constant scalar expressions. This means that certain expressions are now allowed as the
initializer for constants, properties, parameters, static variables, etc.
* [BC] Improved pretty printing of empty statements lists, which are now printed as `{\n}` instead of `{\n \n}`.
This changes the behavior of the protected `PrettyPrinterAbstract::pStmts()` method, so custom pretty printing code
making use it of may need to be adjusted.
* Changed the order of some subnodes to be consistent with their order in the sour code. For example `Stmt\If->cond`
will now appear before `Stmt\If->stmts` etc.
* Added `Scalar\MagicConstant->getName()`, which returns the name of the magic constant (e.g. `__CLASS__`).
**The following changes are also included in 0.9.5**:
* [BC] Deprecated `PHPParser_Template` and `PHPParser_TemplateLoader`. This functionality does not belong in the main project
and - as far as I know - nobody is using it.
* Add `NodeTraverser::removeVisitor()` method, which removes a visitor from the node traverser. This also modifies the
corresponding `NodeTraverserInterface`.
* Fix alias resolution in `NameResolver`: Class names are now correctly handled as case-insensitive.
* The undefined variable error, which is used to the lexer to reset the error state, will no longer interfere with
custom error handlers.
---
**This changelog only includes changes from the 1.0 and 2.0 series. For older changes see the
[0.9 series changelog][https://github.com/nikic/PHP-Parser/blob/0.9/CHANGELOG.md].**

View File

@ -1,21 +1,19 @@
PHP Parser
==========
This is a PHP 5.5 (and older) parser written in PHP. It's purpose is to simplify static code analysis and
This is a PHP 5.2 to PHP 7.0 parser written in PHP. Its purpose is to simplify static code analysis and
manipulation.
Documentation can be found in the [`doc/`][1] directory.
***Note: This project is experimental, so the API is subject to change.***
[**Documentation for version 2.x**][doc_master] (stable; for running on PHP >= 5.4; for parsing PHP 5.2 to PHP 7.0).
[Documentation for version 1.x][doc_1_x] (stable; for running on PHP >= 5.3; for parsing PHP 5.2 to PHP 5.6).
In a Nutshell
-------------
Basically, the parser does nothing more than turn some PHP code into an abstract syntax tree. ("nothing
more" is kind of sarcastic here as PHP has a ... uhm, let's just say "not nice" ... grammar, which makes
parsing PHP very hard.)
For example, if you stick this code in the parser:
The parser turns PHP source code into an abstract syntax tree. For example, if you pass the following code into the
parser:
```php
<?php
@ -25,7 +23,7 @@ hello\world('foo', 'bar' . 'baz');
You'll get a syntax tree looking roughly like this:
```
```php
array(
0: Stmt_Echo(
exprs: array(
@ -73,6 +71,25 @@ programming errors or security issues).
Additionally, you can convert a syntax tree back to PHP code. This allows you to do code preprocessing
(like automatedly porting code to older PHP versions).
So, that's it, in a nutshell. You can find everything else in the [docs][1].
Installation
------------
[1]: https://github.com/nikic/PHP-Parser/tree/master/doc
The preferred installation method is [composer](https://getcomposer.org):
php composer.phar require nikic/php-parser
Documentation
-------------
1. [Introduction](doc/0_Introduction.markdown)
2. [Usage of basic components](doc/2_Usage_of_basic_components.markdown)
3. [Other node tree representations](doc/3_Other_node_tree_representations.markdown)
4. [Code generation](doc/4_Code_generation.markdown)
Component documentation:
1. [Error](doc/component/Error.markdown)
2. [Lexer](doc/component/Lexer.markdown)
[doc_1_x]: https://github.com/nikic/PHP-Parser/tree/1.x/doc
[doc_master]: https://github.com/nikic/PHP-Parser/tree/master/doc

121
UPGRADE-1.0.md Normal file
View File

@ -0,0 +1,121 @@
Upgrading from PHP-Parser 0.9 to 1.0
====================================
### PHP version requirements
PHP-Parser now requires PHP 5.3 or newer to run. It is however still possible to *parse* PHP 5.2 source code, while
running on a newer version.
### Move to namespaced names
The library has been moved to use namespaces with the `PhpParser` vendor prefix. However, the old names using
underscores are still available as aliases, as such most code should continue running on the new version without
further changes.
Old (still works, but discouraged):
```php
$parser = new \PHPParser_Parser(new \PHPParser_Lexer_Emulative);
$prettyPrinter = new \PHPParser_PrettyPrinter_Default;
```
New:
```php
$parser = new \PhpParser\Parser(new PhpParser\Lexer\Emulative);
$prettyPrinter = new \PhpParser\PrettyPrinter\Standard;
```
Note that the `PHPParser` prefix was changed to `PhpParser`. While PHP class names are technically case-insensitive,
the autoloader will not be able to load `PHPParser\Parser` or other case variants.
Due to conflicts with reserved keywords, some class names now end with an underscore, e.g. `PHPParser_Node_Stmt_Class`
is now `PhpParser\Node\Stmt\Class_`. (But as usual, the old name is still available.)
### Changes to `Node::getType()`
The `Node::getType()` method continues to return names using underscores instead of namespace separators and also does
not contain the trailing underscore that may be present in the class name. As such its output will not change in many
cases.
However, some node classes have been moved to a different namespace or renamed, which will result in a different
`Node::getType()` output:
```
Expr_AssignBitwiseAnd => Expr_AssignOp_BitwiseAnd
Expr_AssignBitwiseOr => Expr_AssignOp_BitwiseOr
Expr_AssignBitwiseXor => Expr_AssignOp_BitwiseXor
Expr_AssignConcat => Expr_AssignOp_Concat
Expr_AssignDiv => Expr_AssignOp_Div
Expr_AssignMinus => Expr_AssignOp_Minus
Expr_AssignMod => Expr_AssignOp_Mod
Expr_AssignMul => Expr_AssignOp_Mul
Expr_AssignPlus => Expr_AssignOp_Plus
Expr_AssignShiftLeft => Expr_AssignOp_ShiftLeft
Expr_AssignShiftRight => Expr_AssignOp_ShiftRight
Expr_BitwiseAnd => Expr_BinaryOp_BitwiseAnd
Expr_BitwiseOr => Expr_BinaryOp_BitwiseOr
Expr_BitwiseXor => Expr_BinaryOp_BitwiseXor
Expr_BooleanAnd => Expr_BinaryOp_BooleanAnd
Expr_BooleanOr => Expr_BinaryOp_BooleanOr
Expr_Concat => Expr_BinaryOp_Concat
Expr_Div => Expr_BinaryOp_Div
Expr_Equal => Expr_BinaryOp_Equal
Expr_Greater => Expr_BinaryOp_Greater
Expr_GreaterOrEqual => Expr_BinaryOp_GreaterOrEqual
Expr_Identical => Expr_BinaryOp_Identical
Expr_LogicalAnd => Expr_BinaryOp_LogicalAnd
Expr_LogicalOr => Expr_BinaryOp_LogicalOr
Expr_LogicalXor => Expr_BinaryOp_LogicalXor
Expr_Minus => Expr_BinaryOp_Minus
Expr_Mod => Expr_BinaryOp_Mod
Expr_Mul => Expr_BinaryOp_Mul
Expr_NotEqual => Expr_BinaryOp_NotEqual
Expr_NotIdentical => Expr_BinaryOp_NotIdentical
Expr_Plus => Expr_BinaryOp_Plus
Expr_ShiftLeft => Expr_BinaryOp_ShiftLeft
Expr_ShiftRight => Expr_BinaryOp_ShiftRight
Expr_Smaller => Expr_BinaryOp_Smaller
Expr_SmallerOrEqual => Expr_BinaryOp_SmallerOrEqual
Scalar_ClassConst => Scalar_MagicConst_Class
Scalar_DirConst => Scalar_MagicConst_Dir
Scalar_FileConst => Scalar_MagicConst_File
Scalar_FuncConst => Scalar_MagicConst_Function
Scalar_LineConst => Scalar_MagicConst_Line
Scalar_MethodConst => Scalar_MagicConst_Method
Scalar_NSConst => Scalar_MagicConst_Namespace
Scalar_TraitConst => Scalar_MagicConst_Trait
```
These changes may affect custom pretty printers and code comparing the return value of `Node::getType()` to specific
strings.
### Miscellaneous
* The classes `Template` and `TemplateLoader` have been removed. You should use some other [code generation][code_gen]
project built on top of PHP-Parser instead.
* The `PrettyPrinterAbstract::pStmts()` method now emits a leading newline if the statement list is not empty.
Custom pretty printers should remove the explicit newline before `pStmts()` calls.
Old:
```php
public function pStmt_Trait(PHPParser_Node_Stmt_Trait $node) {
return 'trait ' . $node->name
. "\n" . '{' . "\n" . $this->pStmts($node->stmts) . "\n" . '}';
}
```
New:
```php
public function pStmt_Trait(Stmt\Trait_ $node) {
return 'trait ' . $node->name
. "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}';
}
```
[code_gen]: https://github.com/nikic/PHP-Parser/wiki/Projects-using-the-PHP-Parser#code-generation

74
UPGRADE-2.0.md Normal file
View File

@ -0,0 +1,74 @@
Upgrading from PHP-Parser 1.x to 2.0
====================================
### PHP version requirements
PHP-Parser now requires PHP 5.4 or newer to run. It is however still possible to *parse* PHP 5.2 and
PHP 5.3 source code, while running on a newer version.
### Creating a parser instance
Parser instances should now be created through the `ParserFactory`. Old direct instantiation code
will not work, because the parser class was renamed.
Old:
```php
use PhpParser\Parser, PhpParser\Lexer;
$parser = new Parser(new Lexer\Emulative);
```
New:
```php
use PhpParser\ParserFactory;
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
```
The first argument to `ParserFactory` determines how different PHP versions are handled. The
possible values are:
* `ParserFactory::PREFER_PHP7`: Try to parse code as PHP 7. If this fails, try to parse it as PHP 5.
* `ParserFactory::PREFER_PHP5`: Try to parse code as PHP 5. If this fails, try to parse it as PHP 7.
* `ParserFactory::ONLY_PHP7`: Parse code as PHP 7.
* `ParserFactory::ONLY_PHP5`: Parse code as PHP 5.
For most practical purposes the difference between `PREFER_PHP7` and `PREFER_PHP5` is mainly whether
a scalar type hint like `string` will be stored as `'string'` (PHP 7) or as `new Name('string')`
(PHP 5).
To use a custom lexer, pass it as the second argument to the `create()` method:
```php
use PhpParser\ParserFactory;
$lexer = new MyLexer;
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7, $lexer);
```
### Rename of the `PhpParser\Parser` class
`PhpParser\Parser` is now an interface, which is implemented by `Parser\Php5`, `Parser\Php7` and
`Parser\Multiple`. Parser tokens are now defined in `Parser\Tokens`. If you use the `ParserFactory`
described above to create your parser instance, these changes should have no further impact on you.
### Removal of legacy aliases
All legacy aliases for classes have been removed. This includes the old non-namespaced `PHPParser_`
classes, as well as the classes that had to be renamed for PHP 7 support.
### Deprecations
The `set()`, `setFirst()`, `append()` and `prepend()` methods of the `Node\Name` class have been
deprecated. Instead `Name::concat()` and `Name->slice()` should be used.
### Miscellaneous
* The `NodeTraverser` no longer clones nodes by default. If you want to restore the old behavior,
pass `true` to the constructor.
* The legacy node format has been removed. If you use custom nodes, they are now expected to
implement a `getSubNodeNames()` method.
* The default value for `Scalar` node constructors was removed. This means that something like
`new LNumber()` should be replaced by `new LNumber(0)`.
* String parts of encapsed strings are now represented using `Scalar\EncapsStringPart` nodes, while
previously raw strings were used. This affects the `parts` child of `Scalar\Encaps` and
`Expr\ShellExec`.

166
bin/php-parse Normal file
View File

@ -0,0 +1,166 @@
#!/usr/bin/env php
<?php
foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require $file;
break;
}
}
ini_set('xdebug.max_nesting_level', 3000);
// Disable XDebug var_dump() output truncation
ini_set('xdebug.var_display_max_children', -1);
ini_set('xdebug.var_display_max_data', -1);
ini_set('xdebug.var_display_max_depth', -1);
list($operations, $files, $attributes) = parseArgs($argv);
/* Dump nodes by default */
if (empty($operations)) {
$operations[] = 'dump';
}
if (empty($files)) {
showHelp("Must specify at least one file.");
}
$lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array(
'startLine', 'endLine', 'startFilePos', 'endFilePos'
)));
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7, $lexer);
$dumper = new PhpParser\NodeDumper;
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
$serializer = new PhpParser\Serializer\XML;
$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
foreach ($files as $file) {
if (strpos($file, '<?php') === 0) {
$code = $file;
echo "====> Code $code\n";
} else {
if (!file_exists($file)) {
die("File $file does not exist.\n");
}
$code = file_get_contents($file);
echo "====> File $file:\n";
}
try {
$stmts = $parser->parse($code);
} catch (PhpParser\Error $e) {
if ($attributes['with-column-info'] && $e->hasColumnInfo()) {
$startLine = $e->getStartLine();
$endLine = $e->getEndLine();
$startColumn = $e->getStartColumn($code);
$endColumn = $e->getEndColumn($code);
$message .= $e->getRawMessage() . " from $startLine:$startColumn to $endLine:$endColumn";
} else {
$message = $e->getMessage();
}
die($message . "\n");
}
foreach ($operations as $operation) {
if ('dump' === $operation) {
echo "==> Node dump:\n";
echo $dumper->dump($stmts), "\n";
} elseif ('pretty-print' === $operation) {
echo "==> Pretty print:\n";
echo $prettyPrinter->prettyPrintFile($stmts), "\n";
} elseif ('serialize-xml' === $operation) {
echo "==> Serialized XML:\n";
echo $serializer->serialize($stmts), "\n";
} elseif ('var-dump' === $operation) {
echo "==> var_dump():\n";
var_dump($stmts);
} elseif ('resolve-names' === $operation) {
echo "==> Resolved names.\n";
$stmts = $traverser->traverse($stmts);
}
}
}
function showHelp($error) {
die($error . "\n\n" .
<<<OUTPUT
Usage: php-parse [operations] file1.php [file2.php ...]
or: php-parse [operations] "<?php code"
Turn PHP source code into an abstract syntax tree.
Operations is a list of the following options (--dump by default):
-d, --dump Dump nodes using NodeDumper
-p, --pretty-print Pretty print file using PrettyPrinter\Standard
--serialize-xml Serialize nodes using Serializer\XML
--var-dump var_dump() nodes (for exact structure)
-N, --resolve-names Resolve names using NodeVisitor\NameResolver
-c, --with-column-info Show column-numbers for errors (if available)
Example:
php-parse -d -p -N -d file.php
Dumps nodes, pretty prints them, then resolves names and dumps them again.
OUTPUT
);
}
function parseArgs($args) {
$operations = array();
$files = array();
$attributes = array(
'with-column-info' => false,
);
array_shift($args);
$parseOptions = true;
foreach ($args as $arg) {
if (!$parseOptions) {
$files[] = $arg;
continue;
}
switch ($arg) {
case '--dump':
case '-d':
$operations[] = 'dump';
break;
case '--pretty-print':
case '-p':
$operations[] = 'pretty-print';
break;
case '--serialize-xml':
$operations[] = 'serialize-xml';
break;
case '--var-dump':
$operations[] = 'var-dump';
break;
case '--resolve-names':
case '-N';
$operations[] = 'resolve-names';
break;
case '--with-column-info':
case '-c';
$attributes['with-column-info'] = true;
break;
case '--':
$parseOptions = false;
break;
default:
if ($arg[0] === '-') {
showHelp("Invalid operation $arg.");
} else {
$files[] = $arg;
}
}
}
return array($operations, $files, $attributes);
}

View File

@ -10,14 +10,21 @@
}
],
"require": {
"php": ">=5.2"
"php": ">=5.4",
"ext-tokenizer": "*"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-0": { "PHPParser": "lib/" }
"psr-4": {
"PhpParser\\": "lib/PhpParser"
}
},
"bin": ["bin/php-parse"],
"extra": {
"branch-alias": {
"dev-master": "0.9-dev"
"dev-master": "2.0-dev"
}
}
}

View File

@ -1,16 +1,16 @@
Introduction
============
This project is a PHP 5.5 (and older) parser **written in PHP itself**.
This project is a PHP 5.2 to PHP 7.0 parser **written in PHP itself**.
What is this for?
-----------------
A parser is useful for [static analysis][0] and manipulation of code and basically any other
A parser is useful for [static analysis][0], manipulation of code and basically any other
application dealing with code programmatically. A parser constructs an [Abstract Syntax Tree][1]
(AST) of the code and thus allows dealing with it in an abstract and robust way.
There are other ways of dealing with source code. One that PHP supports natively is using the
There are other ways of processing source code. One that PHP supports natively is using the
token stream generated by [`token_get_all`][2]. The token stream is much more low level than
the AST and thus has different applications: It allows to also analyze the exact formatting of
a file. On the other hand the token stream is much harder to deal with for more complex analysis.
@ -26,13 +26,12 @@ programmatic PHP code analysis are incidentally PHP developers, not C developers
What can it parse?
------------------
The parser uses a PHP 5.5 compliant grammar, which is backwards compatible with at least PHP 5.4, PHP 5.3
and PHP 5.2 (and maybe older).
The parser supports parsing PHP 5.2-5.6 and PHP 7.
As the parser is based on the tokens returned by `token_get_all` (which is only able to lex the PHP
version it runs on), additionally a wrapper for emulating new tokens from 5.3, 5.4 and 5.5 is provided. This
allows to parse PHP 5.5 source code running on PHP 5.2, for example. This emulation is very hacky and not
yet perfect, but it should work well on any sane code.
version it runs on), additionally a wrapper for emulating new tokens from 5.5, 5.6 and 7.0 is
provided. This allows to parse PHP 7.0 source code running on PHP 5.4, for example. This emulation
is somewhat hacky and not perfect, but it should work well on any sane code.
What output does it produce?
----------------------------
@ -56,7 +55,7 @@ array(
)
```
This matches the semantics the program had: An echo statement, which takes two strings as expressions,
This matches the structure of the code: An echo statement, which takes two strings as expressions,
with the values `Hi` and `World!`.
You can also see that the AST does not contain any whitespace information (but most comments are saved).
@ -78,4 +77,4 @@ Apart from the parser itself this package also bundles support for some other, r
[0]: http://en.wikipedia.org/wiki/Static_program_analysis
[1]: http://en.wikipedia.org/wiki/Abstract_syntax_tree
[2]: http://php.net/token_get_all
[2]: http://php.net/token_get_all

View File

@ -1,48 +0,0 @@
Installation
============
There are multiple ways to include the PHP parser into your project:
Installing from the Zip- or Tarball
-----------------------------------
Download the latest version from [the download page][2], unpack it and move the files somewhere into your project.
Installing via Composer
-----------------------
Create a `composer.json` file in your project root and use it to define your dependencies:
{
"require": {
"nikic/php-parser": "0.9.4"
}
}
Then install Composer in your project (or [download the composer.phar][1] directly):
curl -s http://getcomposer.org/installer | php
And finally ask Composer to install the dependencies:
php composer.phar install
Installing as a PEAR package
----------------------------
Run the following two commands:
pear channel-discover nikic.github.com/pear
pear install nikic/PHPParser-0.9.4
Installing as a Git Submodule
-----------------------------
Run the following command to install the parser into the `vendor/PHP-Parser` folder:
git submodule add git://github.com/nikic/PHP-Parser.git vendor/PHP-Parser
[1]: http://getcomposer.org/composer.phar
[2]: https://github.com/nikic/PHP-Parser/tags

View File

@ -6,19 +6,16 @@ This document explains how to use the parser, the pretty printer and the node tr
Bootstrapping
-------------
The library needs to register a class autoloader; this is done by including the
`bootstrap.php` file:
To bootstrap the library, include the autoloader generated by composer:
```php
<?php
require 'path/to/PHP-Parser/lib/bootstrap.php';
require 'path/to/vendor/autoload.php';
```
Additionally you may want to set the `xdebug.max_nesting_level` ini option to a higher value:
```php
<?php
ini_set('xdebug.max_nesting_level', 2000);
ini_set('xdebug.max_nesting_level', 3000);
```
This ensures that there will be no errors when traversing highly nested node trees.
@ -26,31 +23,46 @@ This ensures that there will be no errors when traversing highly nested node tre
Parsing
-------
In order to parse some source code you first have to create a `PHPParser_Parser` object (which
needs to be passed a `PHPParser_Lexer` instance) and then pass the code (including `<?php` opening
tags) to the `parse` method. If a syntax error is encountered `PHPParser_Error` is thrown, so this
exception should be `catch`ed.
In order to parse code, you first have to create a parser instance:
```php
<?php
$code = '<?php // some code';
use PhpParser\ParserFactory;
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
```
$parser = new PHPParser_Parser(new PHPParser_Lexer);
The factory accepts a kind argument, that determines how different PHP versions are treated:
Kind | Behavior
-----|---------
`ParserFactory::PREFER_PHP7` | Try to parse code as PHP 7. If this fails, try to parse it as PHP 5.
`ParserFactory::PREFER_PHP5` | Try to parse code as PHP 5. If this fails, try to parse it as PHP 7.
`ParserFactory::ONLY_PHP7` | Parse code as PHP 7.
`ParserFactory::ONLY_PHP5` | Parse code as PHP 5.
Unless you have strong reason to use something else, `PREFER_PHP7` is a reasonable default.
The `create()` method optionally accepts a `Lexer` instance as the second argument. Some use cases
that require customized lexers are discussed in the [lexer documentation](component/Lexer.markdown).
Subsequently you can pass PHP code (including the opening `<?php` tag) to the `parse` method in order to
create a syntax tree. If a syntax error is encountered, an `PhpParser\Error` exception will be thrown:
```php
use PhpParser\Error;
use PhpParser\ParserFactory;
$code = '<?php // some code';
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
try {
$stmts = $parser->parse($code);
} catch (PHPParser_Error $e) {
// $stmts is an array of statement nodes
} catch (Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
```
The `parse` method will return an array of statement nodes (`$stmts`).
### Emulative lexer
Instead of `PHPParser_Lexer` one can also use `PHPParser_Lexer_Emulative`. This class will emulate tokens
of newer PHP versions and as such allow parsing PHP 5.5 on PHP 5.2, for example. So if you want to parse
PHP code of newer versions than the one you are running, you should use the emulative lexer.
A parser instance can be reused to parse multiple files.
Node tree
---------
@ -81,37 +93,41 @@ array(
```
Thus `$stmts` will contain an array with only one node, with this node being an instance of
`PHPParser_Node_Stmt_Echo`.
`PhpParser\Node\Stmt\Echo_`.
As PHP is a large language there are approximately 140 different nodes. In order to make work
with them easier they are grouped into three categories:
* `PHPParser_Node_Stmt`s are statement nodes, i.e. language constructs that do not return
* `PhpParser\Node\Stmt`s are statement nodes, i.e. language constructs that do not return
a value and can not occur in an expression. For example a class definition is a statement.
It doesn't return a value and you can't write something like `func(class A {});`.
* `PHPParser_Node_Expr`s are expression nodes, i.e. language constructs that return a value
* `PhpParser\Node\Expr`s are expression nodes, i.e. language constructs that return a value
and thus can occur in other expressions. Examples of expressions are `$var`
(`PHPParser_Node_Expr_Variable`) and `func()` (`PHPParser_Node_Expr_FuncCall`).
* `PHPParser_Node_Scalar`s are nodes representing scalar values, like `'string'`
(`PHPParser_Node_Scalar_String`), `0` (`PHPParser_Node_Scalar_LNumber`) or magic constants
like `__FILE__` (`PHPParser_Node_Scalar_FileConst`). All `PHPParser_Node_Scalar`s extend
`PHPParser_Node_Expr`, as scalars are expressions, too.
* There are some nodes not in either of these groups, for example names (`PHPParser_Node_Name`)
and call arguments (`PHPParser_Node_Arg`).
(`PhpParser\Node\Expr\Variable`) and `func()` (`PhpParser\Node\Expr\FuncCall`).
* `PhpParser\Node\Scalar`s are nodes representing scalar values, like `'string'`
(`PhpParser\Node\Scalar\String_`), `0` (`PhpParser\Node\Scalar\LNumber`) or magic constants
like `__FILE__` (`PhpParser\Node\Scalar\MagicConst\File`). All `PhpParser\Node\Scalar`s extend
`PhpParser\Node\Expr`, as scalars are expressions, too.
* There are some nodes not in either of these groups, for example names (`PhpParser\Node\Name`)
and call arguments (`PhpParser\Node\Arg`).
Some node class names have a trailing `_`. This is used whenever the class name would otherwise clash
with a PHP keyword.
Every node has a (possibly zero) number of subnodes. You can access subnodes by writing
`$node->subNodeName`. The `Stmt_Echo` node has only one subnode `exprs`. So in order to access it
in the above example you would write `$stmts[0]->exprs`. If you wanted to access name of the function
`$node->subNodeName`. The `Stmt\Echo_` node has only one subnode `exprs`. So in order to access it
in the above example you would write `$stmts[0]->exprs`. If you wanted to access the name of the function
call, you would write `$stmts[0]->exprs[1]->name`.
All nodes also define a `getType()` method that returns the node type (the type is the class name
without the `PHPParser_Node_` prefix).
All nodes also define a `getType()` method that returns the node type. The type is the class name
without the `PhpParser\Node\` prefix and `\` replaced with `_`. It also does not contain a trailing
`_` for reserved-keyword class names.
It is possible to associate custom metadata with a node using the `setAttribute()` method. This data
can then be retrieved using `hasAttribute()`, `getAttribute()` and `getAttributes()`.
By default the lexer adds the `startLine`, `endLine` and `comments` attributes. `comments` is an array
of `PHPParser_Comment[_Doc]` instances.
of `PhpParser\Comment[\Doc]` instances.
The start line can also be accessed using `getLine()`/`setLine()` (instead of `getAttribute('startLine')`).
The last doc comment from the `comments` attribute can be obtained using `getDocComment()`.
@ -121,14 +137,17 @@ Pretty printer
The pretty printer component compiles the AST back to PHP code. As the parser does not retain formatting
information the formatting is done using a specified scheme. Currently there is only one scheme available,
namely `PHPParser_PrettyPrinter_Default`.
namely `PhpParser\PrettyPrinter\Standard`.
```php
<?php
use PhpParser\Error;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter;
$code = "<?php echo 'Hi ', hi\\getTarget();";
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$prettyPrinter = new PHPParser_PrettyPrinter_Default;
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$prettyPrinter = new PrettyPrinter\Standard;
try {
// parse
@ -139,26 +158,29 @@ try {
->exprs // sub expressions
[0] // the first of them (the string node)
->value // it's value, i.e. 'Hi '
= 'Hallo '; // change to 'Hallo '
= 'Hello '; // change to 'Hello '
// pretty print
$code = '<?php ' . $prettyPrinter->prettyPrint($stmts);
$code = $prettyPrinter->prettyPrint($stmts);
echo $code;
} catch (PHPParser_Error $e) {
} catch (Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
```
The above code will output:
<?php echo 'Hallo ', hi\getTarget();
<?php echo 'Hello ', hi\getTarget();
As you can see the source code was first parsed using `PHPParser_Parser->parse`, then changed and then
again converted to code using `PHPParser_PrettyPrinter_Default->prettyPrint`.
As you can see the source code was first parsed using `PhpParser\Parser->parse()`, then changed and then
again converted to code using `PhpParser\PrettyPrinter\Standard->prettyPrint()`.
The `prettyPrint` method pretty prints a statements array. It is also possible to pretty print only a
single expression using `prettyPrintExpr`.
The `prettyPrint()` method pretty prints a statements array. It is also possible to pretty print only a
single expression using `prettyPrintExpr()`.
The `prettyPrintFile()` method can be used to print an entire file. This will include the opening `<?php` tag
and handle inline HTML as the first/last statement more gracefully.
Node traversation
-----------------
@ -169,20 +191,23 @@ Usually you want to change / analyze code in a generic way, where you don't know
going to look like.
For this purpose the parser provides a component for traversing and visiting the node tree. The basic
structure of a program using this `PHPParser_NodeTraverser` looks like this:
structure of a program using this `PhpParser\NodeTraverser` looks like this:
```php
<?php
$code = "<?php // some code";
use PhpParser\NodeTraverser;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter;
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$traverser = new PHPParser_NodeTraverser;
$prettyPrinter = new PHPParser_PrettyPrinter_Default;
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$traverser = new NodeTraverser;
$prettyPrinter = new PrettyPrinter\Standard;
// add your visitor
$traverser->addVisitor(new MyNodeVisitor);
try {
$code = file_get_contents($fileName);
// parse
$stmts = $parser->parse($code);
@ -190,22 +215,24 @@ try {
$stmts = $traverser->traverse($stmts);
// pretty print
$code = '<?php ' . $prettyPrinter->prettyPrint($stmts);
$code = $prettyPrinter->prettyPrintFile($stmts);
echo $code;
} catch (PHPParser_Error $e) {
} catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
```
A same node visitor for this code might look like this:
The corresponding node visitor might look like this:
```php
<?php
class MyNodeVisitor extends PHPParser_NodeVisitorAbstract
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
class MyNodeVisitor extends NodeVisitorAbstract
{
public function leaveNode(PHPParser_Node $node) {
if ($node instanceof PHPParser_Node_Scalar_String) {
public function leaveNode(Node $node) {
if ($node instanceof Node\Scalar\String_) {
$node->value = 'foo';
}
}
@ -214,30 +241,37 @@ class MyNodeVisitor extends PHPParser_NodeVisitorAbstract
The above node visitor would change all string literals in the program to `'foo'`.
All visitors must implement the `PHPParser_NodeVisitor` interface, which defined the following four
All visitors must implement the `PhpParser\NodeVisitor` interface, which defines the following four
methods:
public function beforeTraverse(array $nodes);
public function enterNode(PHPParser_Node $node);
public function leaveNode(PHPParser_Node $node);
public function afterTraverse(array $nodes);
```php
public function beforeTraverse(array $nodes);
public function enterNode(\PhpParser\Node $node);
public function leaveNode(\PhpParser\Node $node);
public function afterTraverse(array $nodes);
```
The `beforeTraverse` method is called once before the traversal begins and is passed the nodes the
The `beforeTraverse()` method is called once before the traversal begins and is passed the nodes the
traverser was called with. This method can be used for resetting values before traversation or
preparing the tree for traversal.
The `afterTraverse` method is similar to the `beforeTraverse` method, with the only difference that
The `afterTraverse()` method is similar to the `beforeTraverse()` method, with the only difference that
it is called once after the traversal.
The `enterNode` and `leaveNode` methods are called on every node, the former when it is entered,
The `enterNode()` and `leaveNode()` methods are called on every node, the former when it is entered,
i.e. before its subnodes are traversed, the latter when it is left.
All four methods can either return the changed node or not return at all (i.e. `null`) in which
case the current node is not changed. The `leaveNode` method can furthermore return two special
values: If `false` is returned the current node will be removed from the parent array. If an `array`
is returned the current node will be merged into the parent array at the offset of the current node.
I.e. if in `array(A, B, C)` the node `B` should be replaced with `array(X, Y, Z)` the result will be
`array(A, X, Y, Z, C)`.
case the current node is not changed.
The `enterNode()` method can additionally return the value `NodeTraverser::DONT_TRAVERSE_CHILDREN`,
which instructs the traverser to skip all children of the current node.
The `leaveNode()` method can additionally return the value `NodeTraverser::REMOVE_NODE`, in which
case the current node will be removed from the parent array. Furthermove it is possible to return
an array of nodes, which will be merged into the parent array at the offset of the current node.
I.e. if in `array(A, B, C)` the node `B` should be replaced with `array(X, Y, Z)` the result will
be `array(A, X, Y, Z, C)`.
Instead of manually implementing the `NodeVisitor` interface you can also extend the `NodeVisitorAbstract`
class, which will define empty default implementations for all the above methods.
@ -245,7 +279,7 @@ class, which will define empty default implementations for all the above methods
The NameResolver node visitor
-----------------------------
One visitor is already bundled with the package: `PHPParser_NodeVisitor_NameResolver`. This visitor
One visitor is already bundled with the package: `PhpParser\NodeVisitor\NameResolver`. This visitor
helps you work with namespaced code by trying to resolve most names to fully qualified ones.
For example, consider the following code:
@ -275,21 +309,24 @@ assume that no dynamic features are used.
We start off with the following base code:
```php
<?php
const IN_DIR = '/some/path';
const OUT_DIR = '/some/other/path';
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
// use the emulative lexer here, as we are running PHP 5.2 but want to parse PHP 5.3
$parser = new PHPParser_Parser(new PHPParser_Lexer_Emulative);
$traverser = new PHPParser_NodeTraverser;
$prettyPrinter = new PHPParser_PrettyPrinter_Default;
$inDir = '/some/path';
$outDir = '/some/other/path';
$traverser->addVisitor(new PHPParser_NodeVisitor_NameResolver); // we will need resolved names
$traverser->addVisitor(new NodeVisitor_NamespaceConverter); // our own node visitor
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$traverser = new NodeTraverser;
$prettyPrinter = new PrettyPrinter\Standard;
$traverser->addVisitor(new NameResolver); // we will need resolved names
$traverser->addVisitor(new NamespaceConverter); // our own node visitor
// iterate over all .php files in the directory
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(IN_DIR));
$files = new RegexIterator($files, '/\.php$/');
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($inDir));
$files = new \RegexIterator($files, '/\.php$/');
foreach ($files as $file) {
try {
@ -303,56 +340,59 @@ foreach ($files as $file) {
$stmts = $traverser->traverse($stmts);
// pretty print
$code = '<?php ' . $prettyPrinter->prettyPrint($stmts);
$code = $prettyPrinter->prettyPrintFile($stmts);
// write the converted file to the target directory
file_put_contents(
substr_replace($file->getPathname(), OUT_DIR, 0, strlen(IN_DIR)),
substr_replace($file->getPathname(), $outDir, 0, strlen($inDir)),
$code
);
} catch (PHPParser_Error $e) {
} catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
}
```
Now lets start with the main code, the `NodeVisitor_NamespaceConverter`. One thing it needs to do
Now lets start with the main code, the `NodeVisitor\NamespaceConverter`. One thing it needs to do
is convert `A\\B` style names to `A_B` style ones.
```php
<?php
class NodeVisitor_NamespaceConverter extends PHPParser_NodeVisitorAbstract
use PhpParser\Node;
class NamespaceConverter extends \PhpParser\NodeVisitorAbstract
{
public function leaveNode(PHPParser_Node $node) {
if ($node instanceof PHPParser_Node_Name) {
return new PHPParser_Node_Name($node->toString('_'));
public function leaveNode(Node $node) {
if ($node instanceof Node\Name) {
return new Node\Name($node->toString('_'));
}
}
}
```
The above code profits from the fact that the `NameResolver` already resolved all names as far as
possible, so we don't need to do that. All the need to create a string with the name parts separated
possible, so we don't need to do that. We only need to create a string with the name parts separated
by underscores instead of backslashes. This is what `$node->toString('_')` does. (If you want to
create a name with backslashes either write `$node->toString()` or `(string) $node`.) Then we create
a new name from the string and return it. Returning a new node replaces the old node.
Another thing we need to do is change the class/function/const declarations. Currently they contain
only the shortname (i.e. the last part of the name), but they need to contain the complete class
name:
only the shortname (i.e. the last part of the name), but they need to contain the complete name inclduing
the namespace prefix:
```php
<?php
class NodeVisitor_NamespaceConverter extends PHPParser_NodeVisitorAbstract
use PhpParser\Node;
use PhpParser\Node\Stmt;
class NodeVisitor_NamespaceConverter extends \PhpParser\NodeVisitorAbstract
{
public function leaveNode(PHPParser_Node $node) {
if ($node instanceof PHPParser_Node_Name) {
return new PHPParser_Node_Name($node->toString('_'));
} elseif ($node instanceof PHPParser_Node_Stmt_Class
|| $node instanceof PHPParser_Node_Stmt_Interface
|| $node instanceof PHPParser_Node_Stmt_Function) {
public function leaveNode(Node $node) {
if ($node instanceof Node\Name) {
return new Node\Name($node->toString('_'));
} elseif ($node instanceof Stmt\Class_
|| $node instanceof Stmt\Interface_
|| $node instanceof Stmt\Function_) {
$node->name = $node->namespacedName->toString('_');
} elseif ($node instanceof PHPParser_Node_Stmt_Const) {
} elseif ($node instanceof Stmt\Const_) {
foreach ($node->consts as $const) {
$const->name = $const->namespacedName->toString('_');
}
@ -366,24 +406,26 @@ There is not much more to it than converting the namespaced name to string with
The last thing we need to do is remove the `namespace` and `use` statements:
```php
<?php
class NodeVisitor_NamespaceConverter extends PHPParser_NodeVisitorAbstract
use PhpParser\Node;
use PhpParser\Node\Stmt;
class NodeVisitor_NamespaceConverter extends \PhpParser\NodeVisitorAbstract
{
public function leaveNode(PHPParser_Node $node) {
if ($node instanceof PHPParser_Node_Name) {
return new PHPParser_Node_Name($node->toString('_'));
} elseif ($node instanceof PHPParser_Node_Stmt_Class
|| $node instanceof PHPParser_Node_Stmt_Interface
|| $node instanceof PHPParser_Node_Stmt_Function) {
public function leaveNode(Node $node) {
if ($node instanceof Node\Name) {
return new Node\Name($node->toString('_'));
} elseif ($node instanceof Stmt\Class_
|| $node instanceof Stmt\Interface_
|| $node instanceof Stmt\Function_) {
$node->name = $node->namespacedName->toString('_');
} elseif ($node instanceof PHPParser_Node_Stmt_Const) {
} elseif ($node instanceof Stmt\Const_) {
foreach ($node->consts as $const) {
$const->name = $const->namespacedName->toString('_');
}
} elseif ($node instanceof PHPParser_Node_Stmt_Namespace) {
} elseif ($node instanceof Stmt\Namespace_) {
// returning an array merges is into the parent array
return $node->stmts;
} elseif ($node instanceof PHPParser_Node_Stmt_Use) {
} elseif ($node instanceof Stmt\Use_) {
// returning false removed the node altogether
return false;
}
@ -391,4 +433,4 @@ class NodeVisitor_NamespaceConverter extends PHPParser_NodeVisitorAbstract
}
```
That's all.
That's all.

View File

@ -1,7 +1,7 @@
Other node tree representations
===============================
It is possible to convert the AST in several textual representations, which serve different uses.
It is possible to convert the AST into several textual representations, which serve different uses.
Simple serialization
--------------------
@ -13,33 +13,33 @@ but PHP, but it is compact and generates fast. The main application thus is in c
Human readable dumping
----------------------
Furthermore it is possible to dump nodes into a human readable form using the `dump` method of
`PHPParser_NodeDumper`. This can be used for debugging.
Furthermore it is possible to dump nodes into a human readable format using the `dump` method of
`PhpParser\NodeDumper`. This can be used for debugging.
```php
<?php
$code = <<<'CODE'
<?php
function printLine($msg) {
echo $msg, "\n";
}
printLine('Hallo World!!!');
function printLine($msg) {
echo $msg, "\n";
}
printLine('Hello World!!!');
CODE;
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$nodeDumper = new PHPParser_NodeDumper;
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7);
$nodeDumper = new PhpParser\NodeDumper;
try {
$stmts = $parser->parse($code);
echo '<pre>' . htmlspecialchars($nodeDumper->dump($stmts)) . '</pre>';
} catch (PHPParser_Error $e) {
echo $nodeDumper->dump($stmts), "\n";
} catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
```
The above output will have an output looking roughly like this:
The above script will have an output looking roughly like this:
```
array(
@ -77,7 +77,7 @@ array(
args: array(
0: Arg(
value: Scalar_String(
value: Hallo World!!!
value: Hello World!!!
)
byRef: false
)
@ -89,29 +89,30 @@ array(
Serialization to XML
--------------------
It is also possible to serialize the node tree to XML using `PHPParser_Serializer_XML->serialize()`
and to unserialize it using `PHPParser_Unserializer_XML->unserialize()`. This is useful for
It is also possible to serialize the node tree to XML using `PhpParser\Serializer\XML->serialize()`
and to unserialize it using `PhpParser\Unserializer\XML->unserialize()`. This is useful for
interfacing with other languages and applications or for doing transformation using XSLT.
```php
<?php
$code = <<<'CODE'
<?php
function printLine($msg) {
echo $msg, "\n";
}
printLine('Hallo World!!!');
function printLine($msg) {
echo $msg, "\n";
}
printLine('Hello World!!!');
CODE;
$parser = new PHPParser_Parser(new PHPParser_Lexer);
$serializer = new PHPParser_Serializer_XML;
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7);
$serializer = new PhpParser\Serializer\XML;
try {
$stmts = $parser->parse($code);
echo '<pre>' . htmlspecialchars($serializer->serialize($stmts)) . '</pre>';
} catch (PHPParser_Error $e) {
echo $serializer->serialize($stmts);
} catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
```
@ -185,7 +186,7 @@ Produces:
<subNode:value>
<node:Scalar_String line="6">
<subNode:value>
<scalar:string>Hallo World!!!</scalar:string>
<scalar:string>Hello World!!!</scalar:string>
</subNode:value>
</node:Scalar_String>
</subNode:value>

View File

@ -2,264 +2,82 @@ Code generation
===============
It is also possible to generate code using the parser, by first creating an Abstract Syntax Tree and then using the
pretty printer to convert it to PHP code. To simplify code generation, the project comes with a set of builders for
common structures as well as simple templating support. Both features are described in the following:
pretty printer to convert it to PHP code. To simplify code generation, the project comes with builders which allow
creating node trees using a fluid interface, instead of instantiating all nodes manually. Builders are available for
the following syntactic elements:
Builders
--------
The project provides builders for classes, interfaces, methods, functions, parameters and properties, which
allow creating node trees with a fluid interface, instead of instantiating all nodes manually.
* namespaces and use statements
* classes, interfaces and traits
* methods, functions and parameters
* properties
Here is an example:
```php
<?php
$factory = new PHPParser_BuilderFactory;
$node = $factory->class('SomeClass')
->extend('SomeOtherClass')
->implement('A\Few', 'Interfaces')
->makeAbstract() // ->makeFinal()
use PhpParser\BuilderFactory;
use PhpParser\PrettyPrinter;
use PhpParser\Node;
->addStmt($factory->method('someMethod')
$factory = new BuilderFactory;
$node = $factory->namespace('Name\Space')
->addStmt($factory->use('Some\Other\Thingy')->as('SomeOtherClass'))
->addStmt($factory->class('SomeClass')
->extend('SomeOtherClass')
->implement('A\Few', '\Interfaces')
->makeAbstract() // ->makeFinal()
->addParam($factory->param('someParam')->setTypeHint('SomeClass'))
)
->addStmt($factory->method('anotherMethod')
->makeProtected() // ->makePublic() [default], ->makePrivate()
->addParam($factory->param('someParam')->setDefault('test'))
// it is possible to add manually created nodes
->addStmt(new PHPParser_Node_Expr_Print(new PHPParser_Node_Expr_Variable('someParam')))
)
->addStmt($factory->method('someMethod')
->makePublic()
->makeAbstract() // ->makeFinal()
->addParam($factory->param('someParam')->setTypeHint('SomeClass'))
->setDocComment('/**
* This method does something.
*
* @param SomeClass And takes a parameter
*/')
)
// properties will be correctly reordered above the methods
->addStmt($factory->property('someProperty')->makeProtected())
->addStmt($factory->property('anotherProperty')->makePrivate()->setDefault(array(1, 2, 3)))
->addStmt($factory->method('anotherMethod')
->makeProtected() // ->makePublic() [default], ->makePrivate()
->addParam($factory->param('someParam')->setDefault('test'))
// it is possible to add manually created nodes
->addStmt(new Node\Expr\Print_(new Node\Expr\Variable('someParam')))
)
// properties will be correctly reordered above the methods
->addStmt($factory->property('someProperty')->makeProtected())
->addStmt($factory->property('anotherProperty')->makePrivate()->setDefault(array(1, 2, 3)))
)
->getNode()
;
$stmts = array($node);
echo $prettyPrinter->prettyPrint($stmts);
$prettyPrinter = new PrettyPrinter\Standard();
echo $prettyPrinter->prettyPrintFile($stmts);
```
This will produce the following output with the default pretty printer:
This will produce the following output with the standard pretty printer:
```php
<?php
abstract class SomeClass extends SomeOtherClass implements A\Few, Interfaces
namespace Name\Space;
use Some\Other\Thingy as SomeClass;
abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces
{
protected $someProperty;
private $anotherProperty = array(1, 2, 3);
abstract function someMethod(SomeClass $someParam);
/**
* This method does something.
*
* @param SomeClass And takes a parameter
*/
public abstract function someMethod(SomeClass $someParam);
protected function anotherMethod($someParam = 'test')
{
print $someParam;
}
}
```
Templates
---------
Additionally it is possible to generate code from reusable templates.
As an example consider the following template, which defines a general getter/setter skeleton in terms of a property
`__name__` and its `__type__`:
```php
<?php
class GetterSetterTemplate
{
/**
* @var __type__ The __name__
*/
protected $__name__;
/**
* Gets the __name__.
*
* @return __type__ The __name__
*/
public function get__Name__() {
return $this->__name__;
}
/**
* Sets the __name__.
*
* @param __type__ $__name__ The new __name__
*/
public function set__Name__($__name__) {
$this->__name__ = $__name__;
}
}
```
Using this template we can easily create a class with multiple properties and their respective getters and setters:
```php
<?php
// $templateString contains the above template
$template = new PHPParser_Template($parser, $templateString);
// We only have to specify the __name__ placeholder, as the
// capitalized __Name__ placeholder is automatically created
$properties = [
['name' => 'title', 'type' => 'string'],
['name' => 'body', 'type' => 'string'],
['name' => 'author', 'type' => 'User'],
['name' => 'timestamp', 'type' => 'DateTime'],
];
$class = $factory->class('BlogPost')->implement('Post');
foreach ($properties as $propertyPlaceholders) {
$stmts = $template->getStmts($propertyPlaceholders);
$class->addStmts(
// $stmts contains all statements from the template. So [0] fetches the class statement
// and ->stmts retrieves the methods.
$stmts[0]->stmts
);
}
echo $prettyPrinter->prettyPrint(array($class->getNode()));
```
The result would look roughly like this:
```php
<?php
class BlogPost implements Post
{
/**
* @var string The title
*/
protected $title;
/**
* @var string The body
*/
protected $body;
/**
* @var User The author
*/
protected $author;
/**
* @var DateTime The timestamp
*/
protected $timestamp;
/**
* Gets the title.
*
* @return string The title
*/
public function getTitle()
{
return $this->title;
}
/**
* Sets the title.
*
* @param string $title The new title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Gets the body.
*
* @return string The body
*/
public function getBody()
{
return $this->body;
}
/**
* Sets the body.
*
* @param string $body The new body
*/
public function setBody($body)
{
$this->body = $body;
}
/**
* Gets the author.
*
* @return User The author
*/
public function getAuthor()
{
return $this->author;
}
/**
* Sets the author.
*
* @param User $author The new author
*/
public function setAuthor($author)
{
$this->author = $author;
}
/**
* Gets the timestamp.
*
* @return DateTime The timestamp
*/
public function getTimestamp()
{
return $this->timestamp;
}
/**
* Sets the timestamp.
*
* @param DateTime $timestamp The new timestamp
*/
public function setTimestamp($timestamp)
{
$this->timestamp = $timestamp;
}
}
```
When using multiple templates it is easier to manage them on the filesystem. They can be loaded using the
`TemplateLoader`:
```php
<?php
// We'll store our templates in ./templates and give them a .php suffix
$loader = new PHPParser_TemplateLoader($parser, './templates', '.php');
// loads ./templates/GetterSetter.php
$getterSetterTemplate = $loader->load('GetterSetter');
// loads ./templates/Collection.php
$collectionTemplate = $loader->load('Collection');
// The use of a suffix is optional. The following code for example is equivalent:
$loader = new PHPParser_TemplateLoader($parser, './templates');
// loads ./templates/GetterSetter.php
$getterSetterTemplate = $loader->load('GetterSetter.php');
// loads ./templates/Collection.php
$collectionTemplate = $loader->load('Collection.php');
```

View File

@ -0,0 +1,77 @@
Error handling
==============
Errors during parsing or analysis are represented using the `PhpParser\Error` exception class. In addition to an error
message, an error can also store additional information about the location the error occurred at.
How much location information is available depends on the origin of the error and how many lexer attributes have been
enabled. At a minimum the start line of the error is usually available.
Column information
------------------
In order to receive information about not only the line, but also the column span an error occurred at, the file
position attributes in the lexer need to be enabled:
```php
$lexer = new PhpParser\Lexer(array(
'usedAttributes' => array('comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos'),
));
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7, $lexer);
try {
$stmts = $parser->parse($code);
// ...
} catch (PhpParser\Error $e) {
// ...
}
```
Before using column information its availability needs to be checked with `$e->hasColumnInfo()`, as the precise
location of an error cannot always be determined. The methods for retrieving column information also have to be passed
the source code of the parsed file. An example for printing an error:
```php
if ($e->hasColumnInfo()) {
echo $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code)
. ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code);
} else {
echo $e->getMessage();
}
```
Both line numbers and column numbers are 1-based. EOF errors will be located at the position one past the end of the
file.
Error recovery
--------------
> **EXPERIMENTAL**
By default the parser will throw an exception upon encountering the first error during parsing. An alternative mode is
also supported, in which the parser will remember the error, but try to continue parsing the rest of the source code.
To enable this mode the `throwOnError` parser option needs to be disabled. Any errors that occurred during parsing can
then be retrieved using `$parser->getErrors()`. The `$parser->parse()` method will either return a partial syntax tree
or `null` if recovery fails.
A usage example:
```php
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7, null, array(
'throwOnError' => false,
));
$stmts = $parser->parse($code);
$errors = $parser->getErrors();
foreach ($errors as $error) {
// $error is an ordinary PhpParser\Error
}
if (null !== $stmts) {
// $stmts is a best-effort partial AST
}
```
The error recovery implementation is experimental -- it currently won't be able to recover from many types of errors.

View File

@ -1,51 +1,119 @@
Lexer component documentation
=============================
The lexer is responsible for providing tokens to the parser. The project comes with two lexers: `PHPParser_Lexer` and
`PHPParser_Lexer_Emulative`. The latter is an extension of the former, which adds the ability to emulate tokens of
The lexer is responsible for providing tokens to the parser. The project comes with two lexers: `PhpParser\Lexer` and
`PhpParser\Lexer\Emulative`. The latter is an extension of the former, which adds the ability to emulate tokens of
newer PHP versions and thus allows parsing of new code on older versions.
A lexer has to define the following public interface:
This documentation discusses options available for the default lexers and explains how lexers can be extended.
startLexing($code);
getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null);
handleHaltCompiler();
Lexer options
-------------
startLexing
-----------
The `startLexing` method is invoked when the `parse()` method of the parser is called. It's argument will be whatever
was passed to the `parse()` method.
Even though `startLexing` is meant to accept a source code string, you could for example overwrite it to accept a file:
The two default lexers accept an `$options` array in the constructor. Currently only the `'usedAttributes'` option is
supported, which allows you to specify which attributes will be added to the AST nodes. The attributes can then be
accessed using `$node->getAttribute()`, `$node->setAttribute()`, `$node->hasAttribute()` and `$node->getAttributes()`
methods. A sample options array:
```php
<?php
$lexer = new PhpParser\Lexer(array(
'usedAttributes' => array(
'comments', 'startLine', 'endLine'
)
));
```
class FileLexer extends PHPParser_Lexer {
public function startLexing($fileName) {
if (!file_exists($fileName)) {
throw new InvalidArgumentException(sprintf('File "%s" does not exist', $fileName));
The attributes used in this example match the default behavior of the lexer. The following attributes are supported:
* `comments`: Array of `PhpParser\Comment` or `PhpParser\Comment\Doc` instances, representing all comments that occurred
between the previous non-discarded token and the current one. Use of this attribute is required for the
`$node->getDocComment()` method to work. The attribute is also needed if you wish the pretty printer to retain
comments present in the original code.
* `startLine`: Line in which the node starts. This attribute is required for the `$node->getLine()` to work. It is also
required if syntax errors should contain line number information.
* `endLine`: Line in which the node ends.
* `startTokenPos`: Offset into the token array of the first token in the node.
* `endTokenPos`: Offset into the token array of the last token in the node.
* `startFilePos`: Offset into the code string of the first character that is part of the node.
* `endFilePos`: Offset into the code string of the last character that is part of the node.
### Using token positions
The token offset information is useful if you wish to examine the exact formatting used for a node. For example the AST
does not distinguish whether a property was declared using `public` or using `var`, but you can retrieve this
information based on the token position:
```php
function isDeclaredUsingVar(array $tokens, PhpParser\Node\Stmt\Property $prop) {
$i = $prop->getAttribute('startTokenPos');
return $tokens[$i][0] === T_VAR;
}
```
In order to make use of this function, you will have to provide the tokens from the lexer to your node visitor using
code similar to the following:
```php
class MyNodeVisitor extends PhpParser\NodeVisitorAbstract {
private $tokens;
public function setTokens(array $tokens) {
$this->tokens = $tokens;
}
public function leaveNode(PhpParser\Node $node) {
if ($node instanceof PhpParser\Node\Stmt\Property) {
var_dump(isDeclaredUsingVar($this->tokens, $node));
}
parent::startLexing(file_get_contents($fileName));
}
}
$parser = new PHPParser_Parser(new FileLexer);
$lexer = new PhpParser\Lexer(array(
'usedAttributes' => array(
'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos'
)
));
$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7, $lexer);
var_dump($parser->parse('someFile.php'));
var_dump($parser->parse('someOtherFile.php'));
$visitor = new MyNodeVisitor();
$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor($visitor);
try {
$stmts = $parser->parse($code);
$visitor->setTokens($lexer->getTokens());
$stmts = $traverser->traverse($stmts);
} catch (PhpParser\Error $e) {
echo 'Parse Error: ', $e->getMessage();
}
```
getNextToken
------------
The same approach can also be used to perform specific modifications in the code, without changing the formatting in
other places (which is the case when using the pretty printer).
`getNextToken` returns the ID of the next token and sets some additional information in the three variables which it
accepts by-ref. If no more tokens are available it has to return `0`, which is the ID of the `EOF` token.
Lexer extension
---------------
The first by-ref variable `$value` should contain the textual content of the token. It is what will be available as `$1`
etc in the parser.
A lexer has to define the following public interface:
void startLexing(string $code);
array getTokens();
string handleHaltCompiler();
int getNextToken(string &$value = null, array &$startAttributes = null, array &$endAttributes = null);
The `startLexing()` method is invoked with the source code that is to be lexed (including the opening tag) whenever the
`parse()` method of the parser is called. It can be used to reset state or preprocess the source code or tokens.
The `getTokens()` method returns the current token array, in the usual `token_get_all()` format. This method is not
used by the parser (which uses `getNextToken()`), but is useful in combination with the token position attributes.
The `handleHaltCompiler()` method is called whenever a `T_HALT_COMPILER` token is encountered. It has to return the
remaining string after the construct (not including `();`).
The `getNextToken()` method returns the ID of the next token (as defined by the `Parser::T_*` constants). If no more
tokens are available it must return `0`, which is the ID of the `EOF` token. Furthermore the string content of the
token should be written into the by-reference `$value` parameter (which will then be available as `$n` in the parser).
### Attribute handling
The other two by-ref variables `$startAttributes` and `$endAttributes` define which attributes will eventually be
assigned to the generated nodes: The parser will take the `$startAttributes` from the first token which is part of the
@ -54,61 +122,28 @@ node and the `$endAttributes` from the last token that is part of the node.
E.g. if the tokens `T_FUNCTION T_STRING ... '{' ... '}'` constitute a node, then the `$startAttributes` from the
`T_FUNCTION` token will be taken and the `$endAttributes` from the `'}'` token.
By default the lexer creates the attributes `startLine`, `comments` (both part of `$startAttributes`) and `endLine`
(part of `$endAttributes`).
If you don't want all these attributes to be added (to reduce memory usage of the AST) you can simply remove them by
overriding the method:
An application of custom attributes is storing the original formatting of literals: The parser does not retain
information about the formatting of integers (like decimal vs. hexadecimal) or strings (like used quote type or used
escape sequences). This can be remedied by storing the original value in an attribute:
```php
<?php
use PhpParser\Lexer;
use PhpParser\Parser\Tokens;
class LessAttributesLexer extends PHPParser_Lexer {
class KeepOriginalValueLexer extends Lexer // or Lexer\Emulative
{
public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) {
$tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);
// only keep startLine attribute
unset($startAttributes['comments']);
unset($endAttributes['endLine']);
return $tokenId;
}
}
```
You can obviously also add additional attributes. E.g. in conjunction with the above `FileLexer` you might want to add
a `fileName` attribute to all nodes:
```php
<?php
class FileLexer extends PHPParser_Lexer {
protected $fileName;
public function startLexing($fileName) {
if (!file_exists($fileName)) {
throw new InvalidArgumentException(sprintf('File "%s" does not exist', $fileName));
if ($tokenId == Tokens::T_CONSTANT_ENCAPSED_STRING // non-interpolated string
|| $tokenId == Tokens::T_LNUMBER // integer
|| $tokenId == Tokens::T_DNUMBER // floating point number
) {
// could also use $startAttributes, doesn't really matter here
$endAttributes['originalValue'] = $value;
}
$this->fileName = $fileName;
parent::startLexing(file_get_contents($fileName));
}
public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) {
$tokenId = parent::getNextToken($value, $startAttributes, $endAttributes);
// we could use either $startAttributes or $endAttributes here, because the fileName is always the same
// (regardless of whether it is the start or end token). We choose $endAttributes, because it is slightly
// more efficient (as the parser has to keep a stack for the $startAttributes).
$endAttributes['fileName'] = $fileName;
return $tokenId;
}
}
```
handleHaltCompiler
------------------
The method is invoked whenever a `T_HALT_COMPILER` token is encountered. It has to return the remaining string after the
construct (not including `();`).

View File

@ -1,23 +1,23 @@
What do all those files mean?
=============================
* `zend_language_parser.phpy`: PHP grammer written in a pseudo language
* `analyze.php`: Analyzes the `.phpy`-grammer and outputs some info about it
* `rebuildParser.php`: Preprocesses the `.phpy`-grammar and builds the parser using `kmyacc`
* `kmyacc.php.parser`: A `kmyacc` parser prototype file for PHP
* `php5.y`: PHP 5 grammar written in a pseudo language
* `php7.y`: PHP 7 grammar written in a pseudo language
* `tokens.y`: Tokens definition shared between PHP 5 and PHP 7 grammars
* `parser.template`: A `kmyacc` parser prototype file for PHP
* `tokens.template`: A `kmyacc` prototype file for the `Tokens` class
* `analyze.php`: Analyzes the grammer and outputs some info about it
* `rebuildParser.php`: Preprocesses the grammar and builds the parser using `kmyacc`
.phpy pseudo language
=====================
The `.phpy` file is a normal grammer in `kmyacc` (`yacc`) style, with some transformations
The `.y` file is a normal grammer in `kmyacc` (`yacc`) style, with some transformations
applied to it:
* Nodes are created using the syntax `Name[..., ...]`. This is transformed into
`new PHPParser_Node_Name(..., ..., $attributes)`
* `Name::abc` is transformed to `PHPParser_Node_Name::abc`
`new Name(..., ..., attributes())`
* Some function-like constructs are resolved (see `rebuildParser.php` for a list)
* Associative arrays are written as `[key: value, ...]`, which is transformed to
`array('key' => value, ...)`
Building the parser
===================
@ -25,5 +25,5 @@ Building the parser
In order to rebuild the parser, you need [moriyoshi's fork of kmyacc](https://github.com/moriyoshi/kmyacc-forked).
After you compiled/installed it, run the `rebuildParser.php` script.
By default only the `Parser.php` is built. If you want to additionally build `Parser/Debug.php` and `y.output` run the
script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`.
By default only the `Parser.php` is built. If you want to additionally emit debug symbols and create `y.output`, run the
script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`.

View File

@ -1,6 +1,6 @@
<?php
const GRAMMAR_FILE = './zend_language_parser.phpy';
const GRAMMAR_FILE = './php5.y';
const LIB = '(?(DEFINE)
(?<singleQuotedString>\'[^\\\\\']*+(?:\\\\.[^\\\\\']*+)*+\')
@ -93,4 +93,4 @@ foreach ($ruleBlocksMatches as $match) {
}
echo $ruleBlockName, ':', "\n", ' ', implode("\n" . ' | ', $rules), "\n", ';', "\n\n";
}
}

View File

@ -1,361 +0,0 @@
<?php
$meta #
#semval($) $this->yyval
#semval($,%t) $this->yyval
#semval(%n) $this->yyastk[$this->stackPos-(%l-%n)]
#semval(%n,%t) $this->yyastk[$this->stackPos-(%l-%n)]
#include;
/* This is an automatically GENERATED file, which should not be manually edited.
* Instead edit one of the following:
* * the grammar file grammar/zend_language_parser.phpy
* * the parser skeleton grammar/kymacc.php.parser
* * the preprocessing script grammar/rebuildParser.php
*
* The skeleton for this parser was written by Moriyoshi Koizumi and is based on
* the work by Masato Bito and is in the PUBLIC DOMAIN.
*/
#if -t
class #(-p)_Debug extends #(-p)
#endif
#ifnot -t
class #(-p)
#endif
{
#ifnot -t
const TOKEN_NONE = -1;
const TOKEN_INVALID = #(YYBADCH);
const TOKEN_MAP_SIZE = #(YYMAXLEX);
const YYLAST = #(YYLAST);
const YY2TBLSTATE = #(YY2TBLSTATE);
const YYGLAST = #(YYGLAST);
const YYNLSTATES = #(YYNLSTATES);
const YYUNEXPECTED = #(YYUNEXPECTED);
const YYDEFAULT = #(YYDEFAULT);
// {{{ Tokens
#tokenval
const %s = %n;
#endtokenval
// }}}
/* @var array Map of token ids to their respective names */
protected static $terminals = array(
#listvar terminals
, "???"
);
/* @var array Map which translates lexer tokens to internal tokens */
protected static $translate = array(
#listvar yytranslate
);
protected static $yyaction = array(
#listvar yyaction
);
protected static $yycheck = array(
#listvar yycheck
);
protected static $yybase = array(
#listvar yybase
);
protected static $yydefault = array(
#listvar yydefault
);
protected static $yygoto = array(
#listvar yygoto
);
protected static $yygcheck = array(
#listvar yygcheck
);
protected static $yygbase = array(
#listvar yygbase
);
protected static $yygdefault = array(
#listvar yygdefault
);
protected static $yylhs = array(
#listvar yylhs
);
protected static $yylen = array(
#listvar yylen
);
protected $yyval;
protected $yyastk;
protected $stackPos;
protected $lexer;
/**
* Creates a parser instance.
*
* @param PHPParser_Lexer $lexer A lexer
*/
public function __construct(PHPParser_Lexer $lexer) {
$this->lexer = $lexer;
}
#endif
#if -t
protected static $yyproduction = array(
#production-strings;
);
protected function yyprintln($msg) {
echo $msg, "\n";
}
protected function YYTRACE_NEWSTATE($state, $tokenId) {
$this->yyprintln(
'% State ' . $state
. ', Lookahead ' . ($tokenId == self::TOKEN_NONE ? '--none--' : self::$terminals[$tokenId])
);
}
protected function YYTRACE_READ($tokenId) {
$this->yyprintln('% Reading ' . self::$terminals[$tokenId]);
}
protected function YYTRACE_SHIFT($tokenId) {
$this->yyprintln('% Shift ' . self::$terminals[$tokenId]);
}
protected function YYTRACE_ACCEPT() {
$this->yyprintln('% Accepted.');
}
protected function YYTRACE_REDUCE($n) {
$this->yyprintln('% Reduce by (' . $n . ') ' . self::$yyproduction[$n]);
}
protected function YYTRACE_POP($state) {
$this->yyprintln('% Recovering, uncovers state ' . $state);
}
protected function YYTRACE_DISCARD($tokenId) {
$this->yyprintln('% Discard ' . self::$terminals[$tokenId]);
}
#endif
/**
#ifnot -t
* Parses PHP code into a node tree.
#endif
#if -t
* Parses PHP code into a node tree and prints out debugging information.
#endif
*
* @param string $code The source code to parse
*
* @return PHPParser_Node[] Array of statements
*/
public function parse($code) {
$this->lexer->startLexing($code);
// We start off with no lookahead-token
$tokenId = self::TOKEN_NONE;
// The attributes for a node are taken from the first and last token of the node.
// From the first token only the startAttributes are taken and from the last only
// the endAttributes. Both are merged using the array union operator (+).
$startAttributes = array('startLine' => 1);
$endAttributes = array();
// In order to figure out the attributes for the starting token, we have to keep
// them in a stack
$attributeStack = array($startAttributes);
// Start off in the initial state and keep a stack of previous states
$state = 0;
$stateStack = array($state);
// AST stack (?)
$this->yyastk = array();
// Current position in the stack(s)
$this->stackPos = 0;
for (;;) {
#if -t
$this->YYTRACE_NEWSTATE($state, $tokenId);
#endif
if (self::$yybase[$state] == 0) {
$yyn = self::$yydefault[$state];
} else {
if ($tokenId === self::TOKEN_NONE) {
// Fetch the next token id from the lexer and fetch additional info by-ref.
// The end attributes are fetched into a temporary variable and only set once the token is really
// shifted (not during read). Otherwise you would sometimes get off-by-one errors, when a rule is
// reduced after a token was read but not yet shifted.
$origTokenId = $this->lexer->getNextToken($tokenValue, $startAttributes, $nextEndAttributes);
// map the lexer token id to the internally used token id's
$tokenId = $origTokenId >= 0 && $origTokenId < self::TOKEN_MAP_SIZE
? self::$translate[$origTokenId]
: self::TOKEN_INVALID;
if ($tokenId === self::TOKEN_INVALID) {
throw new RangeException(sprintf(
'The lexer returned an invalid token (id=%d, value=%s)',
$origTokenId, $tokenValue
));
}
$attributeStack[$this->stackPos] = $startAttributes;
#if -t
$this->YYTRACE_READ($tokenId);
#endif
}
if ((($yyn = self::$yybase[$state] + $tokenId) >= 0
&& $yyn < self::YYLAST && self::$yycheck[$yyn] == $tokenId
|| ($state < self::YY2TBLSTATE
&& ($yyn = self::$yybase[$state + self::YYNLSTATES] + $tokenId) >= 0
&& $yyn < self::YYLAST
&& self::$yycheck[$yyn] == $tokenId))
&& ($yyn = self::$yyaction[$yyn]) != self::YYDEFAULT) {
/*
* >= YYNLSTATE: shift and reduce
* > 0: shift
* = 0: accept
* < 0: reduce
* = -YYUNEXPECTED: error
*/
if ($yyn > 0) {
/* shift */
#if -t
$this->YYTRACE_SHIFT($tokenId);
#endif
++$this->stackPos;
$stateStack[$this->stackPos] = $state = $yyn;
$this->yyastk[$this->stackPos] = $tokenValue;
$attributeStack[$this->stackPos] = $startAttributes;
$endAttributes = $nextEndAttributes;
$tokenId = self::TOKEN_NONE;
if ($yyn < self::YYNLSTATES)
continue;
/* $yyn >= YYNLSTATES means shift-and-reduce */
$yyn -= self::YYNLSTATES;
} else {
$yyn = -$yyn;
}
} else {
$yyn = self::$yydefault[$state];
}
}
for (;;) {
/* reduce/error */
if ($yyn == 0) {
/* accept */
#if -t
$this->YYTRACE_ACCEPT();
#endif
return $this->yyval;
} elseif ($yyn != self::YYUNEXPECTED) {
/* reduce */
#if -t
$this->YYTRACE_REDUCE($yyn);
#endif
try {
$this->{'yyn' . $yyn}(
$attributeStack[$this->stackPos - self::$yylen[$yyn]]
+ $endAttributes
);
} catch (PHPParser_Error $e) {
if (-1 === $e->getRawLine()) {
$e->setRawLine($startAttributes['startLine']);
}
throw $e;
}
/* Goto - shift nonterminal */
$this->stackPos -= self::$yylen[$yyn];
$yyn = self::$yylhs[$yyn];
if (($yyp = self::$yygbase[$yyn] + $stateStack[$this->stackPos]) >= 0
&& $yyp < self::YYGLAST
&& self::$yygcheck[$yyp] == $yyn) {
$state = self::$yygoto[$yyp];
} else {
$state = self::$yygdefault[$yyn];
}
++$this->stackPos;
$stateStack[$this->stackPos] = $state;
$this->yyastk[$this->stackPos] = $this->yyval;
$attributeStack[$this->stackPos] = $startAttributes;
} else {
/* error */
$expected = array();
$base = self::$yybase[$state];
for ($i = 0; $i < self::TOKEN_MAP_SIZE; ++$i) {
$n = $base + $i;
if ($n >= 0 && $n < self::YYLAST && self::$yycheck[$n] == $i
|| $state < self::YY2TBLSTATE
&& ($n = self::$yybase[$state + self::YYNLSTATES] + $i) >= 0
&& $n < self::YYLAST && self::$yycheck[$n] == $i
) {
if (self::$yyaction[$n] != self::YYUNEXPECTED) {
if (count($expected) == 4) {
/* Too many expected tokens */
$expected = array();
break;
}
$expected[] = self::$terminals[$i];
}
}
}
$expectedString = '';
if ($expected) {
$expectedString = ', expecting ' . implode(' or ', $expected);
}
throw new PHPParser_Error(
'Syntax error, unexpected ' . self::$terminals[$tokenId] . $expectedString,
$startAttributes['startLine']
);
}
if ($state < self::YYNLSTATES)
break;
/* >= YYNLSTATES means shift-and-reduce */
$yyn = $state - self::YYNLSTATES;
}
}
}
#ifnot -t
#reduce
protected function yyn%n($attributes) {
%b
}
#noact
protected function yyn%n() {
$this->yyval = $this->yyastk[$this->stackPos];
}
#endreduce
#endif
}
#tailcode;

103
grammar/parser.template Normal file
View File

@ -0,0 +1,103 @@
<?php
$meta #
#semval($) $this->semValue
#semval($,%t) $this->semValue
#semval(%n) $this->stackPos-(%l-%n)
#semval(%n,%t) $this->stackPos-(%l-%n)
namespace PhpParser\Parser;
use PhpParser\Error;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Stmt;
#include;
/* This is an automatically GENERATED file, which should not be manually edited.
* Instead edit one of the following:
* * the grammar files grammar/php5.y or grammar/php7.y
* * the skeleton file grammar/parser.template
* * the preprocessing script grammar/rebuildParsers.php
*/
class #(-p) extends \PhpParser\ParserAbstract
{
protected $tokenToSymbolMapSize = #(YYMAXLEX);
protected $actionTableSize = #(YYLAST);
protected $gotoTableSize = #(YYGLAST);
protected $invalidSymbol = #(YYBADCH);
protected $errorSymbol = #(YYINTERRTOK);
protected $defaultAction = #(YYDEFAULT);
protected $unexpectedTokenRule = #(YYUNEXPECTED);
protected $YY2TBLSTATE = #(YY2TBLSTATE);
protected $YYNLSTATES = #(YYNLSTATES);
protected $symbolToName = array(
#listvar terminals
);
protected $tokenToSymbol = array(
#listvar yytranslate
);
protected $action = array(
#listvar yyaction
);
protected $actionCheck = array(
#listvar yycheck
);
protected $actionBase = array(
#listvar yybase
);
protected $actionDefault = array(
#listvar yydefault
);
protected $goto = array(
#listvar yygoto
);
protected $gotoCheck = array(
#listvar yygcheck
);
protected $gotoBase = array(
#listvar yygbase
);
protected $gotoDefault = array(
#listvar yygdefault
);
protected $ruleToNonTerminal = array(
#listvar yylhs
);
protected $ruleToLength = array(
#listvar yylen
);
#if -t
protected $productions = array(
#production-strings;
);
#endif
#reduce
protected function reduceRule%n() {
%b
}
#noact
protected function reduceRule%n() {
$this->semValue = $this->semStack[$this->stackPos];
}
#endreduce
}
#tailcode;

File diff suppressed because it is too large Load Diff

813
grammar/php7.y Normal file
View File

@ -0,0 +1,813 @@
%pure_parser
%expect 2
%tokens
%%
start:
top_statement_list { $$ = $this->handleNamespaces($1); }
;
top_statement_list:
top_statement_list top_statement { pushNormalizing($1, $2); }
| /* empty */ { init(); }
;
reserved_non_modifiers:
T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND
| T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE
| T_ENDWHILE | T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH
| T_FINALLY | T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT
| T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
;
semi_reserved:
reserved_non_modifiers
| T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC
;
identifier:
T_STRING { $$ = $1; }
| semi_reserved { $$ = $1; }
;
namespace_name_parts:
T_STRING { init($1); }
| namespace_name_parts T_NS_SEPARATOR T_STRING { push($1, $3); }
;
namespace_name:
namespace_name_parts { $$ = Name[$1]; }
;
top_statement:
statement { $$ = $1; }
| function_declaration_statement { $$ = $1; }
| class_declaration_statement { $$ = $1; }
| T_HALT_COMPILER
{ $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; }
| T_NAMESPACE namespace_name ';' { $$ = Stmt\Namespace_[$2, null]; }
| T_NAMESPACE namespace_name '{' top_statement_list '}' { $$ = Stmt\Namespace_[$2, $4]; }
| T_NAMESPACE '{' top_statement_list '}' { $$ = Stmt\Namespace_[null, $3]; }
| T_USE use_declarations ';' { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; }
| T_USE use_type use_declarations ';' { $$ = Stmt\Use_[$3, $2]; }
| group_use_declaration ';' { $$ = $1; }
| T_CONST constant_declaration_list ';' { $$ = Stmt\Const_[$2]; }
;
use_type:
T_FUNCTION { $$ = Stmt\Use_::TYPE_FUNCTION; }
| T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; }
;
/* Using namespace_name_parts here to avoid s/r conflict on T_NS_SEPARATOR */
group_use_declaration:
T_USE use_type namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
{ $$ = Stmt\GroupUse[Name[$3], $6, $2]; }
| T_USE use_type T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
{ $$ = Stmt\GroupUse[Name[$4], $7, $2]; }
| T_USE namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
{ $$ = Stmt\GroupUse[Name[$2], $5, Stmt\Use_::TYPE_UNKNOWN]; }
| T_USE T_NS_SEPARATOR namespace_name_parts T_NS_SEPARATOR '{' inline_use_declarations '}'
{ $$ = Stmt\GroupUse[Name[$3], $6, Stmt\Use_::TYPE_UNKNOWN]; }
;
unprefixed_use_declarations:
unprefixed_use_declarations ',' unprefixed_use_declaration
{ push($1, $3); }
| unprefixed_use_declaration { init($1); }
;
use_declarations:
use_declarations ',' use_declaration { push($1, $3); }
| use_declaration { init($1); }
;
inline_use_declarations:
inline_use_declarations ',' inline_use_declaration { push($1, $3); }
| inline_use_declaration { init($1); }
;
unprefixed_use_declaration:
namespace_name { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; }
| namespace_name T_AS T_STRING { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; }
;
use_declaration:
unprefixed_use_declaration { $$ = $1; }
| T_NS_SEPARATOR unprefixed_use_declaration { $$ = $2; }
;
inline_use_declaration:
unprefixed_use_declaration { $$ = $1; $$->type = Stmt\Use_::TYPE_NORMAL; }
| use_type unprefixed_use_declaration { $$ = $2; $$->type = $1; }
;
constant_declaration_list:
constant_declaration_list ',' constant_declaration { push($1, $3); }
| constant_declaration { init($1); }
;
constant_declaration:
T_STRING '=' expr { $$ = Node\Const_[$1, $3]; }
;
class_const_list:
class_const_list ',' class_const { push($1, $3); }
| class_const { init($1); }
;
class_const:
identifier '=' expr { $$ = Node\Const_[$1, $3]; }
;
inner_statement_list:
inner_statement_list inner_statement { pushNormalizing($1, $2); }
| /* empty */ { init(); }
;
inner_statement:
statement { $$ = $1; }
| function_declaration_statement { $$ = $1; }
| class_declaration_statement { $$ = $1; }
| T_HALT_COMPILER
{ throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); }
;
statement:
'{' inner_statement_list '}' { $$ = $2; }
| T_IF '(' expr ')' statement elseif_list else_single
{ $$ = Stmt\If_[$3, ['stmts' => toArray($5), 'elseifs' => $6, 'else' => $7]]; }
| T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';'
{ $$ = Stmt\If_[$3, ['stmts' => $6, 'elseifs' => $7, 'else' => $8]]; }
| T_WHILE '(' expr ')' while_statement { $$ = Stmt\While_[$3, $5]; }
| T_DO statement T_WHILE '(' expr ')' ';' { $$ = Stmt\Do_ [$5, toArray($2)]; }
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
{ $$ = Stmt\For_[['init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => $9]]; }
| T_SWITCH '(' expr ')' switch_case_list { $$ = Stmt\Switch_[$3, $5]; }
| T_BREAK optional_expr ';' { $$ = Stmt\Break_[$2]; }
| T_CONTINUE optional_expr ';' { $$ = Stmt\Continue_[$2]; }
| T_RETURN optional_expr ';' { $$ = Stmt\Return_[$2]; }
| T_GLOBAL global_var_list ';' { $$ = Stmt\Global_[$2]; }
| T_STATIC static_var_list ';' { $$ = Stmt\Static_[$2]; }
| T_ECHO expr_list ';' { $$ = Stmt\Echo_[$2]; }
| T_INLINE_HTML { $$ = Stmt\InlineHTML[$1]; }
| expr ';' { $$ = $1; }
| T_UNSET '(' variables_list ')' ';' { $$ = Stmt\Unset_[$3]; }
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
{ $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }
| T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement
{ $$ = Stmt\Foreach_[$3, $7[0], ['keyVar' => $5, 'byRef' => $7[1], 'stmts' => $9]]; }
| T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt\Declare_[$3, $5]; }
| ';' { $$ = array(); /* means: no statement */ }
| T_TRY '{' inner_statement_list '}' catches optional_finally
{ $$ = Stmt\TryCatch[$3, $5, $6]; }
| T_THROW expr ';' { $$ = Stmt\Throw_[$2]; }
| T_GOTO T_STRING ';' { $$ = Stmt\Goto_[$2]; }
| T_STRING ':' { $$ = Stmt\Label[$1]; }
| error { $$ = array(); /* means: no statement */ }
;
catches:
/* empty */ { init(); }
| catches catch { push($1, $2); }
;
catch:
T_CATCH '(' name T_VARIABLE ')' '{' inner_statement_list '}'
{ $$ = Stmt\Catch_[$3, parseVar($4), $7]; }
;
optional_finally:
/* empty */ { $$ = null; }
| T_FINALLY '{' inner_statement_list '}' { $$ = $3; }
;
variables_list:
variable { init($1); }
| variables_list ',' variable { push($1, $3); }
;
optional_ref:
/* empty */ { $$ = false; }
| '&' { $$ = true; }
;
optional_ellipsis:
/* empty */ { $$ = false; }
| T_ELLIPSIS { $$ = true; }
;
function_declaration_statement:
T_FUNCTION optional_ref T_STRING '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
{ $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; }
;
class_declaration_statement:
class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}'
{ $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6]]; }
| T_INTERFACE T_STRING interface_extends_list '{' class_statement_list '}'
{ $$ = Stmt\Interface_[$2, ['extends' => $3, 'stmts' => $5]]; }
| T_TRAIT T_STRING '{' class_statement_list '}'
{ $$ = Stmt\Trait_[$2, $4]; }
;
class_entry_type:
T_CLASS { $$ = 0; }
| T_ABSTRACT T_CLASS { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
| T_FINAL T_CLASS { $$ = Stmt\Class_::MODIFIER_FINAL; }
;
extends_from:
/* empty */ { $$ = null; }
| T_EXTENDS name { $$ = $2; }
;
interface_extends_list:
/* empty */ { $$ = array(); }
| T_EXTENDS name_list { $$ = $2; }
;
implements_list:
/* empty */ { $$ = array(); }
| T_IMPLEMENTS name_list { $$ = $2; }
;
name_list:
name { init($1); }
| name_list ',' name { push($1, $3); }
;
for_statement:
statement { $$ = toArray($1); }
| ':' inner_statement_list T_ENDFOR ';' { $$ = $2; }
;
foreach_statement:
statement { $$ = toArray($1); }
| ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; }
;
declare_statement:
statement { $$ = toArray($1); }
| ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; }
;
declare_list:
declare_list_element { init($1); }
| declare_list ',' declare_list_element { push($1, $3); }
;
declare_list_element:
T_STRING '=' expr { $$ = Stmt\DeclareDeclare[$1, $3]; }
;
switch_case_list:
'{' case_list '}' { $$ = $2; }
| '{' ';' case_list '}' { $$ = $3; }
| ':' case_list T_ENDSWITCH ';' { $$ = $2; }
| ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; }
;
case_list:
/* empty */ { init(); }
| case_list case { push($1, $2); }
;
case:
T_CASE expr case_separator inner_statement_list { $$ = Stmt\Case_[$2, $4]; }
| T_DEFAULT case_separator inner_statement_list { $$ = Stmt\Case_[null, $3]; }
;
case_separator:
':'
| ';'
;
while_statement:
statement { $$ = toArray($1); }
| ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; }
;
elseif_list:
/* empty */ { init(); }
| elseif_list elseif { push($1, $2); }
;
elseif:
T_ELSEIF '(' expr ')' statement { $$ = Stmt\ElseIf_[$3, toArray($5)]; }
;
new_elseif_list:
/* empty */ { init(); }
| new_elseif_list new_elseif { push($1, $2); }
;
new_elseif:
T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt\ElseIf_[$3, $6]; }
;
else_single:
/* empty */ { $$ = null; }
| T_ELSE statement { $$ = Stmt\Else_[toArray($2)]; }
;
new_else_single:
/* empty */ { $$ = null; }
| T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; }
;
foreach_variable:
variable { $$ = array($1, false); }
| '&' variable { $$ = array($2, true); }
| list_expr { $$ = array($1, false); }
;
parameter_list:
non_empty_parameter_list { $$ = $1; }
| /* empty */ { $$ = array(); }
;
non_empty_parameter_list:
parameter { init($1); }
| non_empty_parameter_list ',' parameter { push($1, $3); }
;
parameter:
optional_param_type optional_ref optional_ellipsis T_VARIABLE
{ $$ = Node\Param[parseVar($4), null, $1, $2, $3]; }
| optional_param_type optional_ref optional_ellipsis T_VARIABLE '=' expr
{ $$ = Node\Param[parseVar($4), $6, $1, $2, $3]; }
;
type:
name { $$ = $this->handleScalarTypes($1); }
| T_ARRAY { $$ = 'array'; }
| T_CALLABLE { $$ = 'callable'; }
;
optional_param_type:
/* empty */ { $$ = null; }
| type { $$ = $1; }
;
optional_return_type:
/* empty */ { $$ = null; }
| ':' type { $$ = $2; }
;
argument_list:
'(' ')' { $$ = array(); }
| '(' non_empty_argument_list ')' { $$ = $2; }
;
non_empty_argument_list:
argument { init($1); }
| non_empty_argument_list ',' argument { push($1, $3); }
;
argument:
expr { $$ = Node\Arg[$1, false, false]; }
| '&' variable { $$ = Node\Arg[$2, true, false]; }
| T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; }
;
global_var_list:
global_var_list ',' global_var { push($1, $3); }
| global_var { init($1); }
;
global_var:
simple_variable { $$ = Expr\Variable[$1]; }
;
static_var_list:
static_var_list ',' static_var { push($1, $3); }
| static_var { init($1); }
;
static_var:
T_VARIABLE { $$ = Stmt\StaticVar[parseVar($1), null]; }
| T_VARIABLE '=' expr { $$ = Stmt\StaticVar[parseVar($1), $3]; }
;
class_statement_list:
class_statement_list class_statement { push($1, $2); }
| /* empty */ { init(); }
;
class_statement:
variable_modifiers property_declaration_list ';' { $$ = Stmt\Property[$1, $2]; }
| T_CONST class_const_list ';' { $$ = Stmt\ClassConst[$2]; }
| method_modifiers T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type method_body
{ $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]]; }
| T_USE name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; }
;
trait_adaptations:
';' { $$ = array(); }
| '{' trait_adaptation_list '}' { $$ = $2; }
;
trait_adaptation_list:
/* empty */ { init(); }
| trait_adaptation_list trait_adaptation { push($1, $2); }
;
trait_adaptation:
trait_method_reference_fully_qualified T_INSTEADOF name_list ';'
{ $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; }
| trait_method_reference T_AS member_modifier identifier ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; }
| trait_method_reference T_AS member_modifier ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; }
| trait_method_reference T_AS T_STRING ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
| trait_method_reference T_AS reserved_non_modifiers ';'
{ $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; }
;
trait_method_reference_fully_qualified:
name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = array($1, $3); }
;
trait_method_reference:
trait_method_reference_fully_qualified { $$ = $1; }
| identifier { $$ = array(null, $1); }
;
method_body:
';' /* abstract method */ { $$ = null; }
| '{' inner_statement_list '}' { $$ = $2; }
;
variable_modifiers:
non_empty_member_modifiers { $$ = $1; }
| T_VAR { $$ = 0; }
;
method_modifiers:
/* empty */ { $$ = 0; }
| non_empty_member_modifiers { $$ = $1; }
;
non_empty_member_modifiers:
member_modifier { $$ = $1; }
| non_empty_member_modifiers member_modifier { Stmt\Class_::verifyModifier($1, $2); $$ = $1 | $2; }
;
member_modifier:
T_PUBLIC { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
| T_PROTECTED { $$ = Stmt\Class_::MODIFIER_PROTECTED; }
| T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; }
| T_STATIC { $$ = Stmt\Class_::MODIFIER_STATIC; }
| T_ABSTRACT { $$ = Stmt\Class_::MODIFIER_ABSTRACT; }
| T_FINAL { $$ = Stmt\Class_::MODIFIER_FINAL; }
;
property_declaration_list:
property_declaration { init($1); }
| property_declaration_list ',' property_declaration { push($1, $3); }
;
property_declaration:
T_VARIABLE { $$ = Stmt\PropertyProperty[parseVar($1), null]; }
| T_VARIABLE '=' expr { $$ = Stmt\PropertyProperty[parseVar($1), $3]; }
;
expr_list:
expr_list ',' expr { push($1, $3); }
| expr { init($1); }
;
for_expr:
/* empty */ { $$ = array(); }
| expr_list { $$ = $1; }
;
expr:
variable { $$ = $1; }
| list_expr '=' expr { $$ = Expr\Assign[$1, $3]; }
| variable '=' expr { $$ = Expr\Assign[$1, $3]; }
| variable '=' '&' variable { $$ = Expr\AssignRef[$1, $4]; }
| variable '=' '&' new_expr { $$ = Expr\AssignRef[$1, $4]; }
| new_expr { $$ = $1; }
| T_CLONE expr { $$ = Expr\Clone_[$2]; }
| variable T_PLUS_EQUAL expr { $$ = Expr\AssignOp\Plus [$1, $3]; }
| variable T_MINUS_EQUAL expr { $$ = Expr\AssignOp\Minus [$1, $3]; }
| variable T_MUL_EQUAL expr { $$ = Expr\AssignOp\Mul [$1, $3]; }
| variable T_DIV_EQUAL expr { $$ = Expr\AssignOp\Div [$1, $3]; }
| variable T_CONCAT_EQUAL expr { $$ = Expr\AssignOp\Concat [$1, $3]; }
| variable T_MOD_EQUAL expr { $$ = Expr\AssignOp\Mod [$1, $3]; }
| variable T_AND_EQUAL expr { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; }
| variable T_OR_EQUAL expr { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; }
| variable T_XOR_EQUAL expr { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; }
| variable T_SL_EQUAL expr { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; }
| variable T_SR_EQUAL expr { $$ = Expr\AssignOp\ShiftRight[$1, $3]; }
| variable T_POW_EQUAL expr { $$ = Expr\AssignOp\Pow [$1, $3]; }
| variable T_INC { $$ = Expr\PostInc[$1]; }
| T_INC variable { $$ = Expr\PreInc [$2]; }
| variable T_DEC { $$ = Expr\PostDec[$1]; }
| T_DEC variable { $$ = Expr\PreDec [$2]; }
| expr T_BOOLEAN_OR expr { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; }
| expr T_BOOLEAN_AND expr { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; }
| expr T_LOGICAL_OR expr { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; }
| expr T_LOGICAL_AND expr { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; }
| expr T_LOGICAL_XOR expr { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; }
| expr '|' expr { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; }
| expr '&' expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; }
| expr '^' expr { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; }
| expr '.' expr { $$ = Expr\BinaryOp\Concat [$1, $3]; }
| expr '+' expr { $$ = Expr\BinaryOp\Plus [$1, $3]; }
| expr '-' expr { $$ = Expr\BinaryOp\Minus [$1, $3]; }
| expr '*' expr { $$ = Expr\BinaryOp\Mul [$1, $3]; }
| expr '/' expr { $$ = Expr\BinaryOp\Div [$1, $3]; }
| expr '%' expr { $$ = Expr\BinaryOp\Mod [$1, $3]; }
| expr T_SL expr { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; }
| expr T_SR expr { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; }
| expr T_POW expr { $$ = Expr\BinaryOp\Pow [$1, $3]; }
| '+' expr %prec T_INC { $$ = Expr\UnaryPlus [$2]; }
| '-' expr %prec T_INC { $$ = Expr\UnaryMinus[$2]; }
| '!' expr { $$ = Expr\BooleanNot[$2]; }
| '~' expr { $$ = Expr\BitwiseNot[$2]; }
| expr T_IS_IDENTICAL expr { $$ = Expr\BinaryOp\Identical [$1, $3]; }
| expr T_IS_NOT_IDENTICAL expr { $$ = Expr\BinaryOp\NotIdentical [$1, $3]; }
| expr T_IS_EQUAL expr { $$ = Expr\BinaryOp\Equal [$1, $3]; }
| expr T_IS_NOT_EQUAL expr { $$ = Expr\BinaryOp\NotEqual [$1, $3]; }
| expr T_SPACESHIP expr { $$ = Expr\BinaryOp\Spaceship [$1, $3]; }
| expr '<' expr { $$ = Expr\BinaryOp\Smaller [$1, $3]; }
| expr T_IS_SMALLER_OR_EQUAL expr { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; }
| expr '>' expr { $$ = Expr\BinaryOp\Greater [$1, $3]; }
| expr T_IS_GREATER_OR_EQUAL expr { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; }
| expr T_INSTANCEOF class_name_reference { $$ = Expr\Instanceof_[$1, $3]; }
| '(' expr ')' { $$ = $2; }
| expr '?' expr ':' expr { $$ = Expr\Ternary[$1, $3, $5]; }
| expr '?' ':' expr { $$ = Expr\Ternary[$1, null, $4]; }
| expr T_COALESCE expr { $$ = Expr\BinaryOp\Coalesce[$1, $3]; }
| T_ISSET '(' variables_list ')' { $$ = Expr\Isset_[$3]; }
| T_EMPTY '(' expr ')' { $$ = Expr\Empty_[$3]; }
| T_INCLUDE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; }
| T_INCLUDE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; }
| T_EVAL '(' expr ')' { $$ = Expr\Eval_[$3]; }
| T_REQUIRE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; }
| T_REQUIRE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; }
| T_INT_CAST expr { $$ = Expr\Cast\Int_ [$2]; }
| T_DOUBLE_CAST expr { $$ = Expr\Cast\Double [$2]; }
| T_STRING_CAST expr { $$ = Expr\Cast\String_ [$2]; }
| T_ARRAY_CAST expr { $$ = Expr\Cast\Array_ [$2]; }
| T_OBJECT_CAST expr { $$ = Expr\Cast\Object_ [$2]; }
| T_BOOL_CAST expr { $$ = Expr\Cast\Bool_ [$2]; }
| T_UNSET_CAST expr { $$ = Expr\Cast\Unset_ [$2]; }
| T_EXIT exit_expr { $$ = Expr\Exit_ [$2]; }
| '@' expr { $$ = Expr\ErrorSuppress[$2]; }
| scalar { $$ = $1; }
| '`' backticks_expr '`' { $$ = Expr\ShellExec[$2]; }
| T_PRINT expr { $$ = Expr\Print_[$2]; }
| T_YIELD { $$ = Expr\Yield_[null, null]; }
| T_YIELD expr { $$ = Expr\Yield_[$2, null]; }
| T_YIELD expr T_DOUBLE_ARROW expr { $$ = Expr\Yield_[$4, $2]; }
| T_YIELD_FROM expr { $$ = Expr\YieldFrom[$2]; }
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
'{' inner_statement_list '}'
{ $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; }
| T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
'{' inner_statement_list '}'
{ $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; }
;
anonymous_class:
T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}'
{ $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2); }
new_expr:
T_NEW class_name_reference ctor_arguments { $$ = Expr\New_[$2, $3]; }
| T_NEW anonymous_class
{ list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; }
;
lexical_vars:
/* empty */ { $$ = array(); }
| T_USE '(' lexical_var_list ')' { $$ = $3; }
;
lexical_var_list:
lexical_var { init($1); }
| lexical_var_list ',' lexical_var { push($1, $3); }
;
lexical_var:
optional_ref T_VARIABLE { $$ = Expr\ClosureUse[parseVar($2), $1]; }
;
function_call:
name argument_list { $$ = Expr\FuncCall[$1, $2]; }
| callable_expr argument_list { $$ = Expr\FuncCall[$1, $2]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM member_name argument_list
{ $$ = Expr\StaticCall[$1, $3, $4]; }
;
class_name:
T_STATIC { $$ = Name[$1]; }
| name { $$ = $1; }
;
name:
namespace_name_parts { $$ = Name[$1]; }
| T_NS_SEPARATOR namespace_name_parts { $$ = Name\FullyQualified[$2]; }
| T_NAMESPACE T_NS_SEPARATOR namespace_name_parts { $$ = Name\Relative[$3]; }
;
class_name_reference:
class_name { $$ = $1; }
| new_variable { $$ = $1; }
;
class_name_or_var:
class_name { $$ = $1; }
| dereferencable { $$ = $1; }
;
exit_expr:
/* empty */ { $$ = null; }
| '(' optional_expr ')' { $$ = $2; }
;
backticks_expr:
/* empty */ { $$ = array(); }
| T_ENCAPSED_AND_WHITESPACE
{ $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`')]); }
| encaps_list { parseEncapsed($1, '`', true); $$ = $1; }
;
ctor_arguments:
/* empty */ { $$ = array(); }
| argument_list { $$ = $1; }
;
constant:
name { $$ = Expr\ConstFetch[$1]; }
| class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier
{ $$ = Expr\ClassConstFetch[$1, $3]; }
;
dereferencable_scalar:
T_ARRAY '(' array_pair_list ')' { $$ = Expr\Array_[$3]; }
| '[' array_pair_list ']' { $$ = Expr\Array_[$2]; }
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar\String_[Scalar\String_::parse($1)]; }
;
scalar:
T_LNUMBER { $$ = Scalar\LNumber[Scalar\LNumber::parse($1)]; }
| T_DNUMBER { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
| T_LINE { $$ = Scalar\MagicConst\Line[]; }
| T_FILE { $$ = Scalar\MagicConst\File[]; }
| T_DIR { $$ = Scalar\MagicConst\Dir[]; }
| T_CLASS_C { $$ = Scalar\MagicConst\Class_[]; }
| T_TRAIT_C { $$ = Scalar\MagicConst\Trait_[]; }
| T_METHOD_C { $$ = Scalar\MagicConst\Method[]; }
| T_FUNC_C { $$ = Scalar\MagicConst\Function_[]; }
| T_NS_C { $$ = Scalar\MagicConst\Namespace_[]; }
| dereferencable_scalar { $$ = $1; }
| constant { $$ = $1; }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
{ $$ = Scalar\String_[Scalar\String_::parseDocString($1, $2)]; }
| T_START_HEREDOC T_END_HEREDOC
{ $$ = Scalar\String_['']; }
| '"' encaps_list '"'
{ parseEncapsed($2, '"', true); $$ = Scalar\Encapsed[$2]; }
| T_START_HEREDOC encaps_list T_END_HEREDOC
{ parseEncapsedDoc($2, true); $$ = Scalar\Encapsed[$2]; }
;
optional_comma:
/* empty */
| ','
;
optional_expr:
/* empty */ { $$ = null; }
| expr { $$ = $1; }
;
dereferencable:
variable { $$ = $1; }
| '(' expr ')' { $$ = $2; }
| dereferencable_scalar { $$ = $1; }
;
callable_expr:
callable_variable { $$ = $1; }
| '(' expr ')' { $$ = $2; }
| dereferencable_scalar { $$ = $1; }
;
callable_variable:
simple_variable { $$ = Expr\Variable[$1]; }
| dereferencable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| constant '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| dereferencable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| function_call { $$ = $1; }
| dereferencable T_OBJECT_OPERATOR property_name argument_list
{ $$ = Expr\MethodCall[$1, $3, $4]; }
;
variable:
callable_variable { $$ = $1; }
| static_member { $$ = $1; }
| dereferencable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
;
simple_variable:
T_VARIABLE { $$ = parseVar($1); }
| '$' '{' expr '}' { $$ = $3; }
| '$' simple_variable { $$ = Expr\Variable[$2]; }
;
static_member:
class_name_or_var T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ $$ = Expr\StaticPropertyFetch[$1, $3]; }
;
new_variable:
simple_variable { $$ = Expr\Variable[$1]; }
| new_variable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| new_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
| new_variable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
| class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable { $$ = Expr\StaticPropertyFetch[$1, $3]; }
| new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable { $$ = Expr\StaticPropertyFetch[$1, $3]; }
;
member_name:
identifier { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| simple_variable { $$ = Expr\Variable[$1]; }
;
property_name:
T_STRING { $$ = $1; }
| '{' expr '}' { $$ = $2; }
| simple_variable { $$ = Expr\Variable[$1]; }
;
list_expr:
T_LIST '(' list_expr_elements ')' { $$ = Expr\List_[$3]; }
;
list_expr_elements:
list_expr_elements ',' list_expr_element { push($1, $3); }
| list_expr_element { init($1); }
;
list_expr_element:
variable { $$ = $1; }
| list_expr { $$ = $1; }
| /* empty */ { $$ = null; }
;
array_pair_list:
/* empty */ { $$ = array(); }
| non_empty_array_pair_list optional_comma { $$ = $1; }
;
non_empty_array_pair_list:
non_empty_array_pair_list ',' array_pair { push($1, $3); }
| array_pair { init($1); }
;
array_pair:
expr T_DOUBLE_ARROW expr { $$ = Expr\ArrayItem[$3, $1, false]; }
| expr { $$ = Expr\ArrayItem[$1, null, false]; }
| expr T_DOUBLE_ARROW '&' variable { $$ = Expr\ArrayItem[$4, $1, true]; }
| '&' variable { $$ = Expr\ArrayItem[$2, null, true]; }
;
encaps_list:
encaps_list encaps_var { push($1, $2); }
| encaps_list encaps_string_part { push($1, $2); }
| encaps_var { init($1); }
| encaps_string_part encaps_var { init($1, $2); }
;
encaps_string_part:
T_ENCAPSED_AND_WHITESPACE { $$ = Scalar\EncapsedStringPart[$1]; }
;
encaps_var:
T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
| T_VARIABLE '[' encaps_var_offset ']' { $$ = Expr\ArrayDimFetch[Expr\Variable[parseVar($1)], $3]; }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = Expr\PropertyFetch[Expr\Variable[parseVar($1)], $3]; }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Expr\Variable[$2]; }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' { $$ = Expr\Variable[$2]; }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
{ $$ = Expr\ArrayDimFetch[Expr\Variable[$2], $4]; }
| T_CURLY_OPEN variable '}' { $$ = $2; }
;
encaps_var_offset:
T_STRING { $$ = Scalar\String_[$1]; }
| T_NUM_STRING { $$ = Scalar\String_[$1]; }
| T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
;
%%

View File

@ -1,11 +1,17 @@
<?php
$grammarFile = __DIR__ . '/zend_language_parser.phpy';
$skeletonFile = __DIR__ . '/kmyacc.php.parser';
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
$tmpResultFile = __DIR__ . '/tmp_parser.php';
$parserResultFile = __DIR__ . '/../lib/PHPParser/Parser.php';
$debugParserResultFile = __DIR__ . '/../lib/PHPParser/Parser/Debug.php';
$grammarFileToName = [
__DIR__ . '/php5.y' => 'Php5',
__DIR__ . '/php7.y' => 'Php7',
];
$tokensFile = __DIR__ . '/tokens.y';
$tokensTemplate = __DIR__ . '/tokens.template';
$skeletonFile = __DIR__ . '/parser.template';
$tmpGrammarFile = __DIR__ . '/tmp_parser.phpy';
$tmpResultFile = __DIR__ . '/tmp_parser.php';
$resultDir = __DIR__ . '/../lib/PhpParser/Parser';
$tokensResultsFile = $resultDir . '/Tokens.php';
// check for kmyacc.exe binary in this directory, otherwise fall back to global name
$kmyacc = __DIR__ . '/kmyacc.exe';
@ -36,46 +42,50 @@ const ARGS = '\((?<args>[^()]*+(?:\((?&args)\)[^()]*+)*+)\)';
/// Main script ///
///////////////////
echo 'Building temporary preproprocessed grammar file.', "\n";
$tokens = file_get_contents($tokensFile);
$grammarCode = file_get_contents($grammarFile);
foreach ($grammarFileToName as $grammarFile => $name) {
echo "Building temporary $name grammar file.\n";
$grammarCode = resolveConstants($grammarCode);
$grammarCode = resolveNodes($grammarCode);
$grammarCode = resolveMacros($grammarCode);
$grammarCode = resolveArrays($grammarCode);
$grammarCode = file_get_contents($grammarFile);
$grammarCode = str_replace('%tokens', $tokens, $grammarCode);
file_put_contents($tmpGrammarFile, $grammarCode);
$grammarCode = resolveNodes($grammarCode);
$grammarCode = resolveMacros($grammarCode);
$grammarCode = resolveStackAccess($grammarCode);
echo "Building parser.\n";
$output = trim(shell_exec("$kmyacc -l -m $skeletonFile -p PHPParser_Parser $tmpGrammarFile 2>&1"));
echo "Output: \"$output\"\n";
file_put_contents($tmpGrammarFile, $grammarCode);
moveFileWithDirCheck($tmpResultFile, $parserResultFile);
$additionalArgs = $optionDebug ? '-t -v' : '';
if ($optionDebug) {
echo "Building debug parser.\n";
$output = trim(shell_exec("$kmyacc -t -v -l -m $skeletonFile -p PHPParser_Parser $tmpGrammarFile 2>&1"));
echo "Building $name parser.\n";
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile -p $name $tmpGrammarFile 2>&1"));
echo "Output: \"$output\"\n";
moveFileWithDirCheck($tmpResultFile, $debugParserResultFile);
}
$resultCode = file_get_contents($tmpResultFile);
$resultCode = removeTrailingWhitespace($resultCode);
if (!$optionKeepTmpGrammar) {
unlink($tmpGrammarFile);
ensureDirExists($resultDir);
file_put_contents("$resultDir/$name.php", $resultCode);
unlink($tmpResultFile);
echo "Building token definition.\n";
$output = trim(shell_exec("$kmyacc -l -m $tokensTemplate $tmpGrammarFile 2>&1"));
assert($output === '');
rename($tmpResultFile, $tokensResultsFile);
if (!$optionKeepTmpGrammar) {
unlink($tmpGrammarFile);
}
}
///////////////////////////////
/// Preprocessing functions ///
///////////////////////////////
function resolveConstants($code) {
return preg_replace('~[A-Z][a-zA-Z_]++::~', 'PHPParser_Node_$0', $code);
}
function resolveNodes($code) {
return preg_replace_callback(
'~(?<name>[A-Z][a-zA-Z_]++)\s*' . PARAMS . '~',
'~(?<name>[A-Z][a-zA-Z_\\\\]++)\s*' . PARAMS . '~',
function($matches) {
// recurse
$matches['params'] = resolveNodes($matches['params']);
@ -90,7 +100,7 @@ function resolveNodes($code) {
$paramCode .= $param . ', ';
}
return 'new PHPParser_Node_' . $matches['name'] . '(' . $paramCode . '$attributes)';
return 'new ' . $matches['name'] . '(' . $paramCode . 'attributes())';
},
$code
);
@ -109,10 +119,9 @@ function resolveMacros($code) {
$matches['args']
);
if ('error' == $name) {
assertArgs(1, $args, $name);
return 'throw new PHPParser_Error(' . $args[0] . ')';
if ('attributes' == $name) {
assertArgs(0, $args, $name);
return '$this->startAttributeStack[#1] + $this->endAttributes';
}
if ('init' == $name) {
@ -128,7 +137,8 @@ function resolveMacros($code) {
if ('pushNormalizing' == $name) {
assertArgs(2, $args, $name);
return 'if (is_array(' . $args[1] . ')) { $$ = array_merge(' . $args[0] . ', ' . $args[1] . '); } else { ' . $args[0] . '[] = ' . $args[1] . '; $$ = ' . $args[0] . '; }';
return 'if (is_array(' . $args[1] . ')) { $$ = array_merge(' . $args[0] . ', ' . $args[1] . '); }'
. ' else { ' . $args[0] . '[] = ' . $args[1] . '; $$ = ' . $args[0] . '; }';
}
if ('toArray' == $name) {
@ -144,18 +154,22 @@ function resolveMacros($code) {
}
if ('parseEncapsed' == $name) {
assertArgs(2, $args, $name);
assertArgs(3, $args, $name);
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = PHPParser_Node_Scalar_String::parseEscapeSequences($s, ' . $args[1] . '); } }';
return 'foreach (' . $args[0] . ' as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) {'
. ' $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, ' . $args[1] . ', ' . $args[2] . '); } }';
}
if ('parseEncapsedDoc' == $name) {
assertArgs(1, $args, $name);
assertArgs(2, $args, $name);
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = PHPParser_Node_Scalar_String::parseEscapeSequences($s, null); } } $s = preg_replace(\'~(\r\n|\n|\r)$~\', \'\', $s); if (\'\' === $s) array_pop(' . $args[0] . ');';
return 'foreach (' . $args[0] . ' as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) {'
. ' $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, null, ' . $args[1] . '); } }'
. ' $s->value = preg_replace(\'~(\r\n|\n|\r)\z~\', \'\', $s->value);'
. ' if (\'\' === $s->value) array_pop(' . $args[0] . ');';
}
throw new Exception(sprintf('Unknown macro "%s"', $name));
return $matches[0];
},
$code
);
@ -167,43 +181,22 @@ function assertArgs($num, $args, $name) {
}
}
function resolveArrays($code) {
return preg_replace_callback(
'~' . PARAMS . '~',
function ($matches) {
$elements = magicSplit(
'(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,',
$matches['params']
);
// don't convert [] to array, it might have different meaning
if (empty($elements)) {
return $matches[0];
}
$elementCodes = array();
foreach ($elements as $element) {
// convert only arrays where all elements have keys
if (false === strpos($element, ':')) {
return $matches[0];
}
list($key, $value) = explode(':', $element, 2);
$elementCodes[] = "'" . $key . "' =>" . $value;
}
return 'array(' . implode(', ', $elementCodes) . ')';
},
$code
);
function resolveStackAccess($code) {
$code = preg_replace('/\$\d+/', '$this->semStack[$0]', $code);
$code = preg_replace('/#(\d+)/', '$$1', $code);
return $code;
}
function moveFileWithDirCheck($fromPath, $toPath) {
$dir = dirname($toPath);
function removeTrailingWhitespace($code) {
$lines = explode("\n", $code);
$lines = array_map('rtrim', $lines);
return implode("\n", $lines);
}
function ensureDirExists($dir) {
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
rename($fromPath, $toPath);
}
//////////////////////////////
@ -221,5 +214,9 @@ function magicSplit($regex, $string) {
$piece = trim($piece);
}
return array_filter($pieces);
}
if ($pieces === ['']) {
return [];
}
return $pieces;
}

17
grammar/tokens.template Normal file
View File

@ -0,0 +1,17 @@
<?php
$meta #
#semval($) $this->semValue
#semval($,%t) $this->semValue
#semval(%n) $this->stackPos-(%l-%n)
#semval(%n,%t) $this->stackPos-(%l-%n)
namespace PhpParser\Parser;
#include;
/* GENERATED file based on grammar/tokens.y */
final class Tokens
{
#tokenval
const %s = %n;
#endtokenval
}

113
grammar/tokens.y Normal file
View File

@ -0,0 +1,113 @@
/* We currently rely on the token ID mapping to be the same between PHP 5 and PHP 7 - so the same lexer can be used for
* both. This is enforced by sharing this token file. */
%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE
%left ','
%left T_LOGICAL_OR
%left T_LOGICAL_XOR
%left T_LOGICAL_AND
%right T_PRINT
%right T_YIELD
%right T_DOUBLE_ARROW
%right T_YIELD_FROM
%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL
%left '?' ':'
%right T_COALESCE
%left T_BOOLEAN_OR
%left T_BOOLEAN_AND
%left '|'
%left '^'
%left '&'
%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP
%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL
%left T_SL T_SR
%left '+' '-' '.'
%left '*' '/' '%'
%right '!'
%nonassoc T_INSTANCEOF
%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@'
%right T_POW
%right '['
%nonassoc T_NEW T_CLONE
%token T_EXIT
%token T_IF
%left T_ELSEIF
%left T_ELSE
%left T_ENDIF
%token T_LNUMBER
%token T_DNUMBER
%token T_STRING
%token T_STRING_VARNAME
%token T_VARIABLE
%token T_NUM_STRING
%token T_INLINE_HTML
%token T_CHARACTER
%token T_BAD_CHARACTER
%token T_ENCAPSED_AND_WHITESPACE
%token T_CONSTANT_ENCAPSED_STRING
%token T_ECHO
%token T_DO
%token T_WHILE
%token T_ENDWHILE
%token T_FOR
%token T_ENDFOR
%token T_FOREACH
%token T_ENDFOREACH
%token T_DECLARE
%token T_ENDDECLARE
%token T_AS
%token T_SWITCH
%token T_ENDSWITCH
%token T_CASE
%token T_DEFAULT
%token T_BREAK
%token T_CONTINUE
%token T_GOTO
%token T_FUNCTION
%token T_CONST
%token T_RETURN
%token T_TRY
%token T_CATCH
%token T_FINALLY
%token T_THROW
%token T_USE
%token T_INSTEADOF
%token T_GLOBAL
%right T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC
%token T_VAR
%token T_UNSET
%token T_ISSET
%token T_EMPTY
%token T_HALT_COMPILER
%token T_CLASS
%token T_TRAIT
%token T_INTERFACE
%token T_EXTENDS
%token T_IMPLEMENTS
%token T_OBJECT_OPERATOR
%token T_DOUBLE_ARROW
%token T_LIST
%token T_ARRAY
%token T_CALLABLE
%token T_CLASS_C
%token T_TRAIT_C
%token T_METHOD_C
%token T_FUNC_C
%token T_LINE
%token T_FILE
%token T_COMMENT
%token T_DOC_COMMENT
%token T_OPEN_TAG
%token T_OPEN_TAG_WITH_ECHO
%token T_CLOSE_TAG
%token T_WHITESPACE
%token T_START_HEREDOC
%token T_END_HEREDOC
%token T_DOLLAR_OPEN_CURLY_BRACES
%token T_CURLY_OPEN
%token T_PAAMAYIM_NEKUDOTAYIM
%token T_NAMESPACE
%token T_NS_C
%token T_DIR
%token T_NS_SEPARATOR
%token T_ELLIPSIS

View File

@ -1,33 +0,0 @@
<?php
/**
* @codeCoverageIgnore
*/
class PHPParser_Autoloader
{
/**
* Registers PHPParser_Autoloader as an SPL autoloader.
*/
static public function register()
{
ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(__CLASS__, 'autoload'));
}
/**
* Handles autoloading of classes.
*
* @param string $class A class name.
*/
static public function autoload($class)
{
if (0 !== strpos($class, 'PHPParser')) {
return;
}
$file = dirname(dirname(__FILE__)) . '/' . strtr($class, '_', '/') . '.php';
if (is_file($file)) {
require $file;
}
}
}

View File

@ -1,137 +0,0 @@
<?php
class PHPParser_Builder_Class extends PHPParser_BuilderAbstract
{
protected $name;
protected $extends;
protected $implements;
protected $type;
protected $uses;
protected $constants;
protected $properties;
protected $methods;
/**
* Creates a class builder.
*
* @param string $name Name of the class
*/
public function __construct($name) {
$this->name = $name;
$this->type = 0;
$this->extends = null;
$this->implements = array();
$this->uses = $this->constants = $this->properties = $this->methods = array();
}
/**
* Extends a class.
*
* @param PHPParser_Node_Name|string $class Name of class to extend
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function extend($class) {
$this->extends = $this->normalizeName($class);
return $this;
}
/**
* Implements one or more interfaces.
*
* @param PHPParser_Node_Name|string $interface Name of interface to implement
* @param PHPParser_Node_Name|string $... More interfaces to implement
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function implement() {
foreach (func_get_args() as $interface) {
$this->implements[] = $this->normalizeName($interface);
}
return $this;
}
/**
* Makes the class abstract.
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function makeAbstract() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT);
return $this;
}
/**
* Makes the class final.
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function makeFinal() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_FINAL);
return $this;
}
/**
* Adds a statement.
*
* @param PHPParser_Node_Stmt|PHPParser_Builder $stmt The statement to add
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function addStmt($stmt) {
$stmt = $this->normalizeNode($stmt);
$targets = array(
'Stmt_TraitUse' => &$this->uses,
'Stmt_ClassConst' => &$this->constants,
'Stmt_Property' => &$this->properties,
'Stmt_ClassMethod' => &$this->methods,
);
$type = $stmt->getType();
if (!isset($targets[$type])) {
throw new LogicException(sprintf('Unexpected node of type "%s"', $type));
}
$targets[$type][] = $stmt;
return $this;
}
/**
* Adds multiple statements.
*
* @param array $stmts The statements to add
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function addStmts(array $stmts) {
foreach ($stmts as $stmt) {
$this->addStmt($stmt);
}
return $this;
}
/**
* Returns the built class node.
*
* @return PHPParser_Node_Stmt_Class The built class node
*/
public function getNode() {
return new PHPParser_Node_Stmt_Class($this->name, array(
'type' => $this->type,
'extends' => $this->extends,
'implements' => $this->implements,
'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods),
));
}
}

View File

@ -1,109 +0,0 @@
<?php
class PHPParser_Builder_Function extends PHPParser_BuilderAbstract
{
protected $name;
protected $returnByRef;
protected $params;
protected $stmts;
/**
* Creates a function builder.
*
* @param string $name Name of the function
*/
public function __construct($name) {
$this->name = $name;
$this->returnByRef = false;
$this->params = array();
$this->stmts = array();
}
/**
* Make the function return by reference.
*
* @return PHPParser_Builder_Function The builder instance (for fluid interface)
*/
public function makeReturnByRef() {
$this->returnByRef = true;
return $this;
}
/**
* Adds a parameter.
*
* @param PHPParser_Node_Param|PHPParser_Builder_Param $param The parameter to add
*
* @return PHPParser_Builder_Function The builder instance (for fluid interface)
*/
public function addParam($param) {
$param = $this->normalizeNode($param);
if (!$param instanceof PHPParser_Node_Param) {
throw new LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
}
$this->params[] = $param;
return $this;
}
/**
* Adds multiple parameters.
*
* @param array $params The parameters to add
*
* @return PHPParser_Builder_Function The builder instance (for fluid interface)
*/
public function addParams(array $params) {
foreach ($params as $param) {
$this->addParam($param);
}
return $this;
}
/**
* Adds a statement.
*
* @param PHPParser_Node|PHPParser_Builder $stmt The statement to add
*
* @return PHPParser_Builder_Function The builder instance (for fluid interface)
*/
public function addStmt($stmt) {
$this->stmts[] = $this->normalizeNode($stmt);
return $this;
}
/**
* Adds multiple statements.
*
* @param array $stmts The statements to add
*
* @return PHPParser_Builder_Function The builder instance (for fluid interface)
*/
public function addStmts(array $stmts) {
foreach ($stmts as $stmt) {
$this->addStmt($stmt);
}
return $this;
}
/**
* Returns the built function node.
*
* @return PHPParser_Node_Stmt_Function The built function node
*/
public function getNode() {
return new PHPParser_Node_Stmt_Function($this->name, array(
'byRef' => $this->returnByRef,
'params' => $this->params,
'stmts' => $this->stmts,
));
}
}

View File

@ -1,92 +0,0 @@
<?php
class PHPParser_Builder_Interface extends PHPParser_BuilderAbstract
{
protected $name;
protected $extends;
protected $constants;
protected $methods;
/**
* Creates an interface builder.
*
* @param string $name Name of the interface
*/
public function __construct($name) {
$this->name = $name;
$this->extends = array();
$this->constants = $this->methods = array();
}
/**
* Extends one or more interfaces.
*
* @param PHPParser_Node_Name|string $interface Name of interface to extend
* @param PHPParser_Node_Name|string $... More interfaces to extend
*
* @return PHPParser_Builder_Interface The builder instance (for fluid interface)
*/
public function extend() {
foreach (func_get_args() as $interface) {
$this->extends[] = $this->normalizeName($interface);
}
return $this;
}
/**
* Adds a statement.
*
* @param PHPParser_Node_Stmt|PHPParser_Builder $stmt The statement to add
*
* @return PHPParser_Builder_Interface The builder instance (for fluid interface)
*/
public function addStmt($stmt) {
$stmt = $this->normalizeNode($stmt);
$type = $stmt->getType();
switch ($type) {
case 'Stmt_ClassConst':
$this->constants[] = $stmt;
break;
case 'Stmt_ClassMethod':
// we erase all statements in the body of an interface method
$stmt->stmts = null;
$this->methods[] = $stmt;
break;
default:
throw new LogicException(sprintf('Unexpected node of type "%s"', $type));
}
return $this;
}
/**
* Adds multiple statements.
*
* @param array $stmts The statements to add
*
* @return PHPParser_Builder_Class The builder instance (for fluid interface)
*/
public function addStmts(array $stmts) {
foreach ($stmts as $stmt) {
$this->addStmt($stmt);
}
return $this;
}
/**
* Returns the built class node.
*
* @return PHPParser_Node_Stmt_Interface The built interface node
*/
public function getNode() {
return new PHPParser_Node_Stmt_Interface($this->name, array(
'extends' => $this->extends,
'stmts' => array_merge($this->constants, $this->methods),
));
}
}

View File

@ -1,187 +0,0 @@
<?php
class PHPParser_Builder_Method extends PHPParser_BuilderAbstract
{
protected $name;
protected $type;
protected $returnByRef;
protected $params;
protected $stmts;
/**
* Creates a method builder.
*
* @param string $name Name of the method
*/
public function __construct($name) {
$this->name = $name;
$this->type = 0;
$this->returnByRef = false;
$this->params = array();
$this->stmts = array();
}
/**
* Makes the method public.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makePublic() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC);
return $this;
}
/**
* Makes the method protected.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makeProtected() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED);
return $this;
}
/**
* Makes the method private.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makePrivate() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE);
return $this;
}
/**
* Makes the method static.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makeStatic() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_STATIC);
return $this;
}
/**
* Makes the method abstract.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makeAbstract() {
if (!empty($this->stmts)) {
throw new LogicException('Cannot make method with statements abstract');
}
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_ABSTRACT);
$this->stmts = null; // abstract methods don't have statements
return $this;
}
/**
* Makes the method final.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makeFinal() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_FINAL);
return $this;
}
/**
* Make the method return by reference.
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function makeReturnByRef() {
$this->returnByRef = true;
return $this;
}
/**
* Adds a parameter.
*
* @param PHPParser_Node_Param|PHPParser_Builder_Param $param The parameter to add
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function addParam($param) {
$param = $this->normalizeNode($param);
if (!$param instanceof PHPParser_Node_Param) {
throw new LogicException(sprintf('Expected parameter node, got "%s"', $param->getType()));
}
$this->params[] = $param;
return $this;
}
/**
* Adds multiple parameters.
*
* @param array $params The parameters to add
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function addParams(array $params) {
foreach ($params as $param) {
$this->addParam($param);
}
return $this;
}
/**
* Adds a statement.
*
* @param PHPParser_Node|PHPParser_Builder $stmt The statement to add
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function addStmt($stmt) {
if (null === $this->stmts) {
throw new LogicException('Cannot add statements to an abstract method');
}
$this->stmts[] = $this->normalizeNode($stmt);
return $this;
}
/**
* Adds multiple statements.
*
* @param array $stmts The statements to add
*
* @return PHPParser_Builder_Method The builder instance (for fluid interface)
*/
public function addStmts(array $stmts) {
foreach ($stmts as $stmt) {
$this->addStmt($stmt);
}
return $this;
}
/**
* Returns the built method node.
*
* @return PHPParser_Node_Stmt_ClassMethod The built method node
*/
public function getNode() {
return new PHPParser_Node_Stmt_ClassMethod($this->name, array(
'type' => $this->type !== 0 ? $this->type : PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC,
'byRef' => $this->returnByRef,
'params' => $this->params,
'stmts' => $this->stmts,
));
}
}

View File

@ -1,92 +0,0 @@
<?php
class PHPParser_Builder_Property extends PHPParser_BuilderAbstract
{
protected $name;
protected $type;
protected $default;
/**
* Creates a property builder.
*
* @param string $name Name of the property
*/
public function __construct($name) {
$this->name = $name;
$this->type = 0;
$this->default = null;
}
/**
* Makes the property public.
*
* @return PHPParser_Builder_Property The builder instance (for fluid interface)
*/
public function makePublic() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC);
return $this;
}
/**
* Makes the property protected.
*
* @return PHPParser_Builder_Property The builder instance (for fluid interface)
*/
public function makeProtected() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED);
return $this;
}
/**
* Makes the property private.
*
* @return PHPParser_Builder_Property The builder instance (for fluid interface)
*/
public function makePrivate() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE);
return $this;
}
/**
* Makes the property static.
*
* @return PHPParser_Builder_Property The builder instance (for fluid interface)
*/
public function makeStatic() {
$this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_STATIC);
return $this;
}
/**
* Sets default value for the property.
*
* @param mixed $value Default value to use
*
* @return PHPParser_Builder_Property The builder instance (for fluid interface)
*/
public function setDefault($value) {
$this->default = $this->normalizeValue($value);
return $this;
}
/**
* Returns the built class node.
*
* @return PHPParser_Node_Stmt_Property The built property node
*/
public function getNode() {
return new PHPParser_Node_Stmt_Property(
$this->type !== 0 ? $this->type : PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC,
array(
new PHPParser_Node_Stmt_PropertyProperty($this->name, $this->default)
)
);
}
}

View File

@ -1,94 +0,0 @@
<?php
abstract class PHPParser_BuilderAbstract implements PHPParser_Builder {
/**
* Normalizes a node: Converts builder objects to nodes.
*
* @param PHPParser_Node|PHPParser_Builder $node The node to normalize
*
* @return PHPParser_Node The normalized node
*/
protected function normalizeNode($node) {
if ($node instanceof PHPParser_Builder) {
return $node->getNode();
} elseif ($node instanceof PHPParser_Node) {
return $node;
}
throw new LogicException('Expected node or builder object');
}
/**
* Normalizes a name: Converts plain string names to PHPParser_Node_Name.
*
* @param PHPParser_Node_Name|string $name The name to normalize
*
* @return PHPParser_Node_Name The normalized name
*/
protected function normalizeName($name) {
if ($name instanceof PHPParser_Node_Name) {
return $name;
} else {
return new PHPParser_Node_Name($name);
}
}
/**
* Normalizes a value: Converts nulls, booleans, integers,
* floats, strings and arrays into their respective nodes
*
* @param mixed $value The value to normalize
*
* @return PHPParser_Node_Expr The normalized value
*/
protected function normalizeValue($value) {
if ($value instanceof PHPParser_Node) {
return $value;
} elseif (is_null($value)) {
return new PHPParser_Node_Expr_ConstFetch(
new PHPParser_Node_Name('null')
);
} elseif (is_bool($value)) {
return new PHPParser_Node_Expr_ConstFetch(
new PHPParser_Node_Name($value ? 'true' : 'false')
);
} elseif (is_int($value)) {
return new PHPParser_Node_Scalar_LNumber($value);
} elseif (is_float($value)) {
return new PHPParser_Node_Scalar_DNumber($value);
} elseif (is_string($value)) {
return new PHPParser_Node_Scalar_String($value);
} elseif (is_array($value)) {
$items = array();
$lastKey = -1;
foreach ($value as $itemKey => $itemValue) {
// for consecutive, numeric keys don't generate keys
if (null !== $lastKey && ++$lastKey === $itemKey) {
$items[] = new PHPParser_Node_Expr_ArrayItem(
$this->normalizeValue($itemValue)
);
} else {
$lastKey = null;
$items[] = new PHPParser_Node_Expr_ArrayItem(
$this->normalizeValue($itemValue),
$this->normalizeValue($itemKey)
);
}
}
return new PHPParser_Node_Expr_Array($items);
} else {
throw new LogicException('Invalid value');
}
}
/**
* Sets a modifier in the $this->type property.
*
* @param int $modifier Modifier to set
*/
protected function setModifier($modifier) {
PHPParser_Node_Stmt_Class::verifyModifier($this->type, $modifier);
$this->type |= $modifier;
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
* "class", "interface" and "function" are reserved keywords, so the methods are defined as _class(),
* _interface() and _function() in the class and are made available as class(), interface() and function()
* through __call() magic.
*
* @method PHPParser_Builder_Class class(string $name) Creates a class builder.
* @method PHPParser_Builder_Function function(string $name) Creates a function builder
* @method PHPParser_Builder_Interface interface(string $name) Creates an interface builder.
*/
class PHPParser_BuilderFactory
{
/**
* Creates a class builder.
*
* @param string $name Name of the class
*
* @return PHPParser_Builder_Class The created class builder
*/
protected function _class($name) {
return new PHPParser_Builder_Class($name);
}
/**
* Creates a interface builder.
*
* @param string $name Name of the interface
*
* @return PHPParser_Builder_Class The created interface builder
*/
protected function _interface($name) {
return new PHPParser_Builder_Interface($name);
}
/**
* Creates a method builder.
*
* @param string $name Name of the method
*
* @return PHPParser_Builder_Method The created method builder
*/
public function method($name) {
return new PHPParser_Builder_Method($name);
}
/**
* Creates a parameter builder.
*
* @param string $name Name of the parameter
*
* @return PHPParser_Builder_Param The created parameter builder
*/
public function param($name) {
return new PHPParser_Builder_Param($name);
}
/**
* Creates a property builder.
*
* @param string $name Name of the property
*
* @return PHPParser_Builder_Property The created property builder
*/
public function property($name) {
return new PHPParser_Builder_Property($name);
}
/**
* Creates a function builder.
*
* @param string $name Name of the function
*
* @return PHPParser_Builder_Property The created function builder
*/
protected function _function($name) {
return new PHPParser_Builder_Function($name);
}
public function __call($name, array $args) {
if (method_exists($this, '_' . $name)) {
return call_user_func_array(array($this, '_' . $name), $args);
}
throw new LogicException(sprintf('Method "%s" does not exist', $name));
}
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Comment_Doc extends PHPParser_Comment
{
}

View File

@ -1,70 +0,0 @@
<?php
class PHPParser_Error extends RuntimeException
{
protected $rawMessage;
protected $rawLine;
/**
* Creates an Exception signifying a parse error.
*
* @param string $message Error message
* @param int $line Error line in PHP file
*/
public function __construct($message, $line = -1) {
$this->rawMessage = (string) $message;
$this->rawLine = (int) $line;
$this->updateMessage();
}
/**
* Gets the error message
*
* @return string Error message
*/
public function getRawMessage() {
return $this->rawMessage;
}
/**
* Sets the line of the PHP file the error occurred in.
*
* @param string $message Error message
*/
public function setRawMessage($message) {
$this->rawMessage = (string) $message;
$this->updateMessage();
}
/**
* Gets the error line in the PHP file.
*
* @return int Error line in the PHP file
*/
public function getRawLine() {
return $this->rawLine;
}
/**
* Sets the line of the PHP file the error occurred in.
*
* @param int $line Error line in the PHP file
*/
public function setRawLine($line) {
$this->rawLine = (int) $line;
$this->updateMessage();
}
/**
* Updates the exception message after a change to rawMessage or rawLine.
*/
protected function updateMessage() {
$this->message = $this->rawMessage;
if (-1 === $this->rawLine) {
$this->message .= ' on unknown line';
} else {
$this->message .= ' on line ' . $this->rawLine;
}
}
}

View File

@ -1,191 +0,0 @@
<?php
class PHPParser_Lexer
{
protected $code;
protected $tokens;
protected $pos;
protected $line;
protected $tokenMap;
protected $dropTokens;
/**
* Creates a Lexer.
*/
public function __construct() {
// map from internal tokens to PHPParser tokens
$this->tokenMap = $this->createTokenMap();
// map of tokens to drop while lexing (the map is only used for isset lookup,
// that's why the value is simply set to 1; the value is never actually used.)
$this->dropTokens = array_fill_keys(array(T_WHITESPACE, T_OPEN_TAG), 1);
}
/**
* Initializes the lexer for lexing the provided source code.
*
* @param string $code The source code to lex
*
* @throws PHPParser_Error on lexing errors (unterminated comment or unexpected character)
*/
public function startLexing($code) {
$this->resetErrors();
$this->tokens = @token_get_all($code);
$this->handleErrors();
$this->code = $code; // keep the code around for __halt_compiler() handling
$this->pos = -1;
$this->line = 1;
}
protected function resetErrors() {
// clear error_get_last() by forcing an undefined variable error
@$undefinedVariable;
}
protected function handleErrors() {
$error = error_get_last();
if (preg_match(
'~^Unterminated comment starting line ([0-9]+)$~',
$error['message'], $matches
)) {
throw new PHPParser_Error('Unterminated comment', $matches[1]);
}
if (preg_match(
'~^Unexpected character in input: \'(.)\' \(ASCII=([0-9]+)\)~s',
$error['message'], $matches
)) {
throw new PHPParser_Error(sprintf(
'Unexpected character "%s" (ASCII %d)',
$matches[1], $matches[2]
));
}
// PHP cuts error message after null byte, so need special case
if (preg_match('~^Unexpected character in input: \'$~', $error['message'])) {
throw new PHPParser_Error('Unexpected null byte');
}
}
/**
* Fetches the next token.
*
* @param mixed $value Variable to store token content in
* @param mixed $startAttributes Variable to store start attributes in
* @param mixed $endAttributes Variable to store end attributes in
*
* @return int Token id
*/
public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) {
$startAttributes = array();
$endAttributes = array();
while (isset($this->tokens[++$this->pos])) {
$token = $this->tokens[$this->pos];
if (is_string($token)) {
$startAttributes['startLine'] = $this->line;
$endAttributes['endLine'] = $this->line;
// bug in token_get_all
if ('b"' === $token) {
$value = 'b"';
return ord('"');
} else {
$value = $token;
return ord($token);
}
} else {
$this->line += substr_count($token[1], "\n");
if (T_COMMENT === $token[0]) {
$startAttributes['comments'][] = new PHPParser_Comment($token[1], $token[2]);
} elseif (T_DOC_COMMENT === $token[0]) {
$startAttributes['comments'][] = new PHPParser_Comment_Doc($token[1], $token[2]);
} elseif (!isset($this->dropTokens[$token[0]])) {
$value = $token[1];
$startAttributes['startLine'] = $token[2];
$endAttributes['endLine'] = $this->line;
return $this->tokenMap[$token[0]];
}
}
}
$startAttributes['startLine'] = $this->line;
// 0 is the EOF token
return 0;
}
/**
* Handles __halt_compiler() by returning the text after it.
*
* @return string Remaining text
*/
public function handleHaltCompiler() {
// get the length of the text before the T_HALT_COMPILER token
$textBefore = '';
for ($i = 0; $i <= $this->pos; ++$i) {
if (is_string($this->tokens[$i])) {
$textBefore .= $this->tokens[$i];
} else {
$textBefore .= $this->tokens[$i][1];
}
}
// text after T_HALT_COMPILER, still including ();
$textAfter = substr($this->code, strlen($textBefore));
// ensure that it is followed by ();
// this simplifies the situation, by not allowing any comments
// in between of the tokens.
if (!preg_match('~\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) {
throw new PHPParser_Error('__halt_compiler must be followed by "();"');
}
// prevent the lexer from returning any further tokens
$this->pos = count($this->tokens);
// return with (); removed
return (string) substr($textAfter, strlen($matches[0])); // (string) converts false to ''
}
/**
* Creates the token map.
*
* The token map maps the PHP internal token identifiers
* to the identifiers used by the Parser. Additionally it
* maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'.
*
* @return array The token map
*/
protected function createTokenMap() {
$tokenMap = array();
// 256 is the minimum possible token number, as everything below
// it is an ASCII value
for ($i = 256; $i < 1000; ++$i) {
// T_DOUBLE_COLON is equivalent to T_PAAMAYIM_NEKUDOTAYIM
if (T_DOUBLE_COLON === $i) {
$tokenMap[$i] = PHPParser_Parser::T_PAAMAYIM_NEKUDOTAYIM;
// T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO
} elseif(T_OPEN_TAG_WITH_ECHO === $i) {
$tokenMap[$i] = PHPParser_Parser::T_ECHO;
// T_CLOSE_TAG is equivalent to ';'
} elseif(T_CLOSE_TAG === $i) {
$tokenMap[$i] = ord(';');
// and the others can be mapped directly
} elseif ('UNKNOWN' !== ($name = token_name($i))
&& defined($name = 'PHPParser_Parser::' . $name)
) {
$tokenMap[$i] = constant($name);
}
}
return $tokenMap;
}
}

View File

@ -1,200 +0,0 @@
<?php
/**
* ATTENTION: This code is WRITE-ONLY. Do not try to read it.
*/
class PHPParser_Lexer_Emulative extends PHPParser_Lexer
{
protected $newKeywords;
protected $inObjectAccess;
public function __construct() {
parent::__construct();
$newKeywordsPerVersion = array(
'5.5.0-dev' => array(
'finally' => PHPParser_Parser::T_FINALLY,
'yield' => PHPParser_Parser::T_YIELD,
),
'5.4.0-dev' => array(
'callable' => PHPParser_Parser::T_CALLABLE,
'insteadof' => PHPParser_Parser::T_INSTEADOF,
'trait' => PHPParser_Parser::T_TRAIT,
'__trait__' => PHPParser_Parser::T_TRAIT_C,
),
'5.3.0-dev' => array(
'__dir__' => PHPParser_Parser::T_DIR,
'goto' => PHPParser_Parser::T_GOTO,
'namespace' => PHPParser_Parser::T_NAMESPACE,
'__namespace__' => PHPParser_Parser::T_NS_C,
),
);
$this->newKeywords = array();
foreach ($newKeywordsPerVersion as $version => $newKeywords) {
if (version_compare(PHP_VERSION, $version, '>=')) {
break;
}
$this->newKeywords += $newKeywords;
}
}
public function startLexing($code) {
$this->inObjectAccess = false;
// on PHP 5.4 don't do anything
if (version_compare(PHP_VERSION, '5.4.0RC1', '>=')) {
parent::startLexing($code);
} else {
$code = $this->preprocessCode($code);
parent::startLexing($code);
$this->postprocessTokens();
}
}
/*
* Replaces new features in the code by ~__EMU__{NAME}__{DATA}__~ sequences.
* ~LABEL~ is never valid PHP code, that's why we can (to some degree) safely
* use it here.
* Later when preprocessing the tokens these sequences will either be replaced
* by real tokens or replaced with their original content (e.g. if they occured
* inside a string, i.e. a place where they don't have a special meaning).
*/
protected function preprocessCode($code) {
// binary notation (0b010101101001...)
$code = preg_replace('(\b0b[01]+\b)', '~__EMU__BINARY__$0__~', $code);
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
// namespace separator (backslash not followed by some special characters,
// which are not valid after a NS separator, but would cause problems with
// escape sequence parsing if one would replace the backslash there)
$code = preg_replace('(\\\\(?!["\'`${\\\\]))', '~__EMU__NS__~', $code);
// nowdoc (<<<'ABC'\ncontent\nABC;)
$code = preg_replace_callback(
'((*BSR_ANYCRLF) # set \R to (?>\r\n|\r|\n)
(b?<<<[\t ]*\'([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\'\R) # opening token
((?:(?!\2;?\R).*\R)*) # content
(\2) # closing token
(?=;?\R) # must be followed by newline (with optional semicolon)
)x',
array($this, 'encodeNowdocCallback'),
$code
);
}
return $code;
}
/*
* As nowdocs can have arbitrary content but LABELs can only contain a certain
* range of characters, the nowdoc content is encoded as hex and separated by
* 'x' tokens. So the result of the encoding will look like this:
* ~__EMU__NOWDOC__{HEX(START_TOKEN)}x{HEX(CONTENT)}x{HEX(END_TOKEN)}~
*/
public function encodeNowdocCallback(array $matches) {
return '~__EMU__NOWDOC__'
. bin2hex($matches[1]) . 'x' . bin2hex($matches[3]) . 'x' . bin2hex($matches[4])
. '__~';
}
/*
* Replaces the ~__EMU__...~ sequences with real tokens or their original
* value.
*/
protected function postprocessTokens() {
// we need to manually iterate and manage a count because we'll change
// the tokens array on the way
for ($i = 0, $c = count($this->tokens); $i < $c; ++$i) {
// first check that the following tokens are form ~LABEL~,
// then match the __EMU__... sequence.
if ('~' === $this->tokens[$i]
&& isset($this->tokens[$i + 2])
&& '~' === $this->tokens[$i + 2]
&& T_STRING === $this->tokens[$i + 1][0]
&& preg_match('(^__EMU__([A-Z]++)__(?:([A-Za-z0-9]++)__)?$)', $this->tokens[$i + 1][1], $matches)
) {
if ('BINARY' === $matches[1]) {
// the binary number can either be an integer or a double, so return a LNUMBER
// or DNUMBER respectively
$replace = array(
array(is_int(bindec($matches[2])) ? T_LNUMBER : T_DNUMBER, $matches[2], $this->tokens[$i + 1][2])
);
} elseif ('NS' === $matches[1]) {
// a \ single char token is returned here and replaced by a
// PHPParser_Parser::T_NS_SEPARATOR token in ->getNextToken(). This hacks around
// the limitations arising from T_NS_SEPARATOR not being defined on 5.3
$replace = array('\\');
} elseif ('NOWDOC' === $matches[1]) {
// decode the encoded nowdoc payload; pack('H*' is bin2hex( for 5.3
list($start, $content, $end) = explode('x', $matches[2]);
list($start, $content, $end) = array(pack('H*', $start), pack('H*', $content), pack('H*', $end));
$replace = array();
$replace[] = array(T_START_HEREDOC, $start, $this->tokens[$i + 1][2]);
if ('' !== $content) {
$replace[] = array(T_ENCAPSED_AND_WHITESPACE, $content, -1);
}
$replace[] = array(T_END_HEREDOC, $end, -1);
} else {
// just ignore all other __EMU__ sequences
continue;
}
array_splice($this->tokens, $i, 3, $replace);
$c -= 3 - count($replace);
// for multichar tokens (e.g. strings) replace any ~__EMU__...~ sequences
// in their content with the original character sequence
} elseif (is_array($this->tokens[$i])
&& 0 !== strpos($this->tokens[$i][1], '__EMU__')
) {
$this->tokens[$i][1] = preg_replace_callback(
'(~__EMU__([A-Z]++)__(?:([A-Za-z0-9]++)__)?~)',
array($this, 'restoreContentCallback'),
$this->tokens[$i][1]
);
}
}
}
/*
* This method is a callback for restoring EMU sequences in
* multichar tokens (like strings) to their original value.
*/
public function restoreContentCallback(array $matches) {
if ('BINARY' === $matches[1]) {
return $matches[2];
} elseif ('NS' === $matches[1]) {
return '\\';
} elseif ('NOWDOC' === $matches[1]) {
list($start, $content, $end) = explode('x', $matches[2]);
return pack('H*', $start) . pack('H*', $content) . pack('H*', $end);
} else {
return $matches[0];
}
}
public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) {
$token = parent::getNextToken($value, $startAttributes, $endAttributes);
// replace new keywords by their respective tokens. This is not done
// if we currently are in an object access (e.g. in $obj->namespace
// "namespace" stays a T_STRING tokens and isn't converted to T_NAMESPACE)
if (PHPParser_Parser::T_STRING === $token && !$this->inObjectAccess) {
if (isset($this->newKeywords[strtolower($value)])) {
return $this->newKeywords[strtolower($value)];
}
// backslashes are replaced by T_NS_SEPARATOR tokens
} elseif (92 === $token) { // ord('\\')
return PHPParser_Parser::T_NS_SEPARATOR;
// keep track of whether we currently are in an object access (after ->)
} elseif (PHPParser_Parser::T_OBJECT_OPERATOR === $token) {
$this->inObjectAccess = true;
} else {
$this->inObjectAccess = false;
}
return $token;
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $value Value to pass
* @property bool $byRef Whether to pass by ref
*/
class PHPParser_Node_Arg extends PHPParser_NodeAbstract
{
/**
* Constructs a function call argument node.
*
* @param PHPParser_Node_Expr $value Value to pass
* @param bool $byRef Whether to pass by ref
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $value, $byRef = false, array $attributes = array()) {
parent::__construct(
array(
'value' => $value,
'byRef' => $byRef
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property string $name Name
* @property PHPParser_Node_Expr $value Value
*/
class PHPParser_Node_Const extends PHPParser_NodeAbstract
{
/**
* Constructs a const node for use in class const and const statements.
*
* @param string $name Name
* @param PHPParser_Node_Expr $value Value
* @param array $attributes Additional attributes
*/
public function __construct($name, PHPParser_Node_Expr $value, array $attributes = array()) {
parent::__construct(
array(
'name' => $name,
'value' => $value,
),
$attributes
);
}
}

View File

@ -1,5 +0,0 @@
<?php
abstract class PHPParser_Node_Expr extends PHPParser_NodeAbstract
{
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr_ArrayItem[] $items Items
*/
class PHPParser_Node_Expr_Array extends PHPParser_Node_Expr
{
/**
* Constructs an array node.
*
* @param PHPParser_Node_Expr_ArrayItem[] $items Items of the array
* @param array $attributes Additional attributes
*/
public function __construct(array $items = array(), array $attributes = array()) {
parent::__construct(
array(
'items' => $items
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property null|PHPParser_Node_Expr $dim Array index / dim
*/
class PHPParser_Node_Expr_ArrayDimFetch extends PHPParser_Node_Expr
{
/**
* Constructs an array index fetch node.
*
* @param PHPParser_Node_Expr $var Variable
* @param null|PHPParser_Node_Expr $dim Array index / dim
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $dim = null, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'dim' => $dim
),
$attributes
);
}
}

View File

@ -1,28 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $value Value
* @property null|PHPParser_Node_Expr $key Key
* @property bool $byRef Whether to assign by reference
*/
class PHPParser_Node_Expr_ArrayItem extends PHPParser_Node_Expr
{
/**
* Constructs an array item node.
*
* @param PHPParser_Node_Expr $value Value
* @param null|PHPParser_Node_Expr $key Key
* @param bool $byRef Whether to assign by reference
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $value, PHPParser_Node_Expr $key = null, $byRef = false, array $attributes = array()) {
parent::__construct(
array(
'key' => $key,
'value' => $value,
'byRef' => $byRef
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_Assign extends PHPParser_Node_Expr
{
/**
* Constructs an assignment node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignBitwiseAnd extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with bitwise and node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignBitwiseOr extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with bitwise or node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignBitwiseXor extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with bitwise xor node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignConcat extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with concat node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignDiv extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with division node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignMinus extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with minus node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignMod extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with modulo node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignMul extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with multiplication node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignPlus extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with addition node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable reference is assigned to
* @property PHPParser_Node_Expr $expr Variable which is referenced
*/
class PHPParser_Node_Expr_AssignRef extends PHPParser_Node_Expr
{
/**
* Constructs an assignment node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignShiftLeft extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with left shift node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_AssignShiftRight extends PHPParser_Node_Expr
{
/**
* Constructs an assignment with right shift node.
*
* @param PHPParser_Node_Expr $var Variable
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_BitwiseAnd extends PHPParser_Node_Expr
{
/**
* Constructs a bitwise and node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_BitwiseNot extends PHPParser_Node_Expr
{
/**
* Constructs a bitwise not node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_BitwiseOr extends PHPParser_Node_Expr
{
/**
* Constructs a bitwise or node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_BitwiseXor extends PHPParser_Node_Expr
{
/**
* Constructs a bitwise xor node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_BooleanAnd extends PHPParser_Node_Expr
{
/**
* Constructs a boolean and node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_BooleanNot extends PHPParser_Node_Expr
{
/**
* Constructs a boolean not node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_BooleanOr extends PHPParser_Node_Expr
{
/**
* Constructs a boolean or node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
abstract class PHPParser_Node_Expr_Cast extends PHPParser_Node_Expr
{
/**
* Constructs a cast node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_Array extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_Bool extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_Double extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_Int extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_Object extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_String extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,5 +0,0 @@
<?php
class PHPParser_Node_Expr_Cast_Unset extends PHPParser_Node_Expr_Cast
{
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Name|PHPParser_Node_Expr $class Class name
* @property string $name Constant name
*/
class PHPParser_Node_Expr_ClassConstFetch extends PHPParser_Node_Expr
{
/**
* Constructs a class const fetch node.
*
* @param PHPParser_Node_Name|PHPParser_Node_Expr $class Class name
* @param string $name Constant name
* @param array $attributes Additional attributes
*/
public function __construct($class, $name, array $attributes = array()) {
parent::__construct(
array(
'class' => $class,
'name' => $name
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_Clone extends PHPParser_Node_Expr
{
/**
* Constructs a clone node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,35 +0,0 @@
<?php
/**
* @property PHPParser_Node[] $stmts Statements
* @property PHPParser_Node_Param[] $params Parameters
* @property PHPParser_Node_Expr_ClosureUse[] $uses use()s
* @property bool $byRef Whether to return by reference
* @property bool $static Whether the closure is static
*/
class PHPParser_Node_Expr_Closure extends PHPParser_Node_Expr
{
/**
* Constructs a lambda function node.
*
* @param array $subNodes Array of the following optional subnodes:
* 'stmts' => array(): Statements
* 'params' => array(): Parameters
* 'uses' => array(): use()s
* 'byRef' => false : Whether to return by reference
* 'static' => false : Whether the closure is static
* @param array $attributes Additional attributes
*/
public function __construct(array $subNodes = array(), array $attributes = array()) {
parent::__construct(
$subNodes + array(
'stmts' => array(),
'params' => array(),
'uses' => array(),
'byRef' => false,
'static' => false,
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property string $var Name of variable
* @property bool $byRef Whether to use by reference
*/
class PHPParser_Node_Expr_ClosureUse extends PHPParser_Node_Expr
{
/**
* Constructs a closure use node.
*
* @param string $var Name of variable
* @param bool $byRef Whether to use by reference
* @param array $attributes Additional attributes
*/
public function __construct($var, $byRef = false, array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'byRef' => $byRef
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Concat extends PHPParser_Node_Expr
{
/**
* Constructs a concat node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Name $name Constant name
*/
class PHPParser_Node_Expr_ConstFetch extends PHPParser_Node_Expr
{
/**
* Constructs a const fetch node.
*
* @param PHPParser_Node_Name $name Constant name
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Name $name, array $attributes = array()) {
parent::__construct(
array(
'name' => $name
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Div extends PHPParser_Node_Expr
{
/**
* Constructs a division node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_Empty extends PHPParser_Node_Expr
{
/**
* Constructs an empty() node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Equal extends PHPParser_Node_Expr
{
/**
* Constructs a equality comparison node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_ErrorSuppress extends PHPParser_Node_Expr
{
/**
* Constructs an error suppress node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_Eval extends PHPParser_Node_Expr
{
/**
* Constructs an eval() node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property null|PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Expr_Exit extends PHPParser_Node_Expr
{
/**
* Constructs an exit() node.
*
* @param null|PHPParser_Node_Expr $expr Expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr = null, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Name|PHPParser_Node_Expr $name Function name
* @property PHPParser_Node_Arg[] $args Arguments
*/
class PHPParser_Node_Expr_FuncCall extends PHPParser_Node_Expr
{
/**
* Constructs a function call node.
*
* @param PHPParser_Node_Name|PHPParser_Node_Expr $name Function name
* @param PHPParser_Node_Arg[] $args Arguments
* @param array $attributes Additional attributes
*/
public function __construct($name, array $args = array(), array $attributes = array()) {
parent::__construct(
array(
'name' => $name,
'args' => $args
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Greater extends PHPParser_Node_Expr
{
/**
* Constructs a greater than comparison node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_GreaterOrEqual extends PHPParser_Node_Expr
{
/**
* Constructs a greater than or equal node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Identical extends PHPParser_Node_Expr
{
/**
* Constructs an identicality comparison node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,30 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
* @property int $type Type of include
*/
class PHPParser_Node_Expr_Include extends PHPParser_Node_Expr
{
const TYPE_INCLUDE = 1;
const TYPE_INCLUDE_ONCE = 2;
const TYPE_REQUIRE = 3;
const TYPE_REQUIRE_ONCE = 4;
/**
* Constructs an include node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param int $type Type of include
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, $type, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr,
'type' => $type
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
* @property PHPParser_Node_Name|PHPParser_Node_Expr $class Class name
*/
class PHPParser_Node_Expr_Instanceof extends PHPParser_Node_Expr
{
/**
* Constructs an instanceof check node.
*
* @param PHPParser_Node_Expr $expr Expression
* @param PHPParser_Node_Name|PHPParser_Node_Expr $class Class name
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $expr, $class, array $attributes = array()) {
parent::__construct(
array(
'expr' => $expr,
'class' => $class
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr[] $vars Variables
*/
class PHPParser_Node_Expr_Isset extends PHPParser_Node_Expr
{
/**
* Constructs an array node.
*
* @param PHPParser_Node_Expr[] $vars Variables
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(
array(
'vars' => $vars
),
$attributes
);
}
}

View File

@ -1,22 +0,0 @@
<?php
/**
* @property array $vars List of variables to assign to
*/
class PHPParser_Node_Expr_List extends PHPParser_Node_Expr
{
/**
* Constructs a list() destructuring node.
*
* @param array $vars List of variables to assign to
* @param array $attributes Additional attributes
*/
public function __construct(array $vars, array $attributes = array()) {
parent::__construct(
array(
'vars' => $vars,
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_LogicalAnd extends PHPParser_Node_Expr
{
/**
* Constructs a logical and node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_LogicalOr extends PHPParser_Node_Expr
{
/**
* Constructs a logical or node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_LogicalXor extends PHPParser_Node_Expr
{
/**
* Constructs a logical xor node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,28 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $var Variable holding object
* @property string|PHPParser_Node_Expr $name Method name
* @property PHPParser_Node_Arg[] $args Arguments
*/
class PHPParser_Node_Expr_MethodCall extends PHPParser_Node_Expr
{
/**
* Constructs a function call node.
*
* @param PHPParser_Node_Expr $var Variable holding object
* @param string|PHPParser_Node_Expr $name Method name
* @param PHPParser_Node_Arg[] $args Arguments
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $var, $name, array $args = array(), array $attributes = array()) {
parent::__construct(
array(
'var' => $var,
'name' => $name,
'args' => $args
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Minus extends PHPParser_Node_Expr
{
/**
* Constructs a substraction node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Mod extends PHPParser_Node_Expr
{
/**
* Constructs a modulo node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_Mul extends PHPParser_Node_Expr
{
/**
* Constructs a multiplication node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Name|PHPParser_Node_Expr $class Class name
* @property PHPParser_Node_Arg[] $args Arguments
*/
class PHPParser_Node_Expr_New extends PHPParser_Node_Expr
{
/**
* Constructs a function call node.
*
* @param PHPParser_Node_Name|PHPParser_Node_Expr $class Class name
* @param PHPParser_Node_Arg[] $args Arguments
* @param array $attributes Additional attributes
*/
public function __construct($class, array $args = array(), array $attributes = array()) {
parent::__construct(
array(
'class' => $class,
'args' => $args
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_NotEqual extends PHPParser_Node_Expr
{
/**
* Constructs a not equal comparison node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

View File

@ -1,25 +0,0 @@
<?php
/**
* @property PHPParser_Node_Expr $left The left hand side expression
* @property PHPParser_Node_Expr $right The right hand side expression
*/
class PHPParser_Node_Expr_NotIdentical extends PHPParser_Node_Expr
{
/**
* Constructs a not identical comparison node.
*
* @param PHPParser_Node_Expr $left The left hand side expression
* @param PHPParser_Node_Expr $right The right hand side expression
* @param array $attributes Additional attributes
*/
public function __construct(PHPParser_Node_Expr $left, PHPParser_Node_Expr $right, array $attributes = array()) {
parent::__construct(
array(
'left' => $left,
'right' => $right
),
$attributes
);
}
}

Some files were not shown because too many files have changed in this diff Show More