Giter VIP home page Giter VIP logo

php-parser's Introduction

php-parser

This JavaScript library parses PHP code and converts it to an AST.

Installation

This library is distributed with npm :

npm install php-parser --save

Usage

// initialize the php parser factory class
const fs = require("fs");
const path = require("path");
const engine = require("php-parser");

// initialize a new parser instance
const parser = new engine({
  // some options :
  parser: {
    extractDoc: true,
    php7: true,
  },
  ast: {
    withPositions: true,
  },
});

// Retrieve the AST from the specified source
const eval = parser.parseEval('echo "Hello World";');

// Retrieve an array of tokens (same as php function token_get_all)
const tokens = parser.tokenGetAll('<?php echo "Hello World";');

// Load a static file (Note: this file should exist on your computer)
const phpFile = fs.readFileSync("./example.php");

// Log out results
console.log("Eval parse:", eval);
console.log("Tokens parse:", tokens);
console.log("File parse:", parser.parseCode(phpFile));

Sample AST output

{
  'kind': 'program',
  'children': [
    {
      'kind': 'echo',
      'arguments': [
        {
          'kind': 'string',
          'isDoubleQuote': true,
          'value': 'Hello World'
        }
      ]
    }
  ]
}

API Overview

The main API exposes a class with the following methods :

  • parseEval(String|Buffer) : parse a PHP code in eval style mode (without php open tags)
  • parseCode(String|Buffer, String filename) : parse a PHP code by using php open tags.
  • tokenGetAll(String|Buffer) : retrieves a list of all tokens from the specified input.

You can also pass options that change the behavior of the parser/lexer.

Documentation

Related projects

  • prettier/plugin-php : Prettier PHP Plugin
  • babel-preset-php : Babel preset for converting PHP syntax to JavaScript. It can run subset of PHP in the browser or in Node.js
  • wp-pot : Generate pot file for WordPress plugins and themes
  • crane : PHP Intellisense/code-completion for VS Code
  • php-unparser : Produce code that uses the style format recommended by PSR-1 and PSR-2.
  • php-writer : Update PHP scripts from their AST
  • ts-php-inspections : Provide PHP code inspections written in typescript
  • php-reflection : Reflection API for PHP files
  • vscode-phpunit : vscode phpunit extension
  • lua2php : a Lua to PHP transpiler

You can add here your own project by opening an issue request.

License

This library is released under BSD-3 license clause.

php-parser's People

Contributors

alexander-akait avatar allejo avatar aterrien avatar bbtgp avatar cseufert avatar czosel avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar evilebottnawi avatar fossabot avatar genintho avatar ichiriac avatar jodysimpson avatar justim avatar loilo avatar maartenstaa avatar motiz88 avatar nevadascout avatar northblue333 avatar rainx avatar recca0120 avatar rom1504 avatar selion05 avatar sopamo avatar ssigwart avatar sxxov avatar tldmain avatar ytetsuro avatar zaoqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-parser's Issues

bad variable parsing

Need investigations to understand why, to reproduce :

Error on test/token/yii2/framework/rbac/migrations/m140506_102106_rbac_init.php
[Error: Test "test/token/yii2/framework/rbac/migrations/m140506_102106_rbac_init.php" does not pass !]
FAIL : Expected T_VARIABLE token, but found "$" symbol
FAIL : Token arrays have not the same length !
Error at : test/token/yii2/framework/web/ErrorHandler.php
JS Tokens [ '$' ]
PHP Tokens [ [ 'T_VARIABLE', '$key', 421 ] ]
Error: Test "test/token/yii2/framework/web/ErrorHandler.php" does not pass !
    at test (/home/travis/build/glayzzle/php-parser/bin/test.js:174:19)
    at runTests (/home/travis/build/glayzzle/php-parser/bin/test.js:319:9)
    at /home/travis/build/glayzzle/php-parser/bin/test.js:217:7
    at done (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/mocha.js:498:13)
    at Runner.<anonymous> (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:799:5)
    at Runner.emit (events.js:129:20)
    at /home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:786:12
    at /home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:639:9
    at next (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:284:14)
    at Immediate._onImmediate (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:320:5)
Error on test/token/yii2/framework/web/ErrorHandler.php
[Error: Test "test/token/yii2/framework/web/ErrorHandler.php" does not pass !]

Only closures can `use` variables

Actually every function can handle the use keyword and store it on ast.

Should be much more strict and enable it's parsing only to closures

Add a cosmetic mode

This parser could be used to rebuild back from the AST a document, so some informations are lost during the transformations from tokens to AST.

With a cosmetic option set to true, we could retrieve these informations like :

  • T_INLINE_HTML tags instead their T_ECHO transformation
  • Whitespaces
  • Short tags forms
  • The brackets mode on namespaces or declares
  • The optional paranthesis on echo, require ...

This list may not be exaustive, has to be improved

@todo Write the spec in the wiki

Curlies around variable names in encapsulated strings are mishandled

"use strict";
var engine = require('php-parser');
var parser = new engine({});
var AST1 = parser.parseEval('echo "Hello ${world}";');
console.log(AST1.children[0].arguments[0].value[1]);
var AST2 = parser.parseEval('echo "Hello " . ${world};');
console.log(AST2.children[0].arguments[0].right);

Output is:

Variable {
  kind: 'variable',
  name: Variable { kind: 'variable', name: 'orld', byref: false },
  byref: false }
Variable {
  kind: 'variable',
  name: 
   ConstRef {
     kind: 'constref',
     name: Identifier { kind: 'identifier', resolution: 'uqn', name: 'world' } },
  byref: false }

The two items should be the same. Presumably php-parser is treating it like an explicit interpolated expression (eg. {$world}) by skipping the first character.

Comments in the same line as an expression

If I try to parse this:

echo $a; // this is a comment
echo $b;

Its get parsed like this:

  ["sys", "echo", [["var","$a"]]],
  ["comment", ["// this is a comment\n"]],
  ["sys", "echo", [["var","$b"]]]

Which is the same AST I get if I parse this instead:

echo $a;

// this is a comment
echo $b;

That is a problem, because in the first case the comment belongs to echo $a, while the second case is more likely to be a comment about echo $b.

Perhaps it should be a decorator, with a property saying its in the same line? I'm not sure what would be the right thing to do. What do you think about this?

fix inifinite lexer loop on `parser.suppressErrors` mode

The parser/lexer starts an infinite loop when reaches the end and gets an error on last statement.

Code to reproduce error :

  var AST = parser.create({
    lexer: {
      debug: true
    },
    parser: {
      suppressErrors: true,
      debug: true
    }
  }).parseCode('<?php echo b');

Bug with bitwise operators

http://php.net/manual/en/language.operators.bitwise.php

I'm currently using php-parser to parse the PocketMine project and I'm getting an error on this file https://github.com/PocketMine/PocketMine-MP/blob/mcpe-0.12/src/pocketmine/network/protocol/UpdateBlockPacket.php#L36

Error: Parse Error : unexpected '(', expecting 'SCALAR'
    at Object.api.error (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser.js:165:13)
    at Object.read_scalar (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/scalar.js:88:18)
    at Object.read_constant_declaration (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/class.js:172:10)
    at Object.api.read_list (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser.js:245:28)
    at Object.read_constant_list (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/class.js:155:10)
    at Object.read_class_body (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/class.js:85:38)
    at Object.read_class (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/class.js:39:34)
    at Object.read_top_statement (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/statement.js:48:23)
    at Object.read_top_statements (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/statement.js:17:26)
    at Object.read_namespace (/media/documents/Documents/programmation/interlangage/minecraft/mcpe-protocol-extractor/node_modules/php-parser/src/parser/namespace.js:31:34)

It seems the problem is some case of bitwise operators that are not handled.

Make the class body consistent with the AST nodes

Unlike function or namespaces bodies, the class body is an object regroupping constants, properties, traits and methods.

  • The body is not consistent with the nested arrays design (so generic transversal is not possible)
  • There is no need to use object properties as nodes are typed (list of const in the const property ?!)
  • The document representation is broken (#39)

It's an important change in order to finalise a consistent version

bad line number on edge cases

Oversimplified management on unput function.

https://github.com/glayzzle/php-parser/blob/master/src/lexer.js#L81

To reproduce the bug :

NOTICE : Expected line 95, but found 96
Error at : test/token/yii2/framework/rbac/migrations/m140506_102106_rbac_init.php
JS Tokens [ [ 'T_ENCAPSED_AND_WHITESPACE',
    'CREATE TRIGGER dbo.trigger_auth_item_child\n            ON dbo.',
    96 ] ]
PHP Tokens [ [ 'T_ENCAPSED_AND_WHITESPACE',
    'CREATE TRIGGER dbo.trigger_auth_item_child\n            ON dbo.',
    95 ] ]
Error: Test "test/token/yii2/framework/rbac/migrations/m140506_102106_rbac_init.php" does not pass !
    at test (/home/travis/build/glayzzle/php-parser/bin/test.js:174:19)
    at runTests (/home/travis/build/glayzzle/php-parser/bin/test.js:319:9)
    at /home/travis/build/glayzzle/php-parser/bin/test.js:217:7
    at done (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/mocha.js:498:13)
    at Runner.<anonymous> (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:799:5)
    at Runner.emit (events.js:129:20)
    at /home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:786:12
    at /home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:639:9
    at next (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:284:14)
    at Immediate._onImmediate (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:320:5)

Should fix this without degrading performances

Nodes positions in the AST

Hi,

I was wondering if an option could be added to the library API that would add positional metadata concerning each node in the AST.

ie :

phpParser.evalCode(..., {locations: true})
// -> would return an AST with a location member for each node such as : 
// {start: {row: 3, col: 5}, end: {row: 3, col: 11}}

I have looked at the existing code and while these locations are saved by the lexer, they are not kept by the parser. Do you think it would be difficult to add this behaviour to the library ? The only way I've found to add this information is to change every functions in the parser directory in order to append locations to the returned lists, but it would be quite difficult to do.

New release to NPM

I'd love to use the new node locations feature, but to do that I'd have to manually copy the source and reference it in my project.

Is it possible to have a new version with the latest changes released onto NPM?

Thanks!

Issue with comment

Great job with this module, It's almost perfect but the parseCode method is skipping the comment.
We would like to use the parser to decompose and rewrite our php class (in order to enrich them), but, it's actually impossible to rewrite without the comments (for obvious reason).
Is it possible to add this feature to your module?
Regards.

Dose it parse any project with a lot of file?

Hello.
I think, this is a good library an useful.
I have a problem.
When i use single file, out put is correct, but use one project include some file with commands for example requier and include, php parser create AST for any file separately and then create cfg for any file separately.
Can php parser , parse project and recognize include or require?

Thank you.

release 0.1.0

Entire rewrite of the lexer.

Some benchmark results npm run bench :

--- parsing files - actual lexer version :
Tokens extracted      : 1375000
Tokens by sec (x1000) : 2077.6
Total duration        : 661.8 ms
Memory                :  160 kb

--- parsing files - jison lexer version :
Tokens extracted      : 1373000
Tokens by sec (x1000) : 251.8
Total duration        : 5452.2 ms
Memory                :  223 kb

--- parsing files - plain PHP version :
Tokens extracted      : 1375000
Tokens by sec (x1000) : 1838.1
Total duration        : 748.1 ms
Memory                :  256 kb

--- results Actual vs Jison :
Is 724% more rapid
Use 28% less memory

--- results Actual vs PHP :
Is 13% more rapid
Use 38% less memory

--- results Jison vs PHP :
Is 629% more slower
Use 13% less memory

Looking for help in order tests / increase code coverage (@nevadascout ?)

Pending fixme/todo :

  • passing all php7 syntax updates
  • cover over 80% of code (and 90% of lexer)
  • bad column implementation
  • handle columns and lines revert

Function node location has incorrect start colum

In the screenshot below, the grey boxes show that the parser is reporting that the function starts at col 11 -- immediately after the public access modifier.

I believe it should report 4 as the start column.

improve parsing speed

The lexer speed (reading a string from memory) is about 2,5 millions tokens / sec (depends on CPU).

It's about 3 times more slower than original PHP algorithm, but about 16 times more rapid than a jison based version (which is also more rapid than a regex version ...)

The lexer algorithm could be improved a bit, but there will not be much gain here.

The parser sometimes is 10x slower than the lexer, there is a lot of room to improve the speed, the most cost effective part is recursive parsing on structures like arrays, property chains or string concatenations.

Infinite loop when parsing `trait`

Hey guys, what's up?

I'm struggling with a infinite loop (...and I can't win) when I parse a file that contains trait, how can I fix?

Thanks,
Hugs!

๐Ÿป

Improve tests over comments

In order to validate the extractDoc option, each AST statement should be tested over each edge case with inner comments.

Related issues :

Todo list :

  • IF
  • TRY/CATCH/FINALLY
  • CLASS / TRAIT
  • INTERFACE
  • FUNCTION
  • FOR
  • FOREACH
  • DO / WHILE
  • SWITCH
  • CALL
  • ARRAYS
  • LIST
  • NAMESPACE

use a framework for tests

Need to improve tests codes with some use cases and get the tests driven development simpler :

  • coverage will be generated with istanbul
  • automatic coverage tests will be done with coveralls
  • functionnal tests will be done with mocha

Will add a new symphony framework for generic parsing abilities

Few improvements

Love the idea behind this module. I'd love to use it to extract the dependencies of a php file (i.e., any traits, included/required files, namespaces).

Would be great if the following were possible:

  1. Invoke the parser on code that has an opening <?php tag without an error being thrown:
    image
  2. Get back an AST that is in an object form instead of a nested list. This would have the PHP AST in the same data structure as JavaScript ASTs (produced by libs like Esprima). I could then reuse a tree walker lib to traverse objects instead of nested lists.
  3. Parts of the test.php file really should be converted into a node binary script: create a bin/cli.js file that resembles (https://github.com/mrjoelkemp/node-dependents/blob/master/bin/dependents.js). This should allow folks to get an ast by supplying a filename via the cli. Your cli script would then read the contents of the file, pipe it to the parser, then pipe the AST to the console.
  4. Related to ^^, you can just omit the hand-rolled argument handling by using commander. It's battle-tested, already does what you want, and cuts down on the amount of code one has to sift through when looking at the binary file.

I'm happy to help make this lib into a more friendly node module. However, I need your expertise to achieve the second request.

Issue parsing a call that has spaces before the opening paren.

If I try to parse this:

someFunc (); // Notice that I added one whitespace before the paren

it gets parsed as this

["call",["ns",["omeFunc"]],[]] // is missing the first letter, "s"

If then I try to add more spaces, it reduces the name of the function by each space added.

someFunc   (); // Now it has 3 whitespaces
["call",["ns",["eFunc"]],[]] // and the parsing returns the function shorter by 3 characters

And if I add as many spaces as the name of the function (or more), it returns

Parse Error : unexpected ')', expecting 'EXPR' at line x

While its true that adding spaces before the opening paren is unusual (and a bad habit and it looks really bad), technically is valid php.

Function node location has incorrect end line

The red boxes in the image below shows that the function ends on line 17, but the parser is reporting line 14 as the end.

I haven't tested any other node types to see if they are affected as well

Cleanup the code

  • Add "use strict" statement on every file
  • Check & investigate each @todo / @fixme statement
  • Pass with JSHint on every file
  • Use ES6
  • Add a transpiler for ES5 support

Validate the API

As said in #61, need to pass over :

  • Check consistency in the AST tree
  • Check variables names (avoid importing $ prefix)
  • Check nested block nodes (example into function bodies) - avoid extra levels

A call to a global function is parsed the same as one without namespace

Hi!
If I parse someFunc(); and \someFunc();, both get parsed exactly as:

["call",
  ["ns", ["someFunc"]],
  []]

Which means I don't have any reference that tells me if I'm calling a function from the global namespace or not.

Perhaps \someFunc(); should get parsed as:

["call",
  ["ns", ["", "someFunc"]],
  []]

(Notice the empty string)
What you think about it?

By the way, great parser!

Option to suppress errors

It would be great if we could set an option on the parser to suppress errors.

This would prevent the parser from throwing an exception when encountering a parse error, and instead just return the AST built up to that point.

Parser crashes when encountering property call inside string

So I have some code: echo "test: $this->prop->foo".

When trying to parse this code, the parser crashes without an error, however adding { } around the property call resolves the issue and it parses successfully.

So echo "test: {$this->prop->foo}" works.

Even if this behaviour is not allowed in PHP, the parser should throw an exception so it can be caught on the user side. Currently this code crashes my application without warning, regardless if I use a try/catch block or not.

Compatibility with browserify

Hey! I just created a demo for php-unparser (that of course uses php-parser), inspired by the demo of escodegen.

I decided to do it by wrapping both php-parser and php-unparser using browserify, but browserify wasn't able to do it!

The reason was that both of them were doing require with fs.readdirSync, and it seems browserify don't like that. So I changed php-unparser to have the requires directly added (I'm using a makefile to automate that) and then browserify was able to wrap it.

In the case of php-parser, I replaced the blocks of readdirSync with something like this:

[
    require('./lexer/comments.js')(api, tokens),
    require('./lexer/initial.js')(api, tokens),
    require('./lexer/numbers.js')(api, tokens),
    require('./lexer/property.js')(api, tokens),
    require('./lexer/scripting.js')(api, tokens),
    require('./lexer/strings.js')(api, tokens),
    require('./lexer/tokens.js')(api, tokens),
    require('./lexer/utils.js')(api, tokens)
].forEach(function (ext) {
    for(var k in ext) {
      api[k] = ext[k];
    }
});

With that change I was able to browserify php-parser.

I think it would be nice if php-parser was able to be directly browserified. But of course, is your project and you can decide not to do it.

Also, I'm not saying you should do it like that. Perhaps you would prefer to do it some other way or automatically add the requires, or maybe you do know how to make browserify to process the files even with readdirSync - I wasn't able to do it.

error parsing opencart

See HvyIndustries/crane#178 (comment) - Open Cart is not parsed correctly.

From Travis :

FAIL : Expected T_WHITESPACE token, but found T_INLINE_HTML
Error at : test/token/opencart/upload/catalog/model/extension/shipping/sf_express.php
JS Tokens [ [ 'T_INLINE_HTML', '\n', 273 ] ]
PHP Tokens [ [ 'T_WHITESPACE', '\n', 273 ] ]
Error: Test "test/token/opencart/upload/catalog/model/extension/shipping/sf_express.php" does not pass !
    at test (/home/travis/build/glayzzle/php-parser/bin/test.js:174:19)
    at runTests (/home/travis/build/glayzzle/php-parser/bin/test.js:319:9)
    at /home/travis/build/glayzzle/php-parser/bin/test.js:217:7
    at done (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/mocha.js:498:13)
    at Runner.<anonymous> (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:799:5)
    at Runner.emit (events.js:129:20)
    at /home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:786:12
    at /home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:639:9
    at next (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:284:14)
    at Immediate._onImmediate (/home/travis/build/glayzzle/php-parser/node_modules/mocha/lib/runner.js:320:5)`

Using the standard format for the AST, used by PHP 7

Hi!

I read your comment on #41, and I was thinking about how the resulting AST is going to be.

After checking this repository: https://github.com/nikic/php-ast, it seems there is an official format for a PHP AST, that is generated by PHP 7. (I haven't tested it, but according to it's readme, this project is just exposing the AST that PHP7 generates on it's own)

One of the things I noticed there is that it seems the PHP 7 AST is formed by assoc arrays, which are like JavaScript object literals, instead of using numeric arrays.

Now, I do like how your AST looks like (since it reminds me to Lisp, and IMO, Lisp looks very elegant), but I do think an AST based on objects literals would be more practical.

Right now, in certain cases, I'm checking for the number of elements an array has, but that number will change as soon the AST requires new elements. For instance, on php-unparser class translator, I have an if (method.length === 7) to check if the method has a body (otherwise is an abstract method). But that will break if later becomes necessary to add more elements to the methods and then the number of elements a methods goes to 10 or something. On an object-based AST, I could check for something like if (!method.body) instead, and the amount of properties that the method has would be irrelevant.

But more important than just being easier and more stable, it seems to me that is really important to use and follow one standard AST.

Like in the case of esprima, they don't use their own AST, instead, they use an standard JavaScript AST spec called estree, that was originally created by mozilla.

Since the AST of PHP 7 could be considered as the official format of the AST, I think it would be better to follow that format. Perhaps even would be a good idea to create a project like estree to document the PHP7 AST and create a more formal spec.

Parse php 7 & make the build to pass

Error: Parse Error : unexpected ':', expecting '{' at line 167
at Object.api.error (/home/travis/build/glayzzle/php-parser/src/parser.js:218:15)
at Object.api.expect (/home/travis/build/glayzzle/php-parser/src/parser.js:322:16)
at Object.read_function (/home/travis/build/glayzzle/php-parser/src/parser/function.js:44:16)
at Object.read_class_body (/home/travis/build/glayzzle/php-parser/src/parser/class.js:121:29)
at Object.read_class (/home/travis/build/glayzzle/php-parser/src/parser/class.js:39:34)
at Object.read_top_statement (/home/travis/build/glayzzle/php-parser/src/parser/statement.js:48:23)
at Object.read_start (/home/travis/build/glayzzle/php-parser/src/parser/main.js:18:21)
at Object.api.parse (/home/travis/build/glayzzle/php-parser/src/parser.js:188:31)
at Object.engine.parseCode (/home/travis/build/glayzzle/php-parser/main.js:77:19)
at Object.module.exports.run (/home/travis/build/glayzzle/php-parser/bin/formats/php.js:19:20)
Error on test/token/symfony/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_with_hints.php
[Error: Parse Error : unexpected ':', expecting '{' at line 167]


FAIL : Expected "
" contents, but found "
EOF;
if ("
FAIL : Token arrays have not the same length !
Error at : test/token/symfony/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
JS Tokens [ [ 'T_ENCAPSED_AND_WHITESPACE', '\nEOF;\n\n if (', 820 ] ]
PHP Tokens [ [ 'T_ENCAPSED_AND_WHITESPACE', '\n', 820 ] ]
Error: Test "test/token/symfony/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php" does not pass !
at test (/home/travis/build/glayzzle/php-parser/bin/test.js:153:19)
at Object. (/home/travis/build/glayzzle/php-parser/bin/test.js:268:7)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
Error on test/token/symfony/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
[Error: Test "test/token/symfony/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php" does not pass !]


Error: Parse Error : unexpected ':', expecting '{' at line 19
at Object.api.error (/home/travis/build/glayzzle/php-parser/src/parser.js:218:15)
at Object.api.expect (/home/travis/build/glayzzle/php-parser/src/parser.js:322:16)
at Object.read_function (/home/travis/build/glayzzle/php-parser/src/parser/function.js:44:16)
at Object.read_class_body (/home/travis/build/glayzzle/php-parser/src/parser/class.js:121:29)
at Object.read_class (/home/travis/build/glayzzle/php-parser/src/parser/class.js:39:34)
at Object.read_top_statement (/home/travis/build/glayzzle/php-parser/src/parser/statement.js:48:23)
at Object.read_top_statements (/home/travis/build/glayzzle/php-parser/src/parser/statement.js:17:26)
at Object.read_namespace (/home/travis/build/glayzzle/php-parser/src/parser/namespace.js:31:34)
at Object.read_start (/home/travis/build/glayzzle/php-parser/src/parser/main.js:16:21)
at Object.api.parse (/home/travis/build/glayzzle/php-parser/src/parser.js:188:31)
Error on test/token/symfony/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php7Dummy.php
[Error: Parse Error : unexpected ':', expecting '{' at line 19]


PHP Parse error: syntax error, unexpected 'parseError' (T_STRING), expecting function (T_FUNCTION) in test/token/zf2/tests/ZendTest/Loader/_files/ParseError.php on line 15

Add a support for a graceful parsing mode

Like explained into this thead :
#12

Introducing a new AST node type :
["error", tokenName, [expected...], lineNumber]

To enable to option we could write (disabled by default) :

var ast = parser.parseEval('...some code...', {
  parser: {
    gracefull: true
  }
})

implement encapsed nodes

Needs implementations of AST nodes & tests :

  • encapsed strings
  • encapsed shell
  • here doc nodes
  • nowdoc nodes
  • encapsed nowdoc nodes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.