tree-sitter-bash
repository·master·Indexed 43 days ago
https://github.com/tree-sitter/tree-sitter-bashA tree-sitter grammar for the Bash shell language version 0.25.1, providing high-performance incremental parsing for syntax highlighting, code navigation, and structural analysis.
What's inside tree-sitter-bash
- tree-sitter-bash provides a Bash grammar implementation for tree-sitter. It allows for high-performance incremental parsing of Bash scripts, enabling features like syntax highlighting, code navigation, and structural analysis in editors and tools.
Set up the development environment
masterTo begin developing or contributing to the
tree-sitter-bashrepository, you must first install the necessary dependencies using npm.npm installBuild and run tests
masterUse the following commands to build the project and execute the test suite. To maintain a continuous development workflow, you can also run tests in watch mode.
# Build and run tests once npm run build npm run test # Run build and tests in watch mode npm run test:watchUse eslint-config-treesitter for linting bash grammars
masterTo lint files using the
tree-sitter-bashgrammar with ESLint, importeslint-config-treesitterand spread its configuration into youreslint.config.mjs(Flat Config) array. This provides the necessary rules and parser settings for tree-sitter based linting.import treesitter from 'eslint-config-treesitter'; export default [ ...treesitter, ];Use tree-sitter-bash Node.js bindings
masterThe
tree-sitter-bashpackage provides Node.js bindings for the Bash grammar. It is designed to be compatible with both standard Node.js environments (vianode-gyp-build) and Bun (via prebuilt.nodefiles).When imported, the module exports the compiled tree-sitter grammar object. Additionally, it may export a
nodeTypeInfoproperty containing metadata about node types fromsrc/node-types.jsonif available.const Bash = require('tree-sitter-bash'); // The exported object is the tree-sitter grammar // You can use it with the main 'tree-sitter' libraryAccess Bash node type information via nodeTypeInfo
masterThe bindings export a
nodeTypeInfoproperty which contains a mapping of node types defined in the Bash grammar. This is useful for programmatic inspection of the grammar's structure.const Bash = require('tree-sitter-bash'); if (Bash.nodeTypeInfo) { console.log(Bash.nodeTypeInfo); }