npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-sitter-craft

v0.1.10

Published

Tree-sitter grammar for Craft DSL - A domain-specific language for modeling business use cases and domain interactions

Readme

Tree-sitter Craft

npm npm

Tree-sitter grammar for Craft DSL - A domain-specific language for modeling business use cases and domain interactions with powerful visualization capabilities for domain-driven design and C4 architecture diagrams.

Features

  • 🔥 High-performance parsing with Tree-sitter's incremental parsing
  • 🎯 Syntax highlighting with semantic tokens and queries
  • 📝 Rich language support for VSCode and other editors
  • 🌐 WebAssembly support for browser-based editors
  • 🧪 Well-tested grammar with comprehensive test suite

Installation

npm

npm install tree-sitter-craft

Using in Node.js

import Parser from 'tree-sitter';
import Craft from 'tree-sitter-craft';

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

const sourceCode = `
services {
  UserService {
    domains: Authentication, Profile
    language: typescript
  }
}

use_case "User Registration" {
  when Business_User creates Account
    Authentication validates email format
    Authentication asks Database to check email uniqueness
    Profile creates user profile
}
`;

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

Using in Web Browsers

<script src="https://unpkg.com/web-tree-sitter@^0.25.0/tree-sitter.js"></script>
<script>
(async () => {
  await TreeSitter.init();
  const parser = new TreeSitter();
  const Lang = await TreeSitter.Language.load('tree-sitter-craft.wasm');
  parser.setLanguage(Lang);
  
  const tree = parser.parse('use_case "Example" { when user does something }');
  console.log(tree.rootNode.toString());
})();
</script>

Language Overview

Craft DSL enables you to model:

  • Services: Deployable units with technology specifications
  • Use Cases: Business scenarios through triggers and actions
  • Domains: Core business domains and their interactions
  • Architecture: Component flows and system design
  • Exposures: External access points and relationships

Example Syntax

// Service definition
services {
  EcommerceAPI {
    domains: Order, Payment, Inventory
    language: nodejs
    data-stores: postgres, redis
  }
}

// Use case modeling
use_case "Order Processing" {
  when Customer creates Order
    Order validates product availability
    Order asks Inventory to reserve items
    Order creates payment request
    Order notifies "OrderCreated"
    
  when Payment listens "OrderCreated"
    Payment processes payment
    Payment returns confirmation
}

// Architecture definition
arch OrderFlow {
  presentation:
    WebApp > LoadBalancer
    
  gateway:
    LoadBalancer > API[framework: express, ssl: true]
    API > Database[type: postgres]
}

Development

Prerequisites

  • Node.js 16+
  • Tree-sitter CLI: npm install -g tree-sitter-cli

Building

# Generate parser from grammar
npm run generate

# Build native bindings
npm run build

# Build WebAssembly module
npm run build-wasm

# Run tests
npm test

Grammar Development

The grammar is defined in grammar.js. After making changes:

  1. Regenerate the parser: npm run generate
  2. Update tests in test/corpus/
  3. Run tests: npm test
  4. Build WASM: npm run build-wasm

Syntax Highlighting

This package includes syntax highlighting queries for Tree-sitter compatible editors:

  • highlights.scm: Semantic highlighting rules
  • Supports 40+ distinct token types for precise syntax coloring
  • Context-aware highlighting based on grammar structure

Usage with Editors

The highlighting queries are automatically available when the package is installed. Editors that support Tree-sitter will use the queries/highlights.scm file.

API Reference

Parser Methods

// Basic parsing
const tree = parser.parse(sourceCode);

// Incremental parsing (re-parse only changed parts)
const newTree = parser.parse(newSourceCode, tree);

// Get syntax tree as S-expression
console.log(tree.rootNode.toString());

Query System

import { Query } from 'tree-sitter';

// Load highlighting query
const highlightQuery = new Query(Craft, highlightQuerySource);

// Execute query
const captures = highlightQuery.captures(tree.rootNode);
captures.forEach(({ name, node }) => {
  console.log(`${name}: ${node.text}`);
});

Testing the Grammar

The grammar includes comprehensive tests covering:

  • ✅ Service definitions and properties
  • ✅ Use case modeling and flows
  • ✅ Domain interactions and events
  • ✅ Architecture specifications
  • ✅ Error recovery and edge cases

Running Tests

# Run all grammar tests
npm test

# Parse a specific file
npx tree-sitter parse <file.craft>

# Test with query files
npx tree-sitter query <query-file> <file.craft> 

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes to grammar.js
  4. Add tests in test/corpus/
  5. Run tests: npm test
  6. Submit a pull request

License

MIT © Tiago Carcao

Related Projects


Tree-sitter Craft provides the parsing foundation for rich Craft DSL tooling and editor support.