{"_id":"@atom/tree-sitter","_rev":"2-e57e6670779d469ed1209f6ebc11724b","name":"@atom/tree-sitter","dist-tags":{"latest":"0.15.2"},"versions":{"0.15.2":{"version":"0.15.2","name":"@atom/tree-sitter","description":"Incremental parsers for node","author":{"name":"Max Brunsfeld"},"license":"MIT","repository":{"type":"git","url":"git+ssh://git@github.com/tree-sitter/node-tree-sitter.git"},"keywords":["parser","lexer"],"main":"index.js","types":"tree-sitter.d.ts","dependencies":{"nan":"^2.13.2","prebuild-install":"^5.0.0"},"devDependencies":{"prebuild":"^7.6.0","chai":"3.5.x","mocha":"^5.2.0","superstring":"^2.3.5","tree-sitter-javascript":"git://github.com/tree-sitter/tree-sitter-javascript.git#node-fields"},"scripts":{"install":"prebuild-install || node-gyp rebuild","prebuild":"prebuild -r electron -t 1.8.0 -t 2.0.0 -t 3.0.0 -t 4.0.0 --strip && prebuild -t 8.16.0 -t 9.11.2 -t 10.12.0 --strip","prebuild:upload":"prebuild --upload-all","test":"mocha"},"gitHead":"6413d53dba5fc2542dccf93ff717487c0a3a6351","bugs":{"url":"https://github.com/tree-sitter/node-tree-sitter/issues"},"homepage":"https://github.com/tree-sitter/node-tree-sitter#readme","_id":"@atom/tree-sitter@0.15.2","_nodeVersion":"8.15.1","_npmVersion":"6.9.0","dist":{"integrity":"sha512-URSebF1mLL8FgbRDL44ZDob0+Qujxv4+8DaSYgEZqUn47yoQyPAPz2satZgJEDSfjglnk66DA1183gWUI+f/4Q==","shasum":"60bb4b8abc9b86ad8c797bda2ad3580d65f466d6","tarball":"https://registry.npmjs.org/@atom/tree-sitter/-/tree-sitter-0.15.2.tgz","fileCount":58,"unpackedSize":324659,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdAUATCRA9TVsSAnZWagAAMe4QAKGceFXapb2iwgbBTr6G\nVTWdTK7/rThuBZhsE645QgWJj10cKbm+YH+j58XdXDgDUzs2p8OwUTg6EMiI\nQ64hXflbHr7idHXgpGHk0/di3UYOVBPwql+7WLDF7482vrBkxPvI0l755uD/\nL3fZO8GZ9YaDeJl6hzc2OAVOSOd3LyWkklxxC6Vjb9N7WJUeZlGf1HPACU/D\nW8gtkvY5h7XP99Pc85DtwXEBCZ+8kC4eWAphbREZL7vP+adqhL7cXQg1heyg\nO68G9QwL2EPlaxqGxXOVxctwt4rvOWpMM0YR7GhxYQq4wLWbFSkG4JO8Xlex\nWi7/JHVDNwWNHA6HkN6dFoKTgDaB+/rlftnMveaQKK9Pg/889T6rdZAP0HhX\nrSu95Staqdq8wo33ypNsFeui1eNOZ2jcLRAnGvs17EwKY6rDBTXhPz/p1b+J\n/UGD/KfA5oem5nKE7bMGV0/tFUAH1StaYaQy2Eyq98JRDJ+Di8H+IIbzvxzq\nwHaeIwczH9Gq43hU94du1ZDgCikKG2LJwGk0rXvHVPZclcGE3iRTcR2r2Mej\nMbg4W3/OieDZdXb+HGWq9E3/fl1Z4qW6RAqP+ujvnBA3jVSoExHcsufjqd5p\nXzKRl4SWSBCb282tjFLFZkis4uQi4DbadrgeITsi9epIy1+otnURgQfgiBSR\nzqbr\r\n=BjiQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDLuhipivrGurul3W+ZUC5ayQrUJsS/8kfIgLYx3hDucAIhAJQHbRZ/2s4Y/z0TiikIqhTUcRpDj1CCJ0BsamHKJUeF"}]},"maintainers":[{"name":"daviwil","email":"daviwil@github.com"},{"name":"binarymuse","email":"michelle@michelletilley.net"},{"name":"kuychaco","email":"kuychaco@gmail.com"},{"name":"atom-team","email":"atom@github.com"},{"name":"smashwilson","email":"smashwilson@gmail.com"},{"name":"nathansobo","email":"nathan@github.com"},{"name":"maxbrunsfeld","email":"maxbrunsfeld@gmail.com"},{"name":"simurai","email":"sim@simurai.com"},{"name":"iolsen","email":"ian.olsen@gmail.com"},{"name":"as-cii","email":"as-cii@github.com"},{"name":"jasonrudolph","email":"jason@jasonrudolph.com"},{"name":"lee-dohm","email":"lee@lee-dohm.com"},{"name":"donokuda","email":"helloyesthisisdon@gmail.com"}],"_npmUser":{"name":"nathansobo","email":"nathan@github.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tree-sitter_0.15.2_1560363026527_0.4789997445361991"},"_hasShrinkwrap":false}},"time":{"created":"2019-06-12T18:10:26.413Z","0.15.2":"2019-06-12T18:10:27.032Z","modified":"2022-04-04T16:14:29.525Z"},"maintainers":[{"email":"mazen.elkashef@gmail.com","name":"kashef"},{"email":"daviwil@github.com","name":"daviwil"},{"email":"michelle@michelletilley.net","name":"binarymuse"},{"email":"kuychaco@gmail.com","name":"kuychaco"},{"email":"atom@github.com","name":"atom-team"},{"email":"smashwilson@gmail.com","name":"smashwilson"},{"email":"nathan@github.com","name":"nathansobo"},{"email":"maxbrunsfeld@gmail.com","name":"maxbrunsfeld"},{"email":"sim@simurai.com","name":"simurai"},{"email":"ian.olsen@gmail.com","name":"iolsen"},{"email":"as-cii@github.com","name":"as-cii"},{"email":"jason@jasonrudolph.com","name":"jasonrudolph"},{"email":"lee@lee-dohm.com","name":"lee-dohm"},{"email":"helloyesthisisdon@gmail.com","name":"donokuda"}],"description":"Incremental parsers for node","homepage":"https://github.com/tree-sitter/node-tree-sitter#readme","keywords":["parser","lexer"],"repository":{"type":"git","url":"git+ssh://git@github.com/tree-sitter/node-tree-sitter.git"},"author":{"name":"Max Brunsfeld"},"bugs":{"url":"https://github.com/tree-sitter/node-tree-sitter/issues"},"license":"MIT","readme":"node tree-sitter\n================\n\n[![Build Status](https://travis-ci.org/tree-sitter/node-tree-sitter.svg?branch=master)](https://travis-ci.org/tree-sitter/node-tree-sitter)\n[![Build status](https://ci.appveyor.com/api/projects/status/0pqlhnnk6i9rsakj/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/node-tree-sitter/branch/master)\n\nIncremental parsers for node\n\n### Installation\n\n```sh\nnpm install tree-sitter\n```\n\n### Usage\n\nFirst, you'll need a Tree-sitter grammar for the language you want to parse. There are many [existing grammars](https://github.com/tree-sitter) such as [tree-sitter-javascript](http://github.com/tree-sitter/tree-sitter-javascript) and [tree-sitter-go](http://github.com/tree-sitter/tree-sitter-go). You can also develop a new grammar using the [Tree-sitter CLI](https://github.com/tree-sitter/tree-sitter/tree/master/cli).\n\nOnce you've got your grammar, create a parser with that grammar.\n\n```javascript\nconst Parser = require('tree-sitter');\nconst JavaScript = require('tree-sitter-javascript');\n\nconst parser = new Parser();\nparser.setLanguage(JavaScript);\n```\n\nThen you can parse some source code,\n\n```javascript\nconst sourceCode = 'let x = 1; console.log(x);';\nconst tree = parser.parse(sourceCode);\n```\n\nand inspect the syntax tree.\n\n```javascript\nconsole.log(tree.rootNode.toString());\n\n// (program\n//   (lexical_declaration\n//     (variable_declarator (identifier) (number)))\n//   (expression_statement\n//     (call_expression\n//       (member_expression (identifier) (property_identifier))\n//       (arguments (identifier)))))\n\nconst callExpression = tree.rootNode.child(1).firstChild;\nconsole.log(callExpression);\n\n// { type: 'call_expression',\n//   startPosition: {row: 0, column: 16},\n//   endPosition: {row: 0, column: 30},\n//   startIndex: 0,\n//   endIndex: 30 }\n```\n\nIf your source code *changes*, you can update the syntax tree. This will take less time than the first parse.\n\n```javascript\n// Replace 'let' with 'const'\nconst newSourceCode = 'const x = 1; console.log(x);';\n\ntree.edit({\n  startIndex: 0,\n  oldEndIndex: 3,\n  newEndIndex: 5,\n  startPosition: {row: 0, column: 0},\n  oldEndPosition: {row: 0, column: 3},\n  newEndPosition: {row: 0, column: 5},\n});\n\nconst newTree = parser.parse(newSourceCode, tree);\n```\n\n### Parsing Text From a Custom Data Structure\n\nIf your text is stored in a data structure other than a single string, you can parse it by supplying a callback to `parse` instead of a string:\n\n```javascript\nconst sourceLines = [\n  'let x = 1;',\n  'console.log(x);'\n];\n\nconst tree = parser.parse((index, position) => {\n  let line = sourceLines[position.row];\n  if (line) {\n    return line.slice(position.column);\n  }\n});\n```\n\n### Asynchronous Parsing\n\nIf you have source code stored in a [superstring](https://github.com/atom/superstring) `TextBuffer`, you can parse that source code on a background thread with a `Promise`-based interface:\n\n```javascript\nconst {TextBuffer} = require('superstring');\n\nasync function test() {\n  const buffer = new TextBuffer('const x= 1; console.log(x);');\n  const newTree = await parser.parseTextBuffer(buffer, oldTree);\n}\n```\n\nUsing a background thread can introduce a slight delay, so you may want to allow *some* work to be done on the main thread, in the hopes that parsing will complete so quickly that you won't even *need* a background thread:\n\n```javascript\nasync function test2() {\n  const buffer = new TextBuffer('const x= 1; console.log(x);');\n  const newTree = await parser.parseTextBuffer(buffer, oldTree, {\n    syncOperationCount: 1000\n  });\n}\n```\n","readmeFilename":"README.md"}