Coder Social home page Coder Social logo

phack's Introduction

Phack: HackLang to PHP Transpiler

This project is EXTREMELY EXPERIMENTAL and not ready for prime-time.

Only a few HackLang features are supported at this time, and they aren't fully tested.

What is this?

This project is an attempt to make HackLang code run "out of the box" on a regular PHP runtime without the need for a custom extension (it's all PHP code!). By supporting all of HackLang's rich typing system, we'll be able to make use of the static typechecker to perform robust analysis while still executing it on the stable and trusted PHP runtime.

Any attempt to use HackLang files which have not passed hh_client is a terrible mistake, and you should feel bad.

How does it work?

Phack extends PHP-Parser by amending the PHP 7 parsing rules and overriding the Lexer's pre/post processor hooks. This produces a usable AST, which can then be "PrettyPrinted" into normal PHP. The following table shows our roadmap:

Feature State Notes
Short Lambdas Alpha Needs more tests
Generics Alpha Partial type erasure for PHP compat (base type preserved)
XHP TBD XHP-1.x support available through https://www.github.com/phplang/xhp for now, XHP-2.x coming with this library
Enums Alpha Need to actually implement \InvariantException for full HackLang compat...
Pipe Op Alpha Limited to one use of lhs in rhs (unlike HackLang)
Type Aliasing TBD
Constructor Parameter Promotion Alpha
Prop/Const Typing Alpha Props: Yes, Consts: No
Callable typing Alpha
Soft/Nullable typing Alpha Full erasure on soft/nullables. Need logging for soft, and need psuedo statements for nullable checking (or PHP 7.1 nullable type support)
User Attributes Alpha UA erasure, need to preserve somewhere for reflection.
Shapes TBD
Collections TBD Static initialization is... complicated...
Async Unlikely PHP's Engine just doesn't support this concept well
Trailing Commas Alpha Allow trailing comma in arg/param lists

How do I use it?

To include a HackLang file manually, use \PhpLang\Phack\includeFile() as you would use include, similarly you can use \PhpLang\Phack\evalString as you would eval.

To have composer handle HackLang files transparently, you can try out the EXPERIMENTAL replacement ClassLoader by invoking, at the top level of your entrypoint: \PhpLang\Phack\ClassLoader::hijack();. After this point, any class autoloaded via composer will be preprocessed from HackLang into runable PHP.

To see how HackLang files transpile to PHP, you can run vendor/bin/phack which will invoke PhpLang\Phack\transpileString for you and provide the output.

phack's People

Contributors

sgolemon avatar fredemmott avatar

Watchers

Wall'e avatar  avatar

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.