update readme

This commit is contained in:
Vadym Slizov 2020-03-09 12:44:10 +02:00
parent 18844b4595
commit 3383679bc8
2 changed files with 8 additions and 11 deletions

View File

@ -46,6 +46,7 @@ php-parser [flags] <path> ...
| flag | type | description | | flag | type | description |
|-------|------|----------------------------------------------| |-------|------|----------------------------------------------|
| -p | bool | print filepath |
| -d |string| dump format: [custom, go, json, pretty-json] | | -d |string| dump format: [custom, go, json, pretty-json] |
| -r | bool | resolve names | | -r | bool | resolve names |
| -ff | bool | parse and show free floating strings | | -ff | bool | parse and show free floating strings |
@ -71,7 +72,7 @@ import (
func main() { func main() {
src := []byte(`<? echo "Hello world";`) src := []byte(`<? echo "Hello world";`)
parser := php7.NewParser(src) parser := php7.NewParser(src, "7.4")
parser.Parse() parser.Parse()
for _, e := range parser.GetErrors() { for _, e := range parser.GetErrors() {

16
main.go
View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"bufio"
"bytes" "bytes"
"flag" "flag"
"fmt" "fmt"
@ -26,6 +25,7 @@ var profiler string
var withFreeFloating *bool var withFreeFloating *bool
var showResolvedNs *bool var showResolvedNs *bool
var printBack *bool var printBack *bool
var printPath *bool
type file struct { type file struct {
path string path string
@ -41,6 +41,7 @@ func main() {
withFreeFloating = flag.Bool("ff", false, "parse and show free floating strings") withFreeFloating = flag.Bool("ff", false, "parse and show free floating strings")
showResolvedNs = flag.Bool("r", false, "resolve names") showResolvedNs = flag.Bool("r", false, "resolve names")
printBack = flag.Bool("pb", false, "print AST back into the parsed file") printBack = flag.Bool("pb", false, "print AST back into the parsed file")
printPath = flag.Bool("p", false, "print filepath")
flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]") flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]")
flag.StringVar(&profiler, "prof", "", "start profiler: [cpu, mem, trace]") flag.StringVar(&profiler, "prof", "", "start profiler: [cpu, mem, trace]")
flag.StringVar(&phpVersion, "phpver", "7.4", "php version") flag.StringVar(&phpVersion, "phpver", "7.4", "php version")
@ -126,25 +127,20 @@ func parserWorker(fileCh <-chan *file, r chan<- result) {
func printerWorker(r <-chan result) { func printerWorker(r <-chan result) {
var counter int var counter int
w := bufio.NewWriter(os.Stdout)
for { for {
res, ok := <-r res, ok := <-r
if !ok { if !ok {
w.Flush()
return return
} }
counter++ counter++
fmt.Fprintf(w, "==> [%d] %s\n", counter, res.path) if *printPath {
fmt.Fprintf(os.Stdout, "==> [%d] %s\n", counter, res.path)
}
for _, e := range res.parser.GetErrors() { for _, e := range res.parser.GetErrors() {
// if !strings.Contains(e.Msg, "WARNING") { fmt.Fprintf(os.Stdout, "==> %s\n", e)
// fmt.Print("\n\n\n" + parserWorker.GetPath() + "\n ")
// panic(e.Msg)
// }
fmt.Fprintln(w, e)
} }
if *printBack { if *printBack {