{"id":15029029,"url":"https://github.com/thm-mni-ii/php-parser","last_synced_at":"2025-04-09T20:32:23.432Z","repository":{"id":57730984,"uuid":"98627477","full_name":"thm-mni-ii/PHP-Parser","owner":"thm-mni-ii","description":"A Scala-based parser for the latest PHP versions","archived":false,"fork":false,"pushed_at":"2018-10-12T08:38:56.000Z","size":134,"stargazers_count":12,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-23T22:25:27.167Z","etag":null,"topics":["java","parser","parsing","php","php-parser","php7","phpparser","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thm-mni-ii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-28T08:27:24.000Z","updated_at":"2024-05-31T16:25:50.000Z","dependencies_parsed_at":"2022-09-26T22:01:41.637Z","dependency_job_id":null,"html_url":"https://github.com/thm-mni-ii/PHP-Parser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thm-mni-ii%2FPHP-Parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thm-mni-ii%2FPHP-Parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thm-mni-ii%2FPHP-Parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thm-mni-ii%2FPHP-Parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thm-mni-ii","download_url":"https://codeload.github.com/thm-mni-ii/PHP-Parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107593,"owners_count":21048962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","parser","parsing","php","php-parser","php7","phpparser","scala"],"created_at":"2024-09-24T20:09:36.206Z","updated_at":"2025-04-09T20:32:23.408Z","avatar_url":"https://github.com/thm-mni-ii.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"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)\nThis project contains a PHP-Parser based on the current [php language specification](https://github.com/php/php-langspec). It supports PHP version 7.\n\nThe parser is written in Scala, but can be used in **Java** as well as in **Scala** projects.\nBased on [FastParse](https://github.com/lihaoyi/fastparse) it transforms a valid PHP-Script into an abstract syntax tree.\n\n## Getting Started\n\nImport the artifacts from Maven Central.\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ede.thm.mni.ii\u003c/groupId\u003e\n  \u003cartifactId\u003ephpparser\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Usage\n\nThese simple examples present the basic usage of the parser.\n\n#### Java\n```java\nimport de.thm.mni.ii.phpparser.PHPParser;\nimport de.thm.mni.ii.phpparser.ast.Basic;\n\npublic class Main {\n    public static void main(String[] args) {\n        PHPParser.Result res = (PHPParser.Result) PHPParser.parse(\"\u003c?php $value = 5;\");\n        if (res instanceof PHPParser.Success) {\n            Basic.Script s = ((PHPParser.Success) res).script();\n            System.out.println(s);\n        } else if (res instanceof PHPParser.Failure) {\n            String msg = ((PHPParser.Failure) res).fullMsg();\n            System.out.println(msg);\n        }\n    }\n}\n```\n\n#### Scala\n```scala\nobject Main extends App {\n  import de.thm.mni.ii.phpparser.PHPParser\n\n  PHPParser.parse(\"\u003c?php $value = 5;\") match {\n    case s: PHPParser.Success =\u003e println(s.script)\n    case f: PHPParser.Failure =\u003e println(f.fullMsg)\n  }\n}\n```\n\nThe top-level __PHPParser__ parses a whole PHP-Script. The result is an instance of __PHPParser.Success__ or __PHPParser.Failure__. \n\n__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. \n\n## Project Structure\n\n```\n.\n├── ...\n├── src/main/scala/de/thm/mni/ii/phpparser\n│   ├── PHPParser.scala    # top-level parser\n│   ├── ast/               # case classes of abstract syntax tree\n│   └── parser/            # specific parsers for all different elements\n└── ...\n```\n\n## Contribute\n\nFeel free to send Pull-Requests to improve this parser. If you find a bug, please report it as an issue on github. \n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthm-mni-ii%2Fphp-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthm-mni-ii%2Fphp-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthm-mni-ii%2Fphp-parser/lists"}