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

215 Commits

Author SHA1 Message Date
nikic
4259b44a84 Add support for constant dereferencing (PHP 5.5)
Examples: "foo"[2], [1, 2, 3][2]
2012-09-07 23:41:58 +02:00
nikic
417a8bb07e Add support for yield expressions (PHP 5.5)
This adds a new Yield expression type, with subnodes key and value.
2012-09-07 23:41:57 +02:00
nikic
ae3774f0f2 Add support for finally clauses (PHP 5.5)
This adds a new finallyStmts subnode to the TryCatch node. If there is
no finally clause it will be null.
2012-09-07 23:41:56 +02:00
nikic
f8f1e17e41 Add support for list() in foreach (PHP 5.5)
Example: foreach ($coords as list($x, $y)) { ... }

This change slightly breaks backwards compatability, as it changes the
node structure for the previously existing `list(...) = $foo` assignments.
Those no longer have a dedicated `AssignList` node; instead they are
parsed as a normal `Assign` node with a `List` as `var`. Similarly the
use in `foreach` will generate a `List` for `valueVar`.
2012-09-07 23:41:55 +02:00
nikic
8d218110db Fix some doc comments 2012-09-07 23:41:54 +02:00
nikic
5a947e9843 Fix parsing of $foo =& new Bar;
By-reference assignments of new expressions are now parsed as AssignRef
(instead of just Assign).

Closes issue #31.
2012-07-23 11:36:47 +02:00
nikic
eb5991227d Add Class->getMethods() function 2012-07-07 16:24:07 +02:00
nikic
4137d7a7a8 Add modifier accessors for ClassMethod etc 2012-07-07 16:08:37 +02:00
nikic
35ec185558 Make $line argument for Comment optional
Also add setLine() method.
2012-06-08 17:55:35 +02:00
Jon Cave
0911b2e1ce Add line number information to comments
Line numbers are stored in the $line property of the PHPParser_Comment
and PHPParser_Comment_Doc classes and can be retrieved with getLine().
2012-06-06 14:33:38 +01:00
nikic
e16513a0eb Fix parsing of new expressions in parenthesis
The new dereferencing syntaxes (new Foo)->bar and (new Foo)['bar'] were
causing a shift/reduce conflict with the '(' expr ')' rule. When
(new Foo) was encountered (without dereference operators following) the
parser thus threw a parse error.

The fix simply adds a special '(' new_expr ')' rule to expr. This does not
remove the shift/reduce conflict itself, but makes it irrelevant.

This fixes issue #20.
2012-05-12 14:11:10 +02:00
nikic
10fc22f518 Replace \N with .
Older PCRE versions (coming with PHP 5.2) don't support \N yet.
2012-05-11 20:38:05 +02:00
nikic
93392c82e0 Fix getAttribute signature in Node interface
This fixes a build failure on PHP 5.2.
2012-05-11 18:48:23 +02:00
nikic
dab2fd4b7a Fix comment reformatting on Linux
Remove the use of \R (with BSR_ANYCRLF) at two places, as it was causing
problems there.
2012-05-11 18:45:55 +02:00
nikic
81e53ce0ff Insert comments when pretty printing
This changset also adds unit tests for Comments and adds a way to test the
pretty printer.
2012-05-11 16:18:14 +02:00
nikic
a824a2aba7 Fix $node->getDocComment()
getDocComment() now returns the last comment (given that it is a doc
comment). setDocComment() no longer exists, as it doesn't make sense
with the comment objects anymore. getAttribute() now returns by reference,
so it also works in reference contexts.
2012-05-06 18:24:26 +02:00
nikic
9d96dd1796 Adjust XML unserializer for new comments attribute 2012-05-06 18:12:02 +02:00
nikic
e587e3f4c6 Collect normal comments too, not only doc comments
Comments and doc comments are now saved in the 'comments' attribute, as an
array. The are instances of PHPParser_Comment[_Doc].
2012-05-06 17:49:04 +02:00
nikic
dd711f2a04 Generalize the attribute generation for nodes
Now two arrays are fetched from the lexer: $startAttributes and
$endAttributes. When constructing the attributes for a node, the
$startAttributes from the first token of the node and the $endAttributes
of the last token of the node are merged.

Now the end line is saved in the endLine attribute.
2012-05-05 17:34:27 +02:00
nikic
101a6ddcfc Fix NameResolver to properly copy attributes 2012-05-04 10:18:50 +02:00
nikic
2f5ebf7c4d Store line and doc comment as attributes 2012-05-04 10:16:59 +02:00
nikic
f66a672dd0 Start refactoring parser skeleton
The yacc parser skeleton with all those odd $yy short names is quite
non-obvious. This commits starts to refactor it a bit, to use more
obvious names and logic.
2012-05-04 10:16:49 +02:00
nikic
3701e02d32 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);
2012-05-04 10:16:46 +02:00
Johannes M. Schmitt
c2c7fdd13d fixes a bug were line number were lost 2012-05-03 23:58:47 -05:00
Johannes M. Schmitt
0dae07af6b fixes a bug where catch type was not resolved 2012-05-03 23:52:39 -05:00
nikic
b42c9209c7 Fix PHP 5.2 build failure
lcfirst() isn't defined on PHP 5.2, so I added a fallback function, which
is defined in the bootstrap.php. Not sure whether that's the right place
to put it.
2012-04-23 22:17:06 +02:00
nikic
9329c91591 Merge branch 'codeGeneration'
* codeGeneration:
  Add docs for templates
  Add a filesystem template loader.
  Add simple templating support.
  Add usage example for builders to docs
  Add function builder
  Add ability to specify arrays as default values
  Add property builder
  Add parameter builder
  Add method builder
  Add class builder
2012-04-23 13:32:16 +02:00
nikic
5b27fb40ce Fix line numbers for some list structures
When defining a list in the grammar the list elements have to get a separate
rule, otherwise they'll all be assigned the same line number.
2012-04-19 00:52:44 +02:00
nikic
e2a9745bf1 Make Serializer_XML::_serialize protected 2012-04-19 00:25:13 +02:00
nikic
a45360ccaf Add tests for node attributes
Also fix the @inheritDoc declarations and do some whitespace normalization
2012-04-19 00:22:31 +02:00
Sebastian Bergmann
b9e3565587 Fugbix typo. 2012-04-04 15:54:45 +02:00
nikic
337da5648c Fix XML unserializer
The subNodes array was not initialized, so for empty nodes it would just
be null. Due to the addition of attributes for nodes those have to be
initialized too.
2012-04-04 14:06:08 +02:00
nikic
a048112e2c Add a filesystem template loader.
The template loaders loads templates from a base directory (and can
optionally use a suffix). For example

    $templateLoader = new PHPParser_TemplateLoader(
        $parser, './templates', '.php'
    );

    // loads ./templates/TestTemplate.php
    $templateLoader->load('TestTemplate');

Again the implementation is not optimal. The loader probably shouldn't
intantiate the Template itself, but instead should accept a
TemplateFactory. This seemed like overkill to me, so I left it out.
2012-04-03 23:52:00 +02:00
nikic
19c1f80589 Add simple templating support.
Templates use __name__ placeholders. A variant of the placeholder with a
capitalized first latter can be accessed using __Name__ (this is useful
for camel case identifiers, e.g. get__Name__).

Currently the implemention is not particularly clean, because the Template
instantiates a Lexer itself. Fixing this requires a major refactoring of
the lexer/parser interface.
2012-04-03 22:47:41 +02:00
Johannes
2ccae143d0 added implementations for the new interface methods 2012-04-03 13:07:10 -05:00
Johannes
e932711fa4 added some methods for storing metadata to the interface 2012-04-03 13:04:24 -05:00
nikic
b8b68a969c Add function builder 2012-03-11 09:02:52 +01:00
nikic
9e5c95b6aa Add ability to specify arrays as default values 2012-03-11 08:53:04 +01:00
nikic
3ce3542032 Add property builder 2012-03-11 08:42:13 +01:00
nikic
4c8351fa86 Add parameter builder 2012-03-11 00:06:02 +01:00
nikic
48f0322aef Add method builder 2012-03-10 23:25:26 +01:00
nikic
88e1f2eeab Add class builder 2012-03-10 17:56:56 +01:00
nikic
d7407af87d Remove unused variable 2012-03-03 17:01:28 +01:00
nikic
2ed6cac7c1 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. That "feature" turned out to be a real pain in the ass on some occasions ;)
2012-03-03 16:50:45 +01:00
nikic
6657ac4b76 Clarify that parser is autogenerated 2012-03-02 00:43:34 +01:00
nikic
168982a912 Don't replace \ followed by { with NS_SEPARATOR 2012-02-21 19:28:40 +01:00
nikic
d98a65086b Minor refactor and comments for emlative lexer
The emulative lexer is a single dirty hack so it needs a few more comments :)
2012-02-21 17:56:07 +01:00
nikic
608cfbba4e Factor out error handling out of Lexer construcor
Makes the constructor more concise and puts the strange error handling stuff in separate methods
2012-02-21 17:00:49 +01:00
nikic
cf3117d82d Fix parsing of integers that overflow into floats
Integers in hex/oct/bin notation that overflowed into floats were parsed incorrectly.
2012-01-15 16:54:48 +01:00
nikic
faf0351bab Fix emulation of binary floats
All binary literals were lexed as integers, even if they were floats
2012-01-15 16:37:18 +01:00