Giter Site home page Giter Site logo

haldun / treesitterlanguages Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simonbs/treesitterlanguages

0.0 1.0 0.0 11.82 MB

Languages for Tree-sitter wrapped in Swift packages

License: MIT License

C++ 0.12% Scheme 0.04% C 99.81% Swift 0.03%

treesitterlanguages's Introduction

TreeSitterLanguages

Languages for the Tree-sitter parser generator wrapped in Swift packages.

Motivation

There are two reasons this package exists:

  1. As an easy way to add several Tree-sitter languages to an app and particularly to an app that uses the Runestone framework.
  2. To show how a Tree-sitter language can be wrapped in a Swift package.

It is not recommended to use this package if you only need to add a few Tree-sitter languages to your app. Instead you should add the languages manually.

Installation

The languages are distributed using the Swift Package Manager as separated libraries in a single Swift package. Install the package in your project by adding it as a dependency in your Package.swift manifest or through "Package Dependencies" in your project settings.

let package = Package(
    dependencies: [
        .package(url: "[email protected]:simonbs/TreeSitterLanguages.git", from: "0.1.0")
    ]
)

Usage

The Swift package contains multiple libraries. Each language is wrapped in its own Swift package so you don't need to import a whole suite of languages in case you only need a few.

The package contains the following three libraries for each language.

Name Purpose
TreeSitter{Language} The C code for the generated Tree-sitter parser. Each package exposes a function named like tree_sitter_{language}.
TreeSitter{Language}Queries The queries to be used with the language. For more information on queries, please refer to Tree-sitter's documentation. The only reason this is a separate library and not part of the TreeSitter{Language} library is that C code and Swift code cannot be mixed in a library using Swift Package Manager.
TreeSitter{Language}Runestone Exposes the language to be used with Runestone. This library depends on the TreeSitter{Language} and TreeSitter{Language}Queries libraries and it is the only library you need to import when using Runestone. The library exposes the language as an extension on TreeSitterLanguage (e.g. TreeSitterLanguage.javaScript) that's ready to be used in Runestone. It also includes the indentation specification for select languages.

Furthermore the package contains the TreeSitterLanguagesCommon library which exposes base types from Tree-sitter like TSLanguage. This is useful when you need to refer to these types in your source code, for example if you return a TSLanguage from a function.

Compatibility

The parser.c file of a language is generated using tree-sitter-cli and a language generated with one version of the CLI may not be compatible with future versions of Tree-sitter. All languages in this repository are kept compatible with the version of Tree-sitter used by my Runestone framework.

Acknowledgements

The TreeSitterLanguages repository contains files copied from the following repositories. I had originally added these repositories as submodules but it turned out to be very impractical when the package is used with Swift Package Manager because checking out the repository and all the submodules would take a long time and doing so on a slow connection (for example when commuting) would be unbearable.

Thanks to all the contributors to these repositories for their great effort in ensuring Tree-sitter supports a wide array of languages.

treesitterlanguages's People

Contributors

eliperkins avatar simonbs avatar staykids avatar

Watchers

 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.