JS Hack/HHVMParser - extract AST and tokens
npm install hack-parser --save
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
- Implement all tokens (introduced 43 new tokens)
- Define new AST nodes
- Implement the new grammar
Disclaimer : This is a work in progress
This library is released under BSD-3 license clause.