Skip to content

Idea: Use tolerant-php-parser for error tolerance (Time consuming, requires php7) #520

@TysonAndre

Description

@TysonAndre

I'm mentioning this because it wasn't mentioned in other issues.
This is probably a long term project, and probably couldn't be started until php 5.6 support is dropped. (ext-suggest might work in composer.json)

Benefits of tolerant-php-parser:

  • Better recovery from parse errors. If nikic/php-parser encounters an error (E.g. { without a match in a method), it gives up on parsing nodes in the rest of the file.

    Error tolerance is useful if there were plans to run psalm as a background process that could respond to analysis requests (e.g. Language Server Protocol)

  • Reduced CPU usage from parsing and error diagnostics. (I assume that serialize()/igbinary_serialize() would be smaller on disk and faster to unserialize as well, but haven't benchmarked that)

    See Adopt Microsoft/tolerant-php-parser felixfbecker/php-language-server#357

    Traversing the tree would hopefully also be faster, but I haven't benchmarked that.

Drawbacks of tolerant-php-parser

Other notes:

A hybrid approach of converting tolerant-php-parser to php-parser (Only in cases where php-parser had at least one error) could work in theory. (https://github.com/TysonAndre/tolerant-php-parser-to-php-ast/ is an example of converting one AST format to another)

  • Writing a project to convert from one ast to another is time consuming to implement, debug, and test
  • The only benefit is better recovery from parse errors on syntactically invalid files, which isn't important right now

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions