All Projects → tree-sitter → tree-sitter-cli

tree-sitter / tree-sitter-cli

Licence: MIT license
CLI tool for creating and testing tree-sitter parsers

Programming Languages

javascript
184084 projects - #8 most used programming language
C++
36643 projects - #6 most used programming language
HTML
75241 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to tree-sitter-cli

nvim-yati
Yet another tree-sitter powered indent plugin for Neovim.
Stars: ✭ 60 (+39.53%)
Mutual labels:  tree-sitter
spellsitter.nvim
Treesitter powered spellchecker
Stars: ✭ 251 (+483.72%)
Mutual labels:  tree-sitter
tree-sitter-php
PHP grammar for tree-sitter
Stars: ✭ 83 (+93.02%)
Mutual labels:  tree-sitter
canonix
Experiment in Nix formatting
Stars: ✭ 18 (-58.14%)
Mutual labels:  tree-sitter
tree-edit
🌲 Structural editing in Emacs for any™ language!
Stars: ✭ 211 (+390.7%)
Mutual labels:  tree-sitter
tree-sitter-kotlin
Kotlin grammar for Tree-Sitter
Stars: ✭ 35 (-18.6%)
Mutual labels:  tree-sitter
tree-sitter-markdown
A markdown grammar for tree-sitter
Stars: ✭ 168 (+290.7%)
Mutual labels:  tree-sitter
haskell-tree-sitter
Haskell bindings for tree-sitter
Stars: ✭ 123 (+186.05%)
Mutual labels:  tree-sitter
tree-sitter-rescript
ReScript parser for Tree-Sitter
Stars: ✭ 20 (-53.49%)
Mutual labels:  tree-sitter
dropincc.java
A small and easy to use parser generator. Specify your grammar in pure java and compile dynamically. Especially suitable for DSL creation in java.
Stars: ✭ 90 (+109.3%)
Mutual labels:  parser-generator
tree-sitter-clojure
No description or website provided.
Stars: ✭ 71 (+65.12%)
Mutual labels:  tree-sitter
tree-sitter-sql
SQL syntax highlighting for tree-sitter
Stars: ✭ 33 (-23.26%)
Mutual labels:  tree-sitter
difftastic
a syntax-aware diff 🟥🟩
Stars: ✭ 1,701 (+3855.81%)
Mutual labels:  tree-sitter
tree-sitter-verilog
Verilog grammar for tree-sitter
Stars: ✭ 49 (+13.95%)
Mutual labels:  tree-sitter
tree-sitter.el
An Emacs dynamic module exposing tree-sitter.
Stars: ✭ 59 (+37.21%)
Mutual labels:  tree-sitter
ruby-tree-sitter
Ruby bindings to tree-sitter
Stars: ✭ 48 (+11.63%)
Mutual labels:  tree-sitter
tree-sitter-yaml
YAML grammar for tree-sitter
Stars: ✭ 29 (-32.56%)
Mutual labels:  tree-sitter
kiuatan
A parser library for Pony.
Stars: ✭ 15 (-65.12%)
Mutual labels:  parser-generator
tree-sitter-rust
Rust grammar for tree-sitter
Stars: ✭ 199 (+362.79%)
Mutual labels:  tree-sitter
Tree Sitter
An incremental parsing system for programming tools
Stars: ✭ 7,083 (+16372.09%)
Mutual labels:  tree-sitter

tree-sitter-cli

Incremental parsers for node

Build Status Build status


⚠️ This repository is deprecated. ⚠️

The source code for the Tree-sitter CLI is now part of the main Tree-sitter repository.


Installation

npm install tree-sitter-cli

Creating a language

Create a grammar.js in the root directory of your module. This file should create and export a grammar object using tree-sitter's helper functions:

module.exports = grammar({
  name: "arithmetic",

  extras: $ => [$.comment, /\s/],

  rules: {
    program: $ => repeat(choice(
      $.assignment_statement,
      $.expression_statement
    )),

    assignment_statement: $ => seq(
      $.variable, "=", $.expression, ";"
    ),

    expression_statement: $ => seq(
      $.expression, ";"
    ),

    expression: $ => choice(
      $.variable,
      $.number,
      prec.left(1, seq($.expression, "+", $.expression)),
      prec.left(1, seq($.expression, "-", $.expression)),
      prec.left(2, seq($.expression, "*", $.expression)),
      prec.left(2, seq($.expression, "/", $.expression)),
      prec.left(3, seq($.expression, "^", $.expression))
    ),

    variable: $ => /\a\w*/,

    number: $ => /\d+/,

    comment: $ => /#.*/
  }
});

Run tree-sitter generate. This will generate a C function for parsing your language, a C++ function that exposes the parser to javascript, and a binding.gyp file for compiling these sources into a native node module.

Grammar syntax

The grammar function takes an object with the following keys:

  • name - the name of the language.
  • rules - an object whose keys are rule names and whose values are Grammar Rules. The first key in the map will be the start symbol. See the 'Rules' section for how to construct grammar rules.
  • extras - an array of Grammar Rules which may appear anywhere in a document. This construct is used to useful for things like whitespace and comments in programming languages.
  • conflicts - an array of arrays of Grammar Rules which are known to conflict with each other in an LR(1) parser. You'll need to use this if writing a grammar that is not LR(1).

Rules

  • $.property references - match another rule with the given name.
  • String literals - match exact strings.
  • RegExp literals - match strings according to ECMAScript regexp syntax. Assertions (e.g. ^, $) are not yet supported.
  • choice(rule...) - matches any one of the given rules.
  • repeat(rule) - matches any number of repetitions of the given rule.
  • seq(rule...) - matches each of the given rules in sequence.
  • blank() - matches the empty string.
  • optional(rule) - matches the given rule or the empty string.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].