Git Product home page Git Product logo

ruby-tree-sitter's Introduction

TreeSitter

This gem wraps around tree-sitter.

Installation

Add this line to your application's Gemfile:

gem 'tree-sitter'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tree-sitter

Usage

Tree-sitter performs two different operations: compiling grammars and parsing text with those grammars.

This gem is only concerned with parsing a blob of text, given the appropriate grammars. Compiling grammars from JSON is trivial and can just be kept as an executable generated from C.

Running the parser

The libruntime static library needs to make use of the C code generated by the libcompile executable. Once you've got those, you'll need to provide an absolute path to the directory containing the C files that the library can incorporate. For example:

# if you've installed this gem
$ TREE_SITTER_PARSER_DIR=/somewhere/code bundle install
# if you're using this gem locally
$ TREE_SITTER_PARSER_DIR=/somewhere/code bundle exec rake compile

This directory is appended with the glob suffix **/*.{c,cc}, so it can contain as many nested parser files as necessary.

Then, you can start making use of the parser:

# first argument is the string to parse
# second argument is a set of options; currently, only one is available, `language:`,
# which identifies the text's language
document = TreeSitter::Document.new('a + b * 5', language: 'tree_sitter_arithmetic')

# you can change any of these values whenever you want, just remember to call `parse`
# provide the function name
document.input_string = '12 * 12'
document.language = "tree_sitter_python"
document.parse

Development

After checking out the repo, run script/bootstrap to install dependencies. Then, run script/test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

ruby-tree-sitter's People

Contributors

beneddy avatar gjtorikian avatar zackfern avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.