Skip to content

Latest commit

 

History

History
94 lines (79 loc) · 1.99 KB

README.md

File metadata and controls

94 lines (79 loc) · 1.99 KB

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.