Tree-sitter grammar for the Coi programming language.
Coi is a component-based language for building high-performance web applications that compile to WebAssembly.
npm install tree-sitter-coigit clone https://github.com/jturner/tree-sitter-coi
cd tree-sitter-coi
npm install
npm run buildconst 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());npm run build-wasmThis generates tree-sitter-coi.wasm for use in browsers and other WASM environments.
The grammar supports:
- Components -
component Name { ... }with optionalpub mutparameters - Pods -
pod Name { ... }for plain data types - Functions/Methods -
def name() : ReturnType { ... } - Type Definitions -
type Name { ... } - Structs -
struct Name { ... } - Enums -
enum Name { Variant1, Variant2 }, includingsharedandpubmodifiers - 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
npm run generatenpm run testnpm run parse -- path/to/file.coiThe queries/ directory contains tree-sitter query files:
highlights.scm- Syntax highlightinginjections.scm- Language injections (CSS in style blocks)textobjects.scm- Text objects for editor navigation
MIT