tree-sitter-c Documentation
repository·master·Indexed 18 days ago
https://github.com/tree-sitter/tree-sitter-cA concrete syntax tree parser for the C programming language based on the C99 ISO/IEC 9899:1999 standard. Designed for the tree-sitter framework, it provides high-performance incremental parsing and includes Node.js bindings with query strings for syntax highlighting, injections, locals, and tags.
What's inside tree-sitter-c
- tree-sitter-c provides a C grammar implementation for the tree-sitter incremental parsing library. The grammar is adapted from the C99 ISO/IEC 9899:1999 standard.
Use eslint-config-treesitter for linting
masterTo apply Tree-sitter based linting rules to your project, import
eslint-config-treesitterand spread its configuration into youreslint.config.mjs(or equivalent ESLint flat config file). This provides a pre-configured set of rules designed for Tree-sitter environments.import treesitter from 'eslint-config-treesitter'; export default [ ...treesitter, ];Use the tree-sitter-c Node.js binding
masterThe
tree-sitter-cpackage provides the Node.js bindings for the C language grammar. When imported, it provides the core binding object which includes access to the C grammar's query files for syntax highlighting, injections, locals, and tags. The binding automatically handles loading the correct prebuilt binary for your platform and architecture.import treeSitterC from 'tree-sitter-c'; // The binding object contains the grammar and query strings console.log(treeSitterC.HIGHLIGHTS_QUERY);Access C grammar query strings
masterThe
tree-sitter-cbinding exposes several query strings used for advanced syntax processing. These are loaded lazily from the package's internal.scmfiles when accessed:HIGHLIGHTS_QUERY: Used for syntax highlighting.INJECTIONS_QUERY: Used for language injections.LOCALS_QUERY: Used for identifying local variables/scopes.TAGS_QUERY: Used for semantic tagging.
Note: These properties are defined as getters and will read the file from disk upon first access.
// Example of accessing available query properties const highlights = treeSitterC.HIGHLIGHTS_QUERY; const injections = treeSitterC.INJECTIONS_QUERY; const locals = treeSitterC.LOCALS_QUERY; const tags = treeSitterC.TAGS_QUERY;