tree-sitter-coi

February 22, 2026 ยท View on GitHub

Tree-sitter grammar for the Coi programming language.

Coi is a component-based language for building high-performance web applications that compile to WebAssembly.

Installation

npm

npm install tree-sitter-coi

Build from source

git clone https://github.com/jturner/tree-sitter-coi
cd tree-sitter-coi
npm install
npm run build

Usage

Node.js

const Parser = require('tree-sitter');
const Coi = require('tree-sitter-coi');

const parser = new Parser();
parser.setLanguage(Coi);

const sourceCode = `
component Counter {
    mut int count = 0;

    def increment() : void {
        count++;
    }

    view {
        <div>{count}</div>
    }
}
`;

const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());

WebAssembly

npm run build-wasm

This generates tree-sitter-coi.wasm for use in browsers and other WASM environments.

Language Features

The grammar supports:

  • Components - component Name { ... } with optional pub mut parameters
  • Pods - pod Name { ... } for plain data types
  • Functions/Methods - def name() : ReturnType { ... }
  • Type Definitions - type Name { ... }
  • Structs - struct Name { ... }
  • Enums - enum Name { Variant1, Variant2 }, including shared and pub modifiers
  • Match Expressions - pattern matching with enum, pod, and variant patterns
  • View Blocks - JSX-like syntax for UI with <if>, <for>, and <else> tags
  • Style Blocks - Embedded CSS
  • Lifecycle Hooks - init, mount, tick
  • Control Flow - if/else (with or without braces), for, while
  • Imports/Modules - import "path", module Name
  • App Configuration - app { ... }
  • Routing - router { "/path" => Component(...) }
  • Move semantics - := move assignment, &= element ref binding

Development

Generate parser

npm run generate

Run tests

npm run test

Parse a file

npm run parse -- path/to/file.coi

Query Files

The queries/ directory contains tree-sitter query files:

  • highlights.scm - Syntax highlighting
  • injections.scm - Language injections (CSS in style blocks)
  • textobjects.scm - Text objects for editor navigation

License

MIT