Tree-sitter Ruby Grammar

repository·master·Indexed 42 days ago

https://github.com/tree-sitter/tree-sitter-ruby

A Ruby grammar implementation for the tree-sitter incremental parsing library, version 0.23.1. It enables the generation of concrete syntax trees (CSTs) for Ruby code to support syntax highlighting, code analysis, and refactoring tools. Includes Node.js bindings and nodeTypeInfo for programmatic inspection of the Ruby syntax tree.

Tokens
602
Snippets
3
Records
4
Agent score
3%

What's inside Tree-sitter Ruby

  1. Use eslint-config-treesitter for Ruby linting

    master

    To apply the recommended ESLint rules for tree-sitter projects (including Ruby) to your JavaScript configuration, import eslint-config-treesitter and spread its exported configuration array into your eslint.config.mjs file.

    import treesitter from 'eslint-config-treesitter';
    
    export default [
      ...treesitter,
    ];
  2. Use the Node.js bindings for tree-sitter-ruby

    master

    The tree-sitter-ruby package provides Node.js bindings for the Ruby grammar. It is designed to work with both standard Node.js (via node-gyp-build) and Bun (via prebuilt .node files). Once required, the module provides the necessary interface to parse Ruby code using the Tree-sitter engine.

    Note: The module also exports nodeTypeInfo, which contains metadata about the different node types defined in the Ruby grammar, useful for inspecting the syntax tree.

    const parser = require('tree-sitter-ruby');
    
    // The exported object typically provides a parser instance or factory
    // depending on how it is integrated with the core tree-sitter library.
  3. Access Ruby node type information via nodeTypeInfo

    master

    The tree-sitter-ruby module exports a nodeTypeInfo property. This property contains a JSON object mapping node types to their specific characteristics in the Ruby grammar. This is useful for developers building tools that need to programmatically understand the structure of the Ruby syntax tree.

    const ruby = require('tree-sitter-ruby');
    
    if (ruby.nodeTypeInfo) {
      console.log('Available node types:', ruby.nodeTypeInfo);
    }