2017-12-01 13:29:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-12-01 16:04:31 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2017-12-01 13:29:23 +00:00
|
|
|
"os"
|
2018-01-09 22:03:53 +00:00
|
|
|
"path/filepath"
|
2017-12-01 13:29:23 +00:00
|
|
|
|
2017-12-01 16:04:31 +00:00
|
|
|
"github.com/yookoala/realpath"
|
2018-02-06 10:39:42 +00:00
|
|
|
"github.com/z7zmey/php-parser/comment"
|
|
|
|
"github.com/z7zmey/php-parser/node"
|
2018-01-26 13:24:56 +00:00
|
|
|
"github.com/z7zmey/php-parser/php5"
|
2018-02-06 10:39:42 +00:00
|
|
|
"github.com/z7zmey/php-parser/php7"
|
|
|
|
"github.com/z7zmey/php-parser/position"
|
2018-02-04 19:35:46 +00:00
|
|
|
"github.com/z7zmey/php-parser/visitor"
|
2017-12-01 16:04:31 +00:00
|
|
|
)
|
2017-12-01 13:29:23 +00:00
|
|
|
|
|
|
|
func main() {
|
2018-02-06 10:39:42 +00:00
|
|
|
var nodes node.Node
|
|
|
|
var comments comment.Comments
|
|
|
|
var positions position.Positions
|
|
|
|
|
|
|
|
usePhp5 := flag.Bool("php5", false, "use PHP5 parser")
|
2017-12-01 16:04:31 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
for _, path := range flag.Args() {
|
|
|
|
real, err := realpath.Realpath(path)
|
|
|
|
checkErr(err)
|
|
|
|
|
2018-01-09 22:03:53 +00:00
|
|
|
err = filepath.Walk(real, func(path string, f os.FileInfo, err error) error {
|
|
|
|
if !f.IsDir() && filepath.Ext(path) == ".php" {
|
|
|
|
fmt.Printf("==> %s\n", path)
|
2017-12-18 22:55:57 +00:00
|
|
|
|
2018-01-09 22:03:53 +00:00
|
|
|
src, _ := os.Open(string(path))
|
2018-02-06 10:39:42 +00:00
|
|
|
if *usePhp5 {
|
|
|
|
nodes, comments, positions = php5.Parse(src, path)
|
|
|
|
} else {
|
|
|
|
nodes, comments, positions = php7.Parse(src, path)
|
|
|
|
}
|
2018-01-09 22:03:53 +00:00
|
|
|
|
2018-02-27 13:45:58 +00:00
|
|
|
nsResolver := visitor.NewNamespaceResolver()
|
2018-02-23 18:26:13 +00:00
|
|
|
nodes.Walk(nsResolver)
|
|
|
|
|
|
|
|
dumper := visitor.Dumper{
|
2018-03-03 20:51:22 +00:00
|
|
|
Writer: os.Stdout,
|
2018-03-01 20:31:36 +00:00
|
|
|
Indent: " | ",
|
|
|
|
Comments: comments,
|
|
|
|
Positions: positions,
|
|
|
|
NsResolver: nsResolver,
|
2018-01-12 08:04:31 +00:00
|
|
|
}
|
2018-02-23 18:26:13 +00:00
|
|
|
nodes.Walk(dumper)
|
2018-01-09 22:03:53 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
checkErr(err)
|
2017-12-01 14:04:53 +00:00
|
|
|
}
|
2017-12-01 16:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkErr(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2017-12-01 14:04:53 +00:00
|
|
|
}
|
|
|
|
}
|