Skip to content

Commit cb29615

Browse files
committed
[#120] update readme
1 parent d9bd1df commit cb29615

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

README.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,58 @@ Usage example
3737
package main
3838

3939
import (
40-
"fmt"
40+
"log"
4141
"os"
4242

43-
"github.com/z7zmey/php-parser/php7"
44-
"github.com/z7zmey/php-parser/visitor"
43+
"github.com/z7zmey/php-parser/pkg/cfg"
44+
"github.com/z7zmey/php-parser/pkg/errors"
45+
"github.com/z7zmey/php-parser/pkg/parser"
46+
"github.com/z7zmey/php-parser/pkg/version"
47+
"github.com/z7zmey/php-parser/pkg/visitor/dumper"
4548
)
4649

4750
func main() {
4851
src := []byte(`<? echo "Hello world";`)
4952

50-
parser := php7.NewParser(src, "7.4")
51-
parser.Parse()
53+
// Error handler
5254

53-
for _, e := range parser.GetErrors() {
54-
fmt.Println(e)
55+
var parserErrors []*errors.Error
56+
errorHandler := func(e *errors.Error) {
57+
parserErrors = append(parserErrors, e)
5558
}
5659

57-
visitor := visitor.Dumper{
58-
Writer: os.Stdout,
59-
Indent: "",
60+
// Parse
61+
62+
rootNode, err := parser.Parse(src, cfg.Config{
63+
Version: &version.Version{Major: 5, Minor: 6},
64+
ErrorHandlerFunc: errorHandler,
65+
})
66+
67+
if err != nil {
68+
log.Fatal("Error:" + err.Error())
6069
}
6170

62-
rootNode := parser.GetRootNode()
63-
rootNode.Walk(&visitor)
71+
// Dump
72+
73+
goDumper := dumper.NewDumper(os.Stdout).
74+
WithTokens().
75+
WithPositions()
76+
77+
rootNode.Accept(goDumper)
6478
}
6579
```
6680

6781
Roadmap
6882
-------
6983

7084
- Control Flow Graph (CFG)
71-
- PhpDocComment parser
72-
- Stabilize api
85+
- PHP8
7386

7487
Install
7588
-------
7689

7790
```
78-
go get github.com/z7zmey/php-parser
91+
go get github.com/z7zmey/php-parser/cmd/php-parser
7992
```
8093

8194
CLI
@@ -85,16 +98,14 @@ CLI
8598
php-parser [flags] <path> ...
8699
```
87100

88-
| flag | type | description |
89-
|-------|------|----------------------------------------------|
90-
| -p | bool | print filepath |
91-
| -d |string| dump format: [custom, go, json, pretty-json] |
92-
| -r | bool | resolve names |
93-
| -ff | bool | parse and show free floating strings |
94-
| -prof |string| start profiler: [cpu, mem, trace] |
95-
| -php5 | bool | parse as PHP5 |
96-
97-
Dump AST to stdout.
101+
| flag | type | description |
102+
| ------- | ------ | --------------------------------- |
103+
| -p | bool | print filepath |
104+
| -e | bool | print errors |
105+
| -d | bool | dump in golang format |
106+
| -r | bool | resolve names |
107+
| -prof | string | start profiler: [cpu, mem, trace] |
108+
| -phpver | string | php version (default: 7.4) |
98109

99110
Namespace resolver
100111
------------------

0 commit comments

Comments
 (0)