Comments (2)
Hi,
Glad to see that you're interested by this project. I plan to start a new project very similar to the PHP reflection API based on this parser. I'll start it in a few weeks at https://github.com/glayzzle/php-reflection.
To reply at your questions :
- To parse code (with open tags) you have to use the parseCode function instead the parseEval :
(see https://github.com/glayzzle/php-parser/blob/master/main.js) - You seem to include directly the src/parser.js from you cli.js (line 9), you shoudrequire 'php-parser'
lib -> ./node_modules/php-parser/main.js and then use the parseCode function. - Agree with the object approach but not from the AST. I want to keep the AST memory efficient and that's why I only use nested lists. I have to start a spec but take for granted that the first place in any array is a string that define it's type. But I am agree with you that nested lists are not efficient enough to work with, that's why I need another layer/lib to interpret the AST, that's the next library php-reflection.
- & 4 - Thanks for the advice (I will use it on glayzzle which is the end product). You seem to think that this lib could be used as a standalone utility. The bin folder (and scripts) is only for the developpement stage of the lib (and the code was made in hurry just to validate the lib - they are even not deployed with npm : https://github.com/glayzzle/php-parser/blob/master/.npmignore) - so if for example you would have a cli that take a file and outputs his AST, you should create a new project for that.
So for now I need to start a documentation for all the AST structure on the wiki (after that I'll release the lib on a 1.x version - the AST API will be definitive)
Some tips to help you start with the AST :
['namespace', [...path of the namespace...], [...instructions...] ]
[ 'sys', 'require' | 'include_once' | ... , [argument]]
the argument can be a string like : [ 'string', 'baz.php' ], or an expression
To continue use a file to experiment AST results :
<?php
namespace boo\bar {
trait baz {
function run() {
return true;
}
}
trait foo {
function run() {
return true;
}
function stop() {
return true;
}
}
trait foobaz {
use foo, baz {
baz::run insteadof foo;
}
}
}
namespace foo {
require 'baz.php';
include_once 'foobar.php';
use org\apache\spring\blabla as CoolThing;
abstract class bar extends CoolThing {
use boo\bar\foo, boo\bar\baz {
boo\bar\foo::run insteadof boo\bar\baz;
}
}
}
And get the AST from the command line : ../bin/> node test.js -f ../test/proto/test3.php -v
from php-parser.
Thanks a ton for the insight @ichiriac. I really appreciate it.
from php-parser.
Related Issues (20)
- Null-safe operator followed by a property named `class` results in a syntax error HOT 1
- Modifying the AST HOT 4
- "arrowfunc" puts body into a block HOT 1
- AST type inconsistencies
- add a wiki page for all the available options/configs and what each is for ? HOT 1
- how to access property promotion in php8 ? HOT 6
- noop start and end loc is swapped
- Attribute parsing with string concatenation HOT 2
- Nested staticlookup of property called `class`
- attribute start and end loc are the same, and source is undefined
- Disjunctive Normal Form (DNF) Types is not parsed
- Unexpected syntax error when nullsafe object operator used with parentheses
- Wrong start loc when using nullsafeoperator `?->`
- `uniontype` has wrong start loc
- Heredoc fails to parse escaped newlines
- Fails to parse classes with typed constants HOT 2
- Don`t mark property as static HOT 3
- Runtime ::class const doesn't work properly
- Error in types.d.ts TypeScript definitions
- How to turn ast into PHP code HOT 5
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.