Giter Club home page Giter Club logo

tree-sitter-mojo's Introduction

tree-sitter-mojo

This project provides a Tree-sitter grammar for the Mojo programming language. It is based on the grammar for Python, reflecting the similar syntax structures between Python and Mojo.

Project Overview

The Mojo programming language shares a syntax that is nearly identical to Python. To accommodate the specifics of Mojo while leveraging existing robust solutions, this Tree-sitter grammar is derived from the official tree-sitter-python repository. Necessary modifications to the Python grammar to support Mojo-specific elements are integrated automatically on a weekly basis through GitHub Actions.

Automation with GitHub Actions

The primary customization in this project resides in a single GitHub Actions workflow: tree_sitter_maker.yml. This workflow is responsible for periodically updating the Tree-sitter grammar to adapt any changes from the Python grammar and apply Mojo-specific adjustments.

The updated grammar files are automatically generated and maintained through this automated process, ensuring that the Tree-sitter grammar for Mojo is always up-to-date with the latest syntactical standards of both Python and Mojo.

Adding Mojo-Specific Keywords

You can add Mojo-specific keywords like fn to the grammar by including them in the env: section of the tree_sitter_maker.yml. This allows for easy customization and expansion of the grammar to fit the evolving needs of the Mojo language.

Setting Up Helix for Mojo

To use this Tree-sitter grammar with the Helix editor, follow the setup instructions below:

1. Configure Helix

First, create a languages.toml configuration file in your Helix setup located at ~/.config/helix:

use-grammars = { only = [ "mojo" ] }

[language-server]
mojo = { command = "mojo-lsp-server" }

[[language]]
name = "mojo"
scope = "source.mojo"
roots = []
injection-regex = "mojo"
file-types = ["mojo", "๐Ÿ”ฅ"]
comment-token = "#"
indent = { tab-width = 4, unit = "    " }
language-servers = [ "mojo" ]

[[grammar]]
name = "mojo"
source = { git = "https://github.com/garam-kim1/tree-sitter-mojo", rev = "46f89a2a6554789d534faf56e4ce2ebb3a1a5160" }

2. Install the Grammar

After configuring, fetch, and build the grammar using the following commands in the Helix terminal:

hx --grammar fetch
cd ~/.config/helix
mkdir -p runtime/queries/mojo/
cp -r runtime/grammars/sources/mojo/runtime/queries/mojo/* runtime/queries/mojo/
hx --grammar build

These steps will integrate the Mojo language support into Helix, enabling syntax highlighting and other language-specific features.

tree-sitter-mojo's People

Contributors

maxbrunsfeld avatar rewinfrey avatar amaanq avatar tausbn avatar dcreager avatar patrickt avatar tclem avatar thehamsta avatar calixteman avatar stsewd avatar garam-kim1 avatar observeroftime avatar joshvera avatar berchn avatar robrix avatar sjord avatar aymannadeem avatar bm424 avatar eloitor avatar hellebore avatar drjdn avatar lukepistrol avatar m-novikov avatar the-mikedavis avatar samanpa avatar p-e-w avatar resolritter avatar aryx avatar jasontatton avatar yoff avatar

Stargazers

Alexander Zhipa avatar Josh S Wilkinson avatar Jeremy Brudvik avatar

Watchers

Dmitry Salin 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.