{"id":13694415,"url":"https://github.com/VKCOM/php-parser","last_synced_at":"2025-05-03T01:33:05.723Z","repository":{"id":40320460,"uuid":"390373192","full_name":"VKCOM/php-parser","owner":"VKCOM","description":"PHP parser written in Go","archived":true,"fork":false,"pushed_at":"2023-09-23T02:23:02.000Z","size":12216,"stargazers_count":69,"open_issues_count":5,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-09-26T21:41:38.985Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://php-parser.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"z7zmey/php-parser","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VKCOM.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-28T14:04:58.000Z","updated_at":"2024-08-01T15:05:05.000Z","dependencies_parsed_at":"2024-06-18T21:52:54.261Z","dependency_job_id":null,"html_url":"https://github.com/VKCOM/php-parser","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VKCOM%2Fphp-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VKCOM%2Fphp-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VKCOM%2Fphp-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VKCOM%2Fphp-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VKCOM","download_url":"https://codeload.github.com/VKCOM/php-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224346587,"owners_count":17296245,"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":[],"created_at":"2024-08-02T17:01:31.448Z","updated_at":"2024-11-12T20:32:16.291Z","avatar_url":"https://github.com/VKCOM.png","language":"Go","readme":"\u003e This is a fork of the [z7zmey](https://github.com/z7zmey) [parser](https://github.com/z7zmey/php-parser) that adds PHP 8 support.\n\nPHP Parser written in Go\n========================\n\n\u003cimg src=\"./parser.jpg\" alt=\"PHP Parser written in Go\" width=\"980\"/\u003e\n\n[![GoDoc](https://godoc.org/github.com/VKCOM/php-parser?status.svg)](https://godoc.org/github.com/VKCOM/php-parser)\n[![Build Status](https://github.com/VKCOM/php-parser/workflows/Go/badge.svg)](https://github.com/VKCOM/php-parser/workflows/Go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/VKCOM/php-parser)](https://goreportcard.com/report/github.com/VKCOM/php-parser)\n\nThis project uses [goyacc](https://godoc.org/golang.org/x/tools/cmd/goyacc) and [ragel](https://www.colm.net/open-source/ragel/) tools to create PHP parser. It parses source code into [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree). It can be used to write static analysis, refactoring, metrics, code style formatting tools.\n\nFeatures\n---------\n\n- Fully support PHP 5, PHP 7 and PHP 8.0-8.2 syntax\n- Abstract syntax tree (AST) representation\n- Traversing AST\n- Resolving namespace names\n- Parsing syntax-invalid PHP files\n- Saving and printing free-floating comments and whitespaces\n\nWho Uses\n--------\n\n- [VKCOM/noverify](https://github.com/VKCOM/noverify) — pretty fast linter for PHP\n- [VKCOM/nocolor](https://github.com/VKCOM/nocolor) — architecture validation tool for PHP based on the [*concept of colored functions*](https://github.com/VKCOM/nocolor/blob/master/docs/introducing_colors.md)\n- [quasilyte/phpgrep](https://github.com/quasilyte/phpgrep) — tool for syntax-aware PHP code search\n\nUsage example\n-------\n\n```Golang\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/VKCOM/php-parser/pkg/conf\"\n\t\"github.com/VKCOM/php-parser/pkg/errors\"\n\t\"github.com/VKCOM/php-parser/pkg/parser\"\n\t\"github.com/VKCOM/php-parser/pkg/version\"\n\t\"github.com/VKCOM/php-parser/pkg/visitor/dumper\"\n)\n\nfunc main() {\n\tsrc := []byte(`\u003c?php echo \"Hello world\";`)\n\n\t// Error handler\n\n\tvar parserErrors []*errors.Error\n\terrorHandler := func(e *errors.Error) {\n\t\tparserErrors = append(parserErrors, e)\n\t}\n\n\t// Parse\n\n\trootNode, err := parser.Parse(src, conf.Config{\n\t\tVersion:          \u0026version.Version{Major: 8, Minor: 0},\n\t\tErrorHandlerFunc: errorHandler,\n\t})\n\n\tif err != nil {\n\t\tlog.Fatal(\"Error:\" + err.Error())\n\t}\n\t\n\tif len(parserErrors) \u003e 0 {\n\t\tfor _, e := range parserErrors {\n\t\t\tlog.Println(e.String())\n\t\t}\n\t\tos.Exit(1)\n\t}\n\n\t// Dump\n\n\tgoDumper := dumper.NewDumper(os.Stdout).\n\t\tWithTokens().\n\t\tWithPositions()\n\n\trootNode.Accept(goDumper)\n}\n```\n\nInstall\n-------\n\n```\ngo get github.com/VKCOM/php-parser/cmd/php-parser\n```\n\nCLI\n---\n\n```\nphp-parser [flags] \u003cpath\u003e ...\n```\n\n| flag       | type     | description                         |\n|------------|----------|-------------------------------------|\n| `-p`       | `bool`   | Print file paths                    |\n| `-e`       | `bool`   | Print errors                        |\n| `-d`       | `bool`   | Dump AST in Golang format           |\n| `-r`       | `bool`   | Resolve names                       |\n| `--pb`     | `bool`   | Print AST back into the parsed file |\n| `--time`   | `bool`   | Print execution time                |\n| `--prof`   | `string` | Start profiler: `[cpu, mem, trace]` |\n| `--phpver` | `string` | PHP version (default: 8.0)          |\n\nNamespace resolver\n------------------\n\nNamespace resolver is a visitor that resolves nodes fully qualified name and saves into `map[node.Node]string` structure\n\n- For `Class`, `Interface`, `Trait`, `Function`, `Constant` nodes it saves name with current namespace.\n- For `Name`, `Relative`, `FullyQualified` nodes it resolves `use` aliases and saves a fully qualified name.\n","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["解释器","Interpreter"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVKCOM%2Fphp-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVKCOM%2Fphp-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVKCOM%2Fphp-parser/lists"}