Comments (4)
I modified the namespace resolver with the following patch:
diff --git a/visitor/namespace_resolver.go b/visitor/namespace_resolver.go
index dc7f78f..31e8400 100644
--- a/visitor/namespace_resolver.go
+++ b/visitor/namespace_resolver.go
@@ -289,7 +289,7 @@ func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string,
if aliasType == "const" && len(n.Parts) == 1 {
part := strings.ToLower(n.Parts[0].(*name.NamePart).Value)
if part == "true" || part == "false" || part == "null" {
- return part, nil
+ return "", errors.New("ignore")
}
}
@@ -316,7 +316,7 @@ func (ns *Namespace) ResolveName(nameNode node.Node, aliasType string) (string,
case "iterable":
fallthrough
case "object":
- return part, nil
+ return "", errors.New("ignore")
}
}
And now it outputs correctly
Checking ./test.php
Found *name.Name: App\Domain\Repository\CartRepository
Found *name.Name: SimpleBus\Message\Recorder\RecordsMessages
Found *name.Name: App\Domain\Command\ChangeCurrencyCommand
Found *name.Name: App\Domain\Event\CurrencyChangedEvent
Found *stmt.Class: App\Domain\Handler\Cart\ChangeCurrencyHandler
from php-parser.
The main idea is that all *name.Name
must have an appropriate resolved name. It allows working with them in a similar way. So when we traverse AST there is no need to check is it a function name or is it a name of a reserved constant.
<?
namespace foo;
function true() {
return true;
}
from php-parser.
But since they all are *name.Name
there is no way to tell if it's a FQCN or something else?
from php-parser.
There are few ways to resolve only fully qualified class names
First(simple) - write the same visitor that resolves only FQCN.
It must be implemented in the client code. In this way, you can apply your logic how to process nodes.
Second - add in the all nodes link to their parent node so you will able filter FQN by their parent nodes.
It most flexible approach but It would create an additional load at the parsing level.
from php-parser.
Related Issues (20)
- [dev] syntax error: unexpected T_STRING at line 5 HOT 2
- Question: nikic / PHP-Parser AST compatibility HOT 3
- Wrong line number for multiline strings with variables
- malformed json HOT 1
- parser.Parse hangs up HOT 1
- Json string not valid HOT 1
- NamespaceResolver does not resolve PHP 7.4 typed properties
- 大佬 非常厉害!
- Runtime exception when using "go get github.com/z7zmey/php-parser" HOT 2
- Revise usage example for version 0.8 on master.
- Prestashop sql statements / verify escaping or type cast
- invalid position for ast.ExprArrayItem HOT 1
- AST of parent class HOT 1
- Support PHP 8.0 HOT 13
- PHPDoc parser
- A panic in lexer.go: [runtime error: index out of range] HOT 1
- Some lexer errors are printed to stderr HOT 1
- No reliable way to work with parenthesis HOT 4
- panic: runtime error: index out of range && invalid memory address or nil pointer dereference HOT 1
- name.Parts problem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-parser.