Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thm-mni-ii/php-parser
A Scala-based parser for the latest PHP versions
https://github.com/thm-mni-ii/php-parser
java parser parsing php php-parser php7 phpparser scala
Last synced: 3 months ago
JSON representation
A Scala-based parser for the latest PHP versions
- Host: GitHub
- URL: https://github.com/thm-mni-ii/php-parser
- Owner: thm-mni-ii
- License: mit
- Created: 2017-07-28T08:27:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-12T08:38:56.000Z (about 6 years ago)
- Last Synced: 2024-10-12T13:03:58.766Z (3 months ago)
- Topics: java, parser, parsing, php, php-parser, php7, phpparser, scala
- Language: Scala
- Size: 131 KB
- Stars: 12
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP-Parser [![Build Status](https://travis-ci.org/thm-mni-ii/PHP-Parser.svg?branch=master)](https://travis-ci.org/thm-mni-ii/PHP-Parser) [![Coverage Status](https://coveralls.io/repos/github/thm-mni-ii/PHP-Parser/badge.svg?branch=master)](https://coveralls.io/github/thm-mni-ii/PHP-Parser?branch=master)
This project contains a PHP-Parser based on the current [php language specification](https://github.com/php/php-langspec). It supports PHP version 7.The parser is written in Scala, but can be used in **Java** as well as in **Scala** projects.
Based on [FastParse](https://github.com/lihaoyi/fastparse) it transforms a valid PHP-Script into an abstract syntax tree.## Getting Started
Import the artifacts from Maven Central.
```xml
de.thm.mni.ii
phpparser
1.0.0```
## Usage
These simple examples present the basic usage of the parser.
#### Java
```java
import de.thm.mni.ii.phpparser.PHPParser;
import de.thm.mni.ii.phpparser.ast.Basic;public class Main {
public static void main(String[] args) {
PHPParser.Result res = (PHPParser.Result) PHPParser.parse(" println(s.script)
case f: PHPParser.Failure => println(f.fullMsg)
}
}
```The top-level __PHPParser__ parses a whole PHP-Script. The result is an instance of __PHPParser.Success__ or __PHPParser.Failure__.
__PHPParser.Success__ contains the abstract syntax tree. __PHPParser.Failure__ contains additional information about the error. If you need further error information, take a look at the _failure_-member. FastParse provides additional methods to present the origin of the parse-error.
## Project Structure
```
.
├── ...
├── src/main/scala/de/thm/mni/ii/phpparser
│ ├── PHPParser.scala # top-level parser
│ ├── ast/ # case classes of abstract syntax tree
│ └── parser/ # specific parsers for all different elements
└── ...
```## Contribute
Feel free to send Pull-Requests to improve this parser. If you find a bug, please report it as an issue on github.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details