{"_id":"@bilabila/luaparse","_rev":"2-39f16a94353cce8a01d8a12c23c76781","name":"@bilabila/luaparse","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@bilabila/luaparse","version":"0.0.1","description":"A Lua parser in JavaScript","keywords":["ast","lua","parser","parsing"],"homepage":"https://oxyc.github.io/luaparse/","bugs":{"url":"https://github.com/oxyc/luaparse/issues"},"license":"MIT","author":{"name":"Oskar Schöldström","email":"public@oxy.fi","url":"http://www.oxy.fi/"},"main":"luaparse.js","bin":{"luaparse":"./bin/luaparse"},"man":["./docs/luaparse.1"],"repository":{"type":"git","url":"git+https://github.com/oxyc/luaparse.git"},"scripts":{"test":"make qa"},"devDependencies":{"benchmark":"~1.0.0","complexity-report":"~0.10.5","docco":"~0.6.3","gulp":"^4.0.0","gulp-add-src":"^1.0.0","gulp-filelog":"^0.4.1","gulp-header":"^1.2.2","gulp-jshint":"^1.9.0","gulp-rename":"^1.2.0","gulp-striphtml":"0.0.1","gulp-uglify":"^1.0.1","istanbul":"~0.3.2","marked":"~0.3.2","spec":"git://github.com/kitcambridge/spec.git#gh-pages","testem":"~1.15.0"},"gitHead":"f7b9a728381a8b890c88a7bb553b329aed6ccd3c","_id":"@bilabila/luaparse@0.0.1","_nodeVersion":"11.15.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-JQhbieKaq3HZjE/cYiG9WAXAAmiCHyo+KJAg55GOuNcslGQmCK1d7YhTFlKZDzTwkRKYg+AEdIZmRq4QiHkh7Q==","shasum":"507a80f214ba820442374f6accdbedb73267d189","tarball":"https://registry.npmjs.org/@bilabila/luaparse/-/luaparse-0.0.1.tgz","fileCount":5,"unpackedSize":88909,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc8VCpCRA9TVsSAnZWagAAiOsP/0bt87dnfrHcOurxCd/U\nGivOceInGz7hKOPXZ/WS4mhy9daRazF9hRN0gpU2Xf3g4SSCGK68da3hAnOp\n462dbDwORBlQFhVhrLJafQ2ORwRkopkyL/sUepoSOseIHewDVWnDz4+nCXjo\nr0TReAr/kXAPBu5+xmczBX4kdcbZNHZQbi7kdmjlUx+gvK/r92itiIMZp3A3\nNDmB1Qn9NaTZjQFeXxAFEyAQ41yFbDrZix8UIANm8qO35BylS9ISQrrN+a4E\nCB6MU/rYK0MYjRat+lsoUCH1uRzXTOZCxL664CApSSesfKCu3IKJyEWkFpzI\n0njoggT8vcYET6vVo87Kl0EBjoTG28qFSWZy/deje5ej+z2xUqFg6L+lfZ/9\nMjUNlQDDUNZ1L8bFdC1I8VC9G2eDXbvTwQ8HoAHATetlxlpc7LGGTg8RQNDX\nIbLNu79tM2Bu6jv3RrvZsuQR7LgbY3Id7eX5DJS3sK52ActMffW9Gv15Mzq6\nu+JaNgpp44Zu+o8jlgFH0dLCQpdgjsj0MzImYaeKMpetC32OhMbClr9vF0ab\nn7b8pJW2oDl9OjOxdPDTGAXw3syeTYT9vzcn+oWFNI8Hr0gpYz/bX7X/1jqD\nrQPFgYZp4zvqthANgnd+OkpWdQm+ymhQI4Yvt+Jj8fg38IhT+NBRJSExJ+Li\ni0uB\r\n=3A8z\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCGcxwMLv4Zho4HaeH3pwV8rkSAlXIuYW7lf+Bw1gNX+AIgfSFEpp1Rzrk95xoJ7zWuxKNbzeyxkdxaImi7AErq3iA="}]},"maintainers":[{"name":"bilabila","email":"bilabila@qq.com"}],"_npmUser":{"name":"bilabila","email":"bilabila@qq.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/luaparse_0.0.1_1559318696300_0.4983355396642417"},"_hasShrinkwrap":false},"0.0.2":{"name":"@bilabila/luaparse","version":"0.0.2","description":"A Lua parser in JavaScript","keywords":["ast","lua","parser","parsing"],"homepage":"https://oxyc.github.io/luaparse/","bugs":{"url":"https://github.com/oxyc/luaparse/issues"},"license":"MIT","author":{"name":"Oskar Schöldström","email":"public@oxy.fi","url":"http://www.oxy.fi/"},"main":"luaparse.js","bin":{"luaparse":"./bin/luaparse"},"man":["./docs/luaparse.1"],"repository":{"type":"git","url":"git+https://github.com/tkkcc/luaparse.git"},"scripts":{"test":"make qa"},"devDependencies":{"benchmark":"~1.0.0","complexity-report":"~0.10.5","docco":"~0.6.3","gulp":"^4.0.0","gulp-add-src":"^1.0.0","gulp-filelog":"^0.4.1","gulp-header":"^1.2.2","gulp-jshint":"^1.9.0","gulp-rename":"^1.2.0","gulp-striphtml":"0.0.1","gulp-uglify":"^1.0.1","istanbul":"~0.3.2","marked":"~0.3.2","spec":"git://github.com/kitcambridge/spec.git#gh-pages","testem":"~1.15.0"},"gitHead":"7e7af23b24f3c6a47b8743d379ac6eb99308eecd","_id":"@bilabila/luaparse@0.0.2","_nodeVersion":"11.15.0","_npmVersion":"6.9.0","dist":{"integrity":"sha512-R1V5LryYaQyurQM1fhSRmV7u9Ju7Ampcd6cPxRptpG/AKOBxdMM/p3+TZunyvGNYDy8i7J0+bX/01+KuP/k8qg==","shasum":"eb537fd79068caf27daa2e06d351cd33e4f2e24c","tarball":"https://registry.npmjs.org/@bilabila/luaparse/-/luaparse-0.0.2.tgz","fileCount":6,"unpackedSize":98548,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc8kd6CRA9TVsSAnZWagAA9BkP/3WUNAORvHS3GUfbfzCj\nakk3kRJ+5tlFCLF58rJMtbhR2KNfXQ0axCC/vlvsJzzSG9anLDlQjoo/7yOu\ndDHstciUK9FtcdY1dzl9YmXX70JtQlhrsAMZGHXwEEtxUkvpPTG0T7j7jv8q\nbLitVnH/nLsIZl5fVLtD5pQdqdfBRP6pictJYiWm86pW+uGwaH3jksWKwPqx\nNw35xv6BNUixEhT0D/jgXA+eP7h6JEJpezm6oMmvpaiVd/3vrcz/IBloDZNW\necjCT03OiUHJjOirJTPyqNoC74EmAfLuxWhdPQpn3TU9VXHv1PfLjC/3XXmC\nYhQt1gRjYgxs5vWy0RbWSGtZr98KCHG2es4zaq5Fjh1u6/WjscXxDEpxFuDy\n60gjI75zW044Gax3txSK/l6w/JszKEw3qCaI+picDBZyvs1N6stZBOCwvfhJ\nLTXAvR56hk4D2RZ/Jeds2S7s7dLQJ7I4ayXuuIOUldZndxrx8TJcDfgr0sDb\nch8PSPWJ4OzRVpvBVbslO5d4ykEPQj3NEyy6ymctADqtw4/xujAKLnZECrHx\nOgNo7tm2JTaS2+Gd/eOyOlVxzDhc6CxLUrIeWaB413vGEAJSNs+u20Eh8glK\ngRwDksrS0DdWVLf1j5tOh9GgmpkRc3Pi+LZ0tum5eM2T5d5wOV/0diswrw/V\nssfd\r\n=z1RO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCrkwZiIQBO2XeAw6gLkQBX8vN7vrd4SWQEWMLnroijzAIhAJJAjJ81uexgLaoQi0+HDQ/AmCRl0LhIFOsUX2OodvUd"}]},"maintainers":[{"name":"bilabila","email":"bilabila@qq.com"}],"_npmUser":{"name":"bilabila","email":"bilabila@qq.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/luaparse_0.0.2_1559381881519_0.3910554704927913"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-31T16:04:56.273Z","0.0.1":"2019-05-31T16:04:56.495Z","modified":"2022-04-04T18:47:57.033Z","0.0.2":"2019-06-01T09:38:01.705Z"},"maintainers":[{"name":"bilabila","email":"bilabila@qq.com"}],"description":"A Lua parser in JavaScript","homepage":"https://oxyc.github.io/luaparse/","keywords":["ast","lua","parser","parsing"],"repository":{"type":"git","url":"git+https://github.com/tkkcc/luaparse.git"},"author":{"name":"Oskar Schöldström","email":"public@oxy.fi","url":"http://www.oxy.fi/"},"bugs":{"url":"https://github.com/oxyc/luaparse/issues"},"license":"MIT","readme":"# luaparse [![Build Status](https://travis-ci.org/oxyc/luaparse.svg)](https://travis-ci.org/oxyc/luaparse)\n\nA Lua parser written in JavaScript, for my bachelor's thesis at Arcada.\n\n## Installation\n\nInstall through `bower install luaparse` or `npm install luaparse`.\n\n## Usage\n\nCommonJS\n\n```js\nvar parser = require('luaparse');\nvar ast = parser.parse('i = 0');\nconsole.log(JSON.stringify(ast));\n```\n\nAMD\n\n```js\nrequire(['luaparse'], function(parser) {\n  var ast = parser.parse('i = 0');\n  console.log(JSON.stringify(ast));\n});\n```\n\nBrowser\n\n```html\n<script src=\"luaparse.js\"></script>\n<script>\nvar ast = luaparse.parse('i = 0');\nconsole.log(JSON.stringify(ast));\n</script>\n```\n\n## Parser Interface\n\nBasic usage:\n\n```js\nluaparse.parse(code, options);\n```\n\nThe output of the parser is an Abstract Syntax Tree (AST) formatted in JSON.\n\nThe available options are:\n\n- `wait: false` Explicitly tell the parser when the input ends.\n- `comments: true` Store comments as an array in the chunk object.\n- `scope: false` Track identifier scopes.\n- `locations: false` Store location information on each syntax node.\n- `ranges: false` Store the start and end character locations on each syntax\n  node.\n- `onCreateNode: null` A callback which will be invoked when a syntax node\n  has been completed. The node which has been created will be passed as the\n  only parameter.\n- `onCreateScope: null` A callback which will be invoked when a new scope is\n  created.\n- `onDestroyScope: null` A callback which will be invoked when the current\n  scope is destroyed.\n- `onLocalDeclaration: null` A callback which will be invoked when a local\n  variable is declared. The identifier will be passed as the only parameter.\n- `luaVersion: '5.1'` The version of Lua the parser will target; supported\n  values are `'5.1'`, `'5.2'`, `'5.3'` and `'LuaJIT'`.\n- `extendedIdentifiers: false` Whether to allow code points ≥ U+0080 in\n  identifiers, like LuaJIT does. See 'Note on character encodings' below\n  if you wish to use this option. **Note:** setting `luaVersion: 'LuaJIT'`\n  currently does *not* enable this option; this may change in the future.\n\nThe default options are also exposed through `luaparse.defaultOptions` where\nthey can be overriden globally.\n\nThere is a second interface which might be preferable when using the `wait`\noption.\n\n```js\nvar parser = luaparse.parse({ wait: true });\nparser.write('foo = \"');\nparser.write('bar');\nvar ast = parser.end('\"');\n```\n\nThis would be identical to:\n\n```js\nvar ast = luaparse.parse('foo = \"bar\"');\n```\n\n### AST format\n\nIf the following code is executed:\n\n```js\nluaparse.parse('foo = \"bar\"');\n```\n\nthen the returned value will be:\n\n```js\n{\n  \"type\": \"Chunk\",\n  \"body\": [\n    {\n      \"type\": \"AssignmentStatement\",\n      \"variables\": [\n        {\n          \"type\": \"Identifier\",\n          \"name\": \"foo\"\n        }\n      ],\n      \"init\": [\n        {\n          \"type\": \"StringLiteral\",\n          \"value\": \"bar\",\n          \"raw\": \"\\\"bar\\\"\"\n        }\n      ]\n    }\n  ],\n  \"comments\": []\n}\n```\n\n#### Note on character encodings\n\nUnlike strings in JavaScript, Lua strings are not Unicode strings, but\nbytestrings (sequences of 8-bit values); likewise, implementations of Lua\nparse the source code as a sequence of octets. However, the input to this\nparser is a JavaScript string, i.e. a sequence of 16-bit code units (not\nnecessarily well-formed UTF-16). This poses a problem of how those code\nunits should be interpreted, particularly if they are outside the Basic\nLatin block ('ASCII').\n\nCurrently, this parser handles Unicode input by encoding it in [WTF-8][wtf8],\nand reinterpreting the resulting code units as Unicode code points. This\napplies to string literals and (if `extendedIdentifiers` is enabled) to\nidentifiers as well. Lua byte escapes inside string literals are interpreted\ndirectly as code points, while Lua 5.3 `\\u{}` escapes are similarly decoded\nas UTF-8 code units reinterpreted as code points. It is as if the parser input\nwas being interpreted as ISO-8859-1, while actually being encoded in UTF-8.\n\nThis ensures that no otherwise-valid input will be rejected due to encoding\nerrors. Assuming the input was originally encoded in UTF-8 (which includes\nthe case of only containing ASCII characters), it also preserves the following\nproperties:\n\n- String literal nodes representing the same string value in Lua (and\n  identifier nodes, if `extendedIdentifiers` is enabled) will have the same\n  interpretation in the AST: e.g. the Lua literals `'💩'`, `'\\u{1f4a9}'` and\n  `'\\240\\159\\146\\169'` will all have `\"\\u00f0\\u009f\\u0092\\u00a9\"` in their\n  `.value` property, and likewise `local 💩` will have the same string in\n  its `.name` property.\n- The `.length` property of decoded string values in the AST is equal to\n  the value that the `#` operator would return in Lua.\n\nMaintaining those properties makes the logic of static analysers and code\ntransformation tools simpler. However, it poses a problem when displaying\nstrings to the user and serialising AST back into a string; to recover the\noriginal bytestrings, values transformed in this way will have to be encoded\nin ISO-8859-1.\n\nOther solutions to this problem may be considered in the future. Some of\nthem have been listed below, with their drawbacks:\n\n- A mode that instead treats the input as if it were decoded according\n  to ISO-8859-1 (or [the `x-user-defined` encoding][x-user-defined])\n  and rejects code points that cannot appear in that encoding; may be\n  useful for source code in encodings other than UTF-8\n  - Still tricky to get semantics correctly\n- Using an `ArrayBuffer` or `Uint8Array` for source code and/or string\n  literals\n  - May fail to be portable to older JavaScript engines\n  - Cannot be (directly) serialised as JSON\n  - Values of those types are fixed-length, which makes manipulation\n    cumbersome; they cannot be incrementally built by appending.\n  - They cannot be used as keys in objects; one has to use\n    `Map` and `WeakMap` instead\n- Using a plain `Array` of numbers in the range [0, 256)\n  - Memory-inefficient\n  - May bloat the JSON serialisation considerably\n  - Cannot be used as keys in objects either\n- Storing string literal values as ordinary `String` values, and requiring that\n  escape sequences in literals constitute well-formed UTF-8; an exception\n  is thrown if they do not\n  - UTF-8 chauvinism; imposes semantics that may be unwanted\n  - Reduced compatibility with other Lua implementations\n- Like above, but instead of throwing an exception, ill-formed escapes are\n  transformed to unpaired surrogates, just like Python's `surrogateescape`\n  encoding error handler\n  - Destroys the property that `(\"\\xc4\" .. \"\\x99\") == \"\\xc4\\x99\"`\n  - If the AST is encoded in JSON, some JSON libraries may refuse to parse it\n\n### Custom AST\n\nThe default AST structure is somewhat inspired by the Mozilla Parser API but\ncan easily be overriden to customize the structure or to inject custom logic.\n\n`luaparse.ast` is an object containing all functions used to create the AST, if\nyou for example wanted to trigger an event on node creations you could use the\nfollowing:\n\n```js\nvar luaparse = require('luaparse'),\n    events = new (require('events').EventEmitter);\n\nObject.keys(luaparse.ast).forEach(function(type) {\n  var original = luaparse.ast[type];\n  luaparse.ast[type] = function() {\n    var node = original.apply(null, arguments);\n    events.emit(node.type, node);\n    return node;\n  };\n});\nevents.on('Identifier', function(node) { console.log(node); });\nluaparse.parse('i = \"foo\"');\n```\n\n_this is only an example to illustrate what is possible and this particular\nexample might not suit your needs as the end location of the node has not been\ndetermined yet. If you desire events you should use the `onCreateNode` callback\ninstead)._\n\n\n### Lexer\n\nThe lexer used by luaparse can be used independently of the recursive descent\nparser. The lex function is exposed as `luaparse.lex()` and it will return the\nnext token up until `EOF` is reached.\n\nEach token consists of:\n\n- `type` expressed as an enum flag which can be matched with `luaparse.tokenTypes`.\n- `value`\n- `line`, `lineStart`\n- `range` can be used to slice out raw values, eg. `foo = \"bar\"` will return a\n`StringLiteral` token with the value `bar`. Slicing out the range on the other\nhand will return `\"bar\"`.\n\n```js\nvar parser = luaparse.parse('foo = \"bar\"', { wait: true });\nparser.lex(); // { type: 8, value: \"foo\", line: 1, lineStart: 0, range: [0, 3] }\nparser.lex(); // { type: 32, value: \"=\", line: 1, lineStart: 0, range: [4, 5]}\nparser.lex(); // { type: 2, value: \"bar\", line: 1, lineStart: 0, range: [6, 11] }\nparser.lex(); // { type: 1, value: \"<eof>\", line: 1, lineStart: 0, range: [11 11] }\nparser.lex(); // { type: 1, value: \"<eof>\", line: 1, lineStart: 0, range: [11 11] }\n```\n\n## Examples\n\nHave a look in the [examples directory](https://github.com/oxyc/luaparse/tree/master/examples)\nof the repository for some code examples or check them out [live](https://oxyc.github.io/luaparse/examples.html).\n\n## luaparse(1)\n\nThe `luaparse` executable can be used in your shell by installing `luaparse` globally using npm:\n\n```bash\n$ npm install -g luaparse\n$ luaparse --help\n\nUsage: luaparse [option]... [file|code]...\n\nOptions:\n  -c|--code [code]   parse code snippet\n  -f|--file [file]   parse from file\n  -b|--beautify      output an indenteted AST\n  --[no]-comments    store comments. defaults to true\n  --[no]-scope       store variable scope. defaults to false\n  --[no]-locations   store location data on syntax nodes. defaults to false\n  --[no]-ranges      store start and end character locations. defaults to false\n  -q|--quiet         suppress output\n  -h|--help\n  -v|--version\n  --verbose\n\nExamples:\n  luaparse --no-comments -c \"locale foo = \\\"bar\\\"\"\n  luaparse foo.lua bar.lua\n```\n\nExample usage\n\n```bash\n$ luaparse \"i = 0\"\n\n{\"type\":\"Chunk\",\"body\":[{\"type\":\"AssignmentStatement\",\"variables\":[{\"type\":\"Identifier\",\"name\":\"i\"}],\"init\":[{\"type\":\"NumericLiteral\",\"value\":0,\"raw\":\"0\"}]}],\"comments\":[]}\n```\n\n## Support\n\nHas been tested in at least IE6+, Firefox 3+, Safari 4+, Chrome 10+, Opera 10+,\nNode 0.4.0+, RingoJS 0.8-0.9, Narwhal 0.3.2, Rhino 1.7R4-1.7R5, Nashorn 1.8.0.\n\n## Quality Assurance\n\n_TL;DR simply run `make qa`. This will run all quality assurance scripts but\nassumes you have it set up correctly._\n\nBegin by cloning the repository and installing the development dependencies\nwith `npm install`. To test AMD loading for browsers you should run `bower\ninstall` which will download RequireJS.\n\nThe luaparse test suite uses [testem](https://github.com/airportyh/testem) as a\ntest runner, and because of this it's very easy to run the tests using\ndifferent javascript engines or even on locally installed browsers. Currently\nthe default runner uses [PhantomJS](http://phantomjs.org/) and node so when\nusing `make test` or `npm test` you should have PhantomJS installed.\n\n### Test runners\n\n- `make test` uses PhantomJS and node.\n- `make testem-engines` uses PhantomJS, node, narwhal, ringo, rhino and rhino\n1.7R5. This requires that you have the engines installed.\n- `make test-node` uses a custom command line reporter to make the output\neasier on the eyes while practicing TDD.\n- By installing `testem` globally you can also run the tests in a locally\ninstalled browser.\n\n### Other quality assurance measures\n\n- You can check the function complexity using [complexity-report](https://github.com/philbooth/complexityReport.js)\nusing `make complexity-analysis`\n- Running `make coverage` will generate the [coverage report](https://oxyc.github.io/luaparse/coverage.html).\nTo simply check that all code has coverage you can run `make coverage-analysis`.\n- `make lint`, `make benchmark`, `make profile`.\n\n### Documentation\n\nBy running `make docs` all [documentation](https://oxyc.github.io/luaparse/)\nwill be generated.\n\n## Projects using/extending luaparse\n\n- [luamin](http://mths.be/luamin), a Lua minifier written by Mathias Bynens.\n- [Ace](https://github.com/ajaxorg/ace), an online code editor.\n\n## Acknowledgements\n\n* Initial tests are scaffolded from [yueliang][yueliang] and then manually checked for error.\n* Much of the code is based on [LuaMinify][luaminify], the [Lua][lua] source and [Esprima][esprima]. All awesome projects.\n\n## License\n\nMIT\n\n[luaminify]: https://github.com/stravant/LuaMinify\n[yueliang]: http://yueliang.luaforge.net/\n[lua]: https://www.lua.org\n[esprima]: http://esprima.org\n[wtf8]: https://simonsapin.github.io/wtf-8/\n[x-user-defined]: https://encoding.spec.whatwg.org/#x-user-defined\n","readmeFilename":"README.md"}