From 90f451293dc66544ea542fe517c3a7221881b356 Mon Sep 17 00:00:00 2001 From: z7zmey Date: Sat, 24 Feb 2018 00:17:51 +0200 Subject: [PATCH] update Makefile --- Makefile | 8 +++++--- visitor/NsResolver.go | 13 +++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 001ec9f..5ea444f 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,14 @@ PHPFILE=example.php -all: compile run +all: compile fmt build run + +fmt: + find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' + build: - find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' + go build -run: build +run: ./php-parser $(PHPFILE) test: diff --git a/visitor/NsResolver.go b/visitor/NsResolver.go index 64ef232..0c42d9f 100644 --- a/visitor/NsResolver.go +++ b/visitor/NsResolver.go @@ -2,7 +2,6 @@ package visitor import ( - "fmt" "strings" "github.com/z7zmey/php-parser/node" @@ -60,22 +59,33 @@ func (nsr *NsResolver) EnterNode(w walker.Walkable) bool { NSParts := n.NamespaceName.(*name.Name).Parts nsr.Namespace = NewNamespace(concatNameParts(NSParts)) } + case *stmt.UseList: useType := "" if n.UseType != nil { useType = n.UseType.(*node.Identifier).Value } + for _, nn := range n.Uses { nsr.AddAlias(useType, nn, nil) } + + // no reason to iterate into depth + return false + case *stmt.GroupUse: useType := "" if n.UseType != nil { useType = n.UseType.(*node.Identifier).Value } + for _, nn := range n.UseList { nsr.AddAlias(useType, nn, n.Prefix.(*name.Name).Parts) } + + // no reason to iterate into depth + return false + } return true @@ -110,7 +120,6 @@ func (nsr *NsResolver) LeaveNode(w walker.Walkable) { switch n := w.(type) { case *stmt.Namespace: if n.Stmts != nil { - fmt.Printf("%+v \n", nsr.Namespace.Aliases) nsr.Namespace = NewNamespace("") } }