[#120] update readme
This commit is contained in:
parent
d9bd1df2a2
commit
cb29615397
53
README.md
53
README.md
@ -37,30 +37,44 @@ Usage example
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/php7"
|
"github.com/z7zmey/php-parser/pkg/cfg"
|
||||||
"github.com/z7zmey/php-parser/visitor"
|
"github.com/z7zmey/php-parser/pkg/errors"
|
||||||
|
"github.com/z7zmey/php-parser/pkg/parser"
|
||||||
|
"github.com/z7zmey/php-parser/pkg/version"
|
||||||
|
"github.com/z7zmey/php-parser/pkg/visitor/dumper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
src := []byte(`<? echo "Hello world";`)
|
src := []byte(`<? echo "Hello world";`)
|
||||||
|
|
||||||
parser := php7.NewParser(src, "7.4")
|
// Error handler
|
||||||
parser.Parse()
|
|
||||||
|
|
||||||
for _, e := range parser.GetErrors() {
|
var parserErrors []*errors.Error
|
||||||
fmt.Println(e)
|
errorHandler := func(e *errors.Error) {
|
||||||
|
parserErrors = append(parserErrors, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor := visitor.Dumper{
|
// Parse
|
||||||
Writer: os.Stdout,
|
|
||||||
Indent: "",
|
rootNode, err := parser.Parse(src, cfg.Config{
|
||||||
|
Version: &version.Version{Major: 5, Minor: 6},
|
||||||
|
ErrorHandlerFunc: errorHandler,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Error:" + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
rootNode := parser.GetRootNode()
|
// Dump
|
||||||
rootNode.Walk(&visitor)
|
|
||||||
|
goDumper := dumper.NewDumper(os.Stdout).
|
||||||
|
WithTokens().
|
||||||
|
WithPositions()
|
||||||
|
|
||||||
|
rootNode.Accept(goDumper)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -68,14 +82,13 @@ Roadmap
|
|||||||
-------
|
-------
|
||||||
|
|
||||||
- Control Flow Graph (CFG)
|
- Control Flow Graph (CFG)
|
||||||
- PhpDocComment parser
|
- PHP8
|
||||||
- Stabilize api
|
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
|
|
||||||
```
|
```
|
||||||
go get github.com/z7zmey/php-parser
|
go get github.com/z7zmey/php-parser/cmd/php-parser
|
||||||
```
|
```
|
||||||
|
|
||||||
CLI
|
CLI
|
||||||
@ -86,15 +99,13 @@ php-parser [flags] <path> ...
|
|||||||
```
|
```
|
||||||
|
|
||||||
| flag | type | description |
|
| flag | type | description |
|
||||||
|-------|------|----------------------------------------------|
|
| ------- | ------ | --------------------------------- |
|
||||||
| -p | bool | print filepath |
|
| -p | bool | print filepath |
|
||||||
| -d |string| dump format: [custom, go, json, pretty-json] |
|
| -e | bool | print errors |
|
||||||
|
| -d | bool | dump in golang format |
|
||||||
| -r | bool | resolve names |
|
| -r | bool | resolve names |
|
||||||
| -ff | bool | parse and show free floating strings |
|
|
||||||
| -prof | string | start profiler: [cpu, mem, trace] |
|
| -prof | string | start profiler: [cpu, mem, trace] |
|
||||||
| -php5 | bool | parse as PHP5 |
|
| -phpver | string | php version (default: 7.4) |
|
||||||
|
|
||||||
Dump AST to stdout.
|
|
||||||
|
|
||||||
Namespace resolver
|
Namespace resolver
|
||||||
------------------
|
------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user