{"name":"tree-sitter","version":"0.22.4","description":"Node.js bindings to the Tree-sitter parsing library","repository":{"type":"git","url":"git+ssh://git@github.com/tree-sitter/node-tree-sitter.git"},"publishConfig":{"access":"public"},"license":"MIT","author":{"name":"Max Brunsfeld","email":"maxbrunsfeld@gmail.com"},"contributors":[{"name":"Segev Finer","email":"segev208@gmail.com"},{"name":"Boris Verkhovskiy","email":"boris.verk@gmail.com"}],"main":"index.js","types":"tree-sitter.d.ts","keywords":["incremental","parsing","tree-sitter"],"dependencies":{"node-addon-api":"^8.3.0","node-gyp-build":"^4.8.4"},"devDependencies":{"@types/node":"^22.10.2","@types/tmp":"^0.2.6","glob":"^11.0.0","node-gyp":"^11.0.0","prebuildify":"^6.0.1","tmp":"^0.2.3","tree-sitter-c":"^0.23.4","tree-sitter-embedded-template":"^0.23.2","tree-sitter-html":"^0.23.2","tree-sitter-java":"^0.23.5","tree-sitter-javascript":"^0.23.1","tree-sitter-json":"^0.24.8","tree-sitter-python":"^0.23.6","tree-sitter-ruby":"^0.23.1","tree-sitter-rust":"^0.23.2","typedoc":"^0.27.6","typedoc-plugin-rename-defaults":"^0.7.2","typescript":"^5.7.2"},"scripts":{"docs":"typedoc --out docs/api tree-sitter.d.ts --readme README.md","install":"node-gyp-build","build":"prebuildify --napi --strip","rebuild":"node-gyp rebuild","test":"node -e \"require('child_process').spawnSync('node', ['--test', ...require('glob').sync('test/**/*.js')], {stdio:'inherit'})\""},"_id":"tree-sitter@0.22.4","gitHead":"483e1853edd4e3e228dd0b0b3196d7cb85a4b093","bugs":{"url":"https://github.com/tree-sitter/node-tree-sitter/issues"},"homepage":"https://github.com/tree-sitter/node-tree-sitter#readme","_nodeVersion":"20.18.1","_npmVersion":"10.8.2","dist":{"integrity":"sha512-usbHZP9/oxNsUY65MQUsduGRqDHQOou1cagUSwjhoSYAmSahjQDAVsh9s+SlZkn8X8+O1FULRGwHu7AFP3kjzg==","shasum":"7d29547f663ff6f49ee8d1ac444e6fa169c72b77","tarball":"http://registry-npm.ywwl.com/tree-sitter/download/tree-sitter-0.22.4.tgz","fileCount":80,"unpackedSize":4305148,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDt+uu5mize632YAjVvvu7lInp9auENJda/Aa20bsyOhAIgLUHI06LiSSSwhV9V358mfcKTXNw8VtBwGBAjkxk8Uj4="}],"size":1536047,"noattachment":false,"key":"/tree-sitter/-/tree-sitter-0.22.4.tgz"},"_npmUser":{"name":"maxbrunsfeld","email":"maxbrunsfeld@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tree-sitter_0.22.4_1735524322251_0.26036749759247324"},"_hasShrinkwrap":false,"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":1735524322481,"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":1735524322481,"dist-tags":{"latest":"0.25.1"}}