@codebolt/codeparser
v1.2.1
Published
Code parsing utilities with tree-sitter support for multiple programming languages
Readme
@codebolt/codeparser
Code parsing utilities with tree-sitter support for multiple programming languages.
Features
- Parse source code files across multiple programming languages
- Extract definitions and code structure using tree-sitter parsers
- Support for JavaScript, TypeScript, Python, Rust, Go, Java, C/C++, C#, Ruby, PHP, and Swift
- Tree-sitter WASM binaries for cross-platform compatibility
Installation
npm install @codebolt/codeparserUsage
import { parseSourceCodeForDefinitionsTopLevel, parseFile, loadRequiredLanguageParsers } from '@codebolt/codeparser';
// Parse a directory for source code definitions
const definitions = await parseSourceCodeForDefinitionsTopLevel('./src');
// Parse a specific file
const languageParsers = await loadRequiredLanguageParsers(['./src/example.ts']);
const fileDefinitions = await parseFile('./src/example.ts', languageParsers);Supported Languages
- JavaScript (.js, .jsx)
- TypeScript (.ts, .tsx)
- Python (.py)
- Rust (.rs)
- Go (.go)
- Java (.java)
- C (.c, .h)
- C++ (.cpp, .hpp)
- C# (.cs)
- Ruby (.rb)
- PHP (.php)
- Swift (.swift)
API
Functions
parseSourceCodeForDefinitionsTopLevel(dirPath: string)- Parse a directory for source code definitionsparseFile(filePath: string, languageParsers: LanguageParser)- Parse a specific fileloadRequiredLanguageParsers(filesToParse: string[])- Load language parsers for specific fileslistFiles(dirPath: string, recursive: boolean)- List files in a directoryseparateFiles(allFiles: string[])- Separate files into parseable and remaining files
Types
LanguageParser- Language parser interfaceASTNode- Abstract syntax tree node interfaceParserConfig- Parser configuration interface
