{"name":"tree-sitter","version":"0.22.2","keywords":["incremental","parsing","tree-sitter"],"author":{"name":"Max Brunsfeld","email":"maxbrunsfeld@gmail.com"},"license":"MIT","_id":"tree-sitter@0.22.2","contributors":[{"name":"Segev Finer","email":"segev208@gmail.com"},{"name":"Boris Verkhovskiy","email":"boris.verk@gmail.com"}],"homepage":"https://github.com/tree-sitter/node-tree-sitter#readme","bugs":{"url":"https://github.com/tree-sitter/node-tree-sitter/issues"},"dist":{"shasum":"07c0e6e5ba56958920ae9fe6962105f59a491948","tarball":"http://registry-npm.ywwl.com/tree-sitter/download/tree-sitter-0.22.2.tgz","fileCount":80,"integrity":"sha512-8v6N8UTnsJvLKdfQzX9yuaZwzUX2pJnZvvfE7P+FBmC52DmoOGZ72G4mmkJ90IB+WZUpM1wQk9LFd89bJh96AA==","signatures":[{"sig":"MEYCIQC/Zg3xJqULLt5GWL7Wi3pokffDsU8gFS38WOkCOcBwZgIhAJAoRcSgPcA3nZLElTGwvOy+DHZRoxIGjSbLkBlckDEx","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4305087,"size":1536034,"noattachment":false,"key":"/tree-sitter/-/tree-sitter-0.22.2.tgz"},"main":"index.js","types":"tree-sitter.d.ts","gitHead":"e1c57810b91efc6caa6feab1fef62a16c011ee99","scripts":{"docs":"typedoc --out docs/api tree-sitter.d.ts --readme README.md","test":"node -e \"require('child_process').spawnSync('node', ['--test', ...require('glob').sync('test/**/*.js')], {stdio:'inherit'})\"","build":"prebuildify --napi --strip","install":"node-gyp-build","rebuild":"node-gyp rebuild"},"_npmUser":{"name":"maxbrunsfeld","email":"maxbrunsfeld@gmail.com"},"repository":{"url":"git+ssh://git@github.com/tree-sitter/node-tree-sitter.git","type":"git"},"_npmVersion":"10.8.2","description":"Node.js bindings to the Tree-sitter parsing library","directories":{},"_nodeVersion":"20.18.1","dependencies":{"node-addon-api":"^8.3.0","node-gyp-build":"^4.8.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tmp":"^0.2.3","glob":"^11.0.0","typedoc":"^0.27.6","node-gyp":"^11.0.0","@types/tmp":"^0.2.6","typescript":"^5.7.2","@types/node":"^22.10.2","prebuildify":"^6.0.1","tree-sitter-c":"^0.23.4","tree-sitter-html":"^0.23.2","tree-sitter-java":"^0.23.5","tree-sitter-json":"^0.24.8","tree-sitter-ruby":"^0.23.1","tree-sitter-rust":"^0.23.2","tree-sitter-python":"^0.23.6","tree-sitter-javascript":"^0.23.1","tree-sitter-embedded-template":"^0.23.2","typedoc-plugin-rename-defaults":"^0.7.2"},"_npmOperationalInternal":{"tmp":"tmp/tree-sitter_0.22.2_1735522586915_0.8597046634509096","host":"s3://npm-registry-packages-npm-production"},"readme":"# Node Tree-sitter\n\n[![CI][ci]](https://github.com/tree-sitter/node-tree-sitter/actions/workflows/ci.yml)\n[![npm][npm]](https://npmjs.com/package/tree-sitter)\n[![docs][docs]](https://tree-sitter.github.io/node-tree-sitter)\n\nThis module provides Node.js bindings to the [tree-sitter] parsing library.\n\n## Installation\n\n```sh\nnpm install tree-sitter\n```\n\n## Basic Usage\n\n### Prerequisites\n\nFirst, you'll need a Tree-sitter grammar for the language you want to parse. There are many [existing grammars][grammars],\nsuch as [tree-sitter-javascript][javascript]. These grammars can typically be installed with a package manager like NPM,\nso long as the author has published them.\n\n```sh\nnpm install tree-sitter-javascript\n```\n\nYou can also develop a new grammar by using the [Tree-sitter CLI][cli] and following the [docs][ts docs].\n\n### Parsing Source Code\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// {\n//   type: 'call_expression',\n//   startPosition: {row: 0, column: 16},\n//   endPosition: {row: 0, column: 30},\n//   startIndex: 0,\n//   endIndex: 30\n// }\n```\n\nIf your source code *changes*, you can update the syntax tree. This is much faster than the first parse.\n\n```javascript\n// In the code, we replaced 'let' with 'const'.\n// So, we set our old end index to 3, and our new end index to 5.\n// Note that the end index is exclusive.\nconst newSourceCode = 'const x = 1; console.log(x);';\n//                        ^ ^\n// indices:               3 5\n// points:            (0,3) (0,5)\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, such as a rope or array, you can parse it by supplying\na 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### Further Reading\n\nIt's recommended that you read the [Tree-sitter documentation][usage docs] on using parsers to get a higher-level overview\nof the API. Once you're comfortable with the basics, you can explore the [full API documentation](https://tree-sitter.github.io/node-tree-sitter),\nwhich should map closely to the C API, though there are some differences.\n\n[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/node-tree-sitter/ci.yml?logo=github&label=CI\n[cli]: https://github.com/tree-sitter/tree-sitter/tree/master/cli\n[docs]: https://img.shields.io/badge/docs-website-blue\n[npm]: https://img.shields.io/npm/v/tree-sitter?logo=npm\n[grammars]: https://github.com/tree-sitter/tree-sitter/wiki/List-of-parsers\n[javascript]: http://github.com/tree-sitter/tree-sitter-javascript\n[ts docs]: https://tree-sitter.github.io/tree-sitter/creating-parsers\n[usage docs]: https://tree-sitter.github.io/tree-sitter/using-parsers\n","publish_time":1735522587137,"maintainers":[{"name":"ahlinc","email":"ahlincq@gmail.com"},{"name":"maxbrunsfeld","email":"maxbrunsfeld@gmail.com"},{"name":"amaanq","email":"amaanq12@gmail.com"},{"name":"tclem","email":"timothy.clem@gmail.com"},{"name":"rewinfrey","email":"rick.winfrey@gmail.com"},{"name":"robrix","email":"rob.rix@github.com"},{"name":"joshvera","email":"josh@joshvera.com"},{"name":"patrickthomson","email":"patrickt@github.com"},{"name":"verhovsky","email":"boris.verk@gmail.com"}],"_cnpm_publish_time":1735522587137,"dist-tags":{"latest":"0.25.1"}}