Giter VIP home page Giter VIP logo

Comments (2)

ichiriac avatar ichiriac commented on August 23, 2024 1

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 :

  1. 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 shoud require 'php-parser' lib -> ./node_modules/php-parser/main.js and then use the parseCode function.
  2. 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.
  3. & 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.

mrjoelkemp avatar mrjoelkemp commented on August 23, 2024

Thanks a ton for the insight @ichiriac. I really appreciate it.

from php-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.