Skip to content

glayzzle/hack-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hack-parser

JS Hack/HHVMParser - extract AST and tokens

Coverage Status Build Status


Install

npm install hack-parser --save

Usage

import parser from 'hack-parser';
console.log(
  parser.parseCode(`<?hh
      <<__Memoize>>
      function foo(inout vec<string> $bar): {
      }
  `)
);

This will output :

Program {
  "children": Array [
    _Function {
      "arguments": Array [
        Parameter {
          "byref": false,
          "inout": true,
          "kind": "parameter",
          "modifiers": null,
          "name": "bar",
          "nullable": false,
          "type": Identifier {
            "arguments": Array [
              Identifier {
                "kind": "identifier",
                "name": "string",
                "resolution": "uqn",
              },
            ],
            "kind": "identifier",
            "name": "vec",
            "resolution": "rn",
          },
          "value": null,
          "variadic": false,
        },
      ],
      "attributes": Array [
        Attribute_Spec {
          "args": null,
          "kind": "attribute_spec",
          "name": "__Memoize",
        },
      ],
      "body": Block {
        "children": Array [],
        "kind": "block",
      },
      "byref": false,
      "kind": "function",
      "name": "foo",
      "nullable": false,
      "type": null,
    },
  ],
  "errors": Array [],
  "kind": "program",
}

The library is based on php-parser

Roadmap for first release

  • Implement all tokens (introduced 43 new tokens)
  • Define new AST nodes
  • Implement the new grammar

Disclaimer : This is a work in progress

Misc

This library is released under BSD-3 license clause.

About

JS Hack/HHVMParser - extract AST and tokens

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published