The project builds an Abstract Syntax Tree (AST) from HackLang source code
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
grammar
lib
tests
vendor
README.md
_buildpath.xml
_gitignore
_project.xml
composer.json
composer.lock
phack

README.md

HackLang parser

What is this?

This project is a parser for HackLang written in PHP. It is based on Sara Golemon's project Phack. It builds an abstract Syntax Tree (AST) from HackLang source code.

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?

Hack Parser extends PHP-Parser by amending the PHP 7 parsing rules and overriding the Lexer's pre/post processor hooks.

How do I use it?

The prefered way of installation is via composer. For this, add the following to your composer.json:

"repositories": [
    {
        "type": "vcs",
        "url": "<git_repository_url>"
    }
],
"require": {
    "adel/hackparser": "*"
}

To Parse a HackLang file, use new PhpLang\Phack\PhpParser\ParserFactory)->create(PhpLang\Phack\PhpParser\ParserFactory::HACKLANG)->parse($str);. This returns an abstract syntax tree that can be used for static analysis for example. More informations in the PHP-Parser documentation.

To see the AST of a given HackLang file, you can run vendor/bin/hackParser which will invoke compileString for you and dump the tree.