Skip to content

kraken-lang/tree-sitter-kraken

Repository files navigation

Kraken Language

KRAKEN LANGUAGE
TREE SITTER

Tree-sitter grammar for the Kraken programming language. Provides fast, incremental parsing for syntax highlighting, code navigation, and editor integration.

Version: v0.9.2 — This repo tracks the Kraken language version. Tags match compiler tags.

Features

This grammar covers the full syntax of Kraken v0.9.2, including:

  • Function declarations with generics, pub, async, unsafe, const fn, where clauses
  • Struct, enum, union, class, and interface declarations
  • Trait declarations and implementations with associated types
  • Closure expressions with move semantics
  • Advanced pattern matching (tuples, structs, enums, enum variants, ranges, guards, or-patterns)
  • Type system (primitives, generics, tuples, arrays, function types, pointers, references, trait objects, containers, slices)
  • Control flow (if, while, for, for-in, match, defer, break, continue)
  • Operators (arithmetic, logical, bitwise, comparison, compound assignment)
  • Module system (import, module declarations)
  • Unsafe blocks and raw pointers
  • Range expressions and try operator
  • Await and spawn expressions
  • Enum variant paths (Enum::Variant)
  • Turbofish syntax for explicit type arguments
  • Attributes (#[repr(C)], etc.)
  • Hex, binary, and octal integer literals
  • Doc comments (///, //!)

Canonical Identifiers

  • File extension: .kr
  • Language name: kraken
  • Scope: source.kraken
  • Tree-sitter language ID: kraken

All editor integrations should use these identifiers for consistency.

Installation

Node.js

npm install tree-sitter-kraken  # (publishing planned)

Rust

Add to your Cargo.toml:

[dependencies]
tree-sitter-kraken = "0.9.2"  # (publishing to crates.io planned)

Usage

Node.js

const Parser = require('tree-sitter');
const Kraken = require('tree-sitter-kraken');

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

const sourceCode = `
fn main() -> int {
    let x = 42;
    return x;
}
`;

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

Rust

use tree_sitter::Parser;

fn main() {
    let mut parser = Parser::new();
    parser.set_language(tree_sitter_kraken::language()).unwrap();
    
    let source_code = r#"
        fn main() -> int {
            let x = 42;
            return x;
        }
    "#;
    
    let tree = parser.parse(source_code, None).unwrap();
    println!("{}", tree.root_node().to_sexp());
}

Editor Integration

Neovim

Using nvim-treesitter:

require('nvim-treesitter.configs').setup {
  ensure_installed = { "kraken" },
  highlight = { enable = true },
}

Helix

Add to languages.toml:

[[language]]
name = "kraken"
scope = "source.kraken"
file-types = ["kr"]
roots = ["Cargo.toml"]
comment-token = "//"
indent = { tab-width = 4, unit = "    " }

[[grammar]]
name = "kraken"
source = { git = "https://github.com/kraken-lang/tree-sitter-kraken", rev = "main" }

Development

Building

Generate the parser from grammar:

npm install
npm run build

Testing

Run the test suite:

npm test

Parse a specific file:

npm run parse examples/hello.kr

Grammar Structure

The grammar is defined in grammar.js and covers:

  • Declarations: Functions, structs, enums, traits, impl blocks
  • Statements: Let bindings, control flow, expressions
  • Expressions: Literals, operators, calls, closures
  • Patterns: Comprehensive pattern matching support
  • Types: Full type system including generics and trait objects

Syntax Highlighting

Syntax highlighting queries are provided in queries/highlights.scm. The grammar supports semantic highlighting for:

  • Keywords and operators
  • Function and type names
  • Variables and parameters
  • String literals and escape sequences
  • Comments
  • Attributes and macros

Performance

Tree-sitter provides incremental parsing, making it efficient for real-time editor use. The parser can handle large Kraken files with minimal latency.

Compatibility

This grammar tracks the Kraken language version. Version 0.9.2 covers the full syntax of Kraken v0.9.2. Gaps or edge cases are tracked in Issues.

Note: Tree-sitter grammars focus on syntax structure, not full semantic validation. For complete language correctness, use the Kraken compiler.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

About

Tree-sitter grammar for Kraken Lang: fast, incremental parsing for syntax highlighting, code folding, and editor integrations (Neovim, Helix, Zed, etc.).

Topics

Resources

License

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors