cmd: add php5 flag
This commit is contained in:
parent
ce9d676229
commit
f546db54b6
12
Makefile
12
Makefile
@ -1,16 +1,20 @@
|
|||||||
PHPFILE=example.php
|
PHPFILE=example.php
|
||||||
|
|
||||||
all: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go
|
all: compile run
|
||||||
rm -f y.output
|
|
||||||
gofmt -l -s -w *.go
|
build:
|
||||||
|
gofmt -l -s -w **/*.go
|
||||||
go build
|
go build
|
||||||
|
|
||||||
run: all
|
run: build
|
||||||
./php-parser $(PHPFILE)
|
./php-parser $(PHPFILE)
|
||||||
|
|
||||||
test: all
|
test: all
|
||||||
go test ./... --cover
|
go test ./... --cover
|
||||||
|
|
||||||
|
compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go
|
||||||
|
rm -f y.output
|
||||||
|
|
||||||
./scanner/scanner.go: ./scanner/scanner.l
|
./scanner/scanner.go: ./scanner/scanner.l
|
||||||
golex -o $@ $<
|
golex -o $@ $<
|
||||||
|
|
||||||
|
15
main.go
15
main.go
@ -8,11 +8,20 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/yookoala/realpath"
|
"github.com/yookoala/realpath"
|
||||||
|
"github.com/z7zmey/php-parser/comment"
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
"github.com/z7zmey/php-parser/php5"
|
"github.com/z7zmey/php-parser/php5"
|
||||||
|
"github.com/z7zmey/php-parser/php7"
|
||||||
|
"github.com/z7zmey/php-parser/position"
|
||||||
"github.com/z7zmey/php-parser/visitor"
|
"github.com/z7zmey/php-parser/visitor"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var nodes node.Node
|
||||||
|
var comments comment.Comments
|
||||||
|
var positions position.Positions
|
||||||
|
|
||||||
|
usePhp5 := flag.Bool("php5", false, "use PHP5 parser")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
for _, path := range flag.Args() {
|
for _, path := range flag.Args() {
|
||||||
@ -24,7 +33,11 @@ func main() {
|
|||||||
fmt.Printf("==> %s\n", path)
|
fmt.Printf("==> %s\n", path)
|
||||||
|
|
||||||
src, _ := os.Open(string(path))
|
src, _ := os.Open(string(path))
|
||||||
nodes, comments, positions := php5.Parse(src, path)
|
if *usePhp5 {
|
||||||
|
nodes, comments, positions = php5.Parse(src, path)
|
||||||
|
} else {
|
||||||
|
nodes, comments, positions = php7.Parse(src, path)
|
||||||
|
}
|
||||||
|
|
||||||
visitor := visitor.Dumper{
|
visitor := visitor.Dumper{
|
||||||
Indent: " | ",
|
Indent: " | ",
|
||||||
|
Loading…
Reference in New Issue
Block a user