# arborium-capnp

[![Part of Arborium](https://img.shields.io/badge/🌳_Arborium-grammar_collection-228B22)](https://github.com/bearcove/arborium)
[![crates.io](https://img.shields.io/crates/v/arborium-capnp.svg)](https://crates.io/crates/arborium-capnp)
[![docs.rs](https://img.shields.io/docsrs/arborium-capnp)](https://docs.rs/arborium-capnp)
[![license](https://img.shields.io/crates/l/arborium-capnp.svg)](https://github.com/bearcove/arborium)

[Cap&#039;n Proto](https://en.wikipedia.org/wiki/Cap&#039;n_Proto) grammar for [tree-sitter](https://tree-sitter.github.io/).

> Cap'n Proto serialization and RPC system; design and spec at <a href="https://capnproto.org/">capnproto.org</a>.


| | |
|---|---|
| **Inventor** | Kenton Varda |
| **Year** | 2013 |

## Usage

```rust
use arborium_capnp::language;
use tree_sitter_patched_arborium::Parser;

let mut parser = Parser::new();
parser.set_language(&language()).expect("Error loading capnp grammar");

let source_code = "/* your capnp code here */";
let tree = parser.parse(source_code, None).unwrap();
println!("{}", tree.root_node().to_sexp());
```

For most use cases, prefer the main [arborium](https://crates.io/crates/arborium) crate:

```toml
[dependencies]
arborium = { version = "*", features = ["capnp"] }
```

Or use this crate directly:

```toml
[dependencies]
arborium-capnp = "*"
```

## About Arborium

This crate is part of [**Arborium**](https://github.com/bearcove/arborium), a collection of tree-sitter grammars packaged as Rust crates, maintained by [Amos Wenger](https://fasterthanli.me).

This crate packages a `parser.c` file generated by the [tree-sitter CLI](https://tree-sitter.github.io/tree-sitter/creating-parsers#generating-the-parser). It exports a `language()` function returning the tree-sitter `Language` for **capnp**.

**Why separate crates?** Tree-sitter parsers can be large (some exceed 1MB of generated C). Splitting languages into separate crates means you only compile what you need, and parallel/incremental builds are more effective.

## Build Requirements

- **Rust**: MSRV is 1.85.0 (Rust 2024 edition)
- **C compiler**: This crate compiles C code via the [`cc`](https://crates.io/crates/cc) crate

### Supported Targets

- All major platforms: Linux, macOS, Windows
- WebAssembly: `wasm32-unknown-unknown` (with custom sysroot)

## Upstream Grammar

| | |
|---|---|
| **Repository** | [tree-sitter-grammars/tree-sitter-capnp](https://github.com/tree-sitter-grammars/tree-sitter-capnp) |
| **Commit** | `7b0883c03e5edd34ef7bcf703194204299d7099f` |
| **License** | MIT |

To regenerate after upstream updates:

```sh
cargo xtask gen --name capnp
```

**Found a grammar bug?** Please report it to the [upstream repository](https://github.com/tree-sitter-grammars/tree-sitter-capnp/issues).

## Safety

This crate uses `unsafe` for FFI bindings to the tree-sitter C library. The unsafe surface is minimal and limited to what tree-sitter requires. The generated parser code is produced by tree-sitter's own code generator.

## Versioning

Crate versions track Arborium releases, not upstream grammar versions. The upstream commit is recorded above. A major version bump occurs when grammar changes affect node names or structure (breaking for query consumers).

## License

- **Generated parser code** (`parser.c`): **MIT** (from upstream grammar)
- **Arborium glue code**: **MIT OR Apache-2.0**

## Contributing

- Issues: [github.com/bearcove/arborium/issues](https://github.com/bearcove/arborium/issues)
- Repository: [github.com/bearcove/arborium](https://github.com/bearcove/arborium)