2018-01-02 12:41:54 +00:00
|
|
|
<!--
|
|
|
|
Title: PHP Parser
|
|
|
|
Description: A Parser for PHP written in Go.
|
|
|
|
Author: Slizov Vadim
|
2018-01-10 22:49:01 +00:00
|
|
|
Keywords: go golang php php-parser ast
|
2018-01-02 12:41:54 +00:00
|
|
|
-->
|
|
|
|
|
|
|
|
# PHP-Parser
|
2018-01-09 16:36:06 +00:00
|
|
|
|
2018-01-10 22:32:20 +00:00
|
|
|
[![Go Report Card](https://goreportcard.com/badge/github.com/z7zmey/php-parser)](https://goreportcard.com/report/github.com/z7zmey/php-parser)
|
2018-01-09 16:36:06 +00:00
|
|
|
[![Exago](https://api.exago.io:443/badge/tests/github.com/z7zmey/php-parser)](https://exago.io/project/github.com/z7zmey/php-parser)
|
2018-01-12 07:44:56 +00:00
|
|
|
[![Exago](https://api.exago.io:443/badge/cov/github.com/z7zmey/php-parser)](https://exago.io/project/github.com/z7zmey/php-parser)
|
2018-01-09 16:36:06 +00:00
|
|
|
|
2018-01-05 09:53:00 +00:00
|
|
|
A Parser for PHP written in Go inspired by [Nikic PHP Parser](https://github.com/nikic/PHP-Parser)
|
2018-01-02 12:34:26 +00:00
|
|
|
|
2018-01-09 16:29:05 +00:00
|
|
|
## Features:
|
2018-02-04 19:47:12 +00:00
|
|
|
- Fully support PHP5 and PHP7 syntax
|
2018-01-09 16:29:05 +00:00
|
|
|
- Abstract syntax tree representation
|
2018-01-09 16:36:06 +00:00
|
|
|
- Traversing AST
|
2018-01-09 16:29:05 +00:00
|
|
|
|
2018-01-12 08:04:31 +00:00
|
|
|
## Example
|
|
|
|
```Golang
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2018-02-04 19:35:46 +00:00
|
|
|
"github.com/z7zmey/php-parser/php5"
|
2018-01-12 08:04:31 +00:00
|
|
|
"github.com/z7zmey/php-parser/visitor"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2018-01-12 08:17:41 +00:00
|
|
|
src := bytes.NewBufferString(`<? echo "Hello world";`)
|
2018-02-04 19:35:46 +00:00
|
|
|
nodes, comments, positions := php5.Parse(src, "example.php")
|
2018-01-12 08:04:31 +00:00
|
|
|
|
2018-02-04 19:35:46 +00:00
|
|
|
visitor := visitor.Dumper{
|
|
|
|
Indent: "",
|
|
|
|
Comments: comments,
|
|
|
|
Positions: positions,
|
|
|
|
}
|
2018-01-17 16:58:45 +00:00
|
|
|
nodes.Walk(visitor)
|
2018-01-12 08:04:31 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-01-02 12:41:54 +00:00
|
|
|
## Roadmap
|
2018-01-02 12:34:26 +00:00
|
|
|
- [X] Lexer
|
2018-01-05 17:48:20 +00:00
|
|
|
- [x] PHP 7 syntax analyzer (completely)
|
2018-01-02 12:34:26 +00:00
|
|
|
- [x] AST nodes
|
2018-01-02 12:41:54 +00:00
|
|
|
- [x] AST visitor
|
2018-01-04 22:33:50 +00:00
|
|
|
- [x] AST dumper
|
|
|
|
- [x] node position
|
2018-01-05 15:03:59 +00:00
|
|
|
- [x] handling comments
|
2018-02-04 19:47:12 +00:00
|
|
|
- [x] PHP 5 syntax analyzer
|
2018-01-02 12:41:54 +00:00
|
|
|
- [ ] Tests
|
2018-01-09 16:29:05 +00:00
|
|
|
- [ ] Error handling
|
|
|
|
- [ ] Stabilize api
|
2018-01-02 12:41:54 +00:00
|
|
|
- [ ] Documentation
|
2018-01-05 09:53:00 +00:00
|
|
|
- [ ] Pretty printer
|
2018-02-04 19:47:12 +00:00
|
|
|
- [ ] Code flow graph
|