Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ docs/

# CLI Reference

Run: `cargo run -p plotnik-cli -- <command>`
Run: `cargo run -p plotnik -- <command>`

| Command | Purpose |
| ------- | ----------------------------- |
Expand All @@ -185,40 +185,40 @@ Run: `cargo run -p plotnik-cli -- <command>`
Show AST of query and/or source file.

```sh
cargo run -p plotnik-cli -- ast query.ptk # query AST
cargo run -p plotnik-cli -- ast app.ts # source AST (tree-sitter)
cargo run -p plotnik-cli -- ast query.ptk app.ts # both ASTs
cargo run -p plotnik-cli -- ast query.ptk app.ts --raw # CST / include anonymous nodes
cargo run -p plotnik -- ast query.ptk # query AST
cargo run -p plotnik -- ast app.ts # source AST (tree-sitter)
cargo run -p plotnik -- ast query.ptk app.ts # both ASTs
cargo run -p plotnik -- ast query.ptk app.ts --raw # CST / include anonymous nodes
```

## check

Validate a query (silent on success, like `cargo check`).

```sh
cargo run -p plotnik-cli -- check query.ptk -l typescript
cargo run -p plotnik-cli -- check queries.ts/ # workspace with lang inference
cargo run -p plotnik-cli -- check -q '(identifier) @id' -l javascript
cargo run -p plotnik -- check query.ptk -l typescript
cargo run -p plotnik -- check queries.ts/ # workspace with lang inference
cargo run -p plotnik -- check -q '(identifier) @id' -l javascript
```

## dump

Show compiled bytecode.

```sh
cargo run -p plotnik-cli -- dump query.ptk # unlinked
cargo run -p plotnik-cli -- dump query.ptk -l typescript # linked
cargo run -p plotnik-cli -- dump -q '(identifier) @id'
cargo run -p plotnik -- dump query.ptk # unlinked
cargo run -p plotnik -- dump query.ptk -l typescript # linked
cargo run -p plotnik -- dump -q '(identifier) @id'
```

## infer

Generate TypeScript type definitions from a query.

```sh
cargo run -p plotnik-cli -- infer query.ptk -l javascript
cargo run -p plotnik-cli -- infer queries.ts/ -o types.d.ts
cargo run -p plotnik-cli -- infer -q '(identifier) @id' -l typescript
cargo run -p plotnik -- infer query.ptk -l javascript
cargo run -p plotnik -- infer queries.ts/ -o types.d.ts
cargo run -p plotnik -- infer -q '(identifier) @id' -l typescript
```

Options: `--verbose-nodes`, `--no-node-type`, `--no-export`, `-o <FILE>`
Expand All @@ -236,9 +236,9 @@ exec -q <TEXT> -s <TEXT> -l <LANG> # all inline
```

```sh
cargo run -p plotnik-cli -- exec query.ptk app.ts
cargo run -p plotnik-cli -- exec -q 'Q = (identifier) @id' app.ts
cargo run -p plotnik-cli -- exec -q 'Q = (identifier) @id' -s 'let x' -l javascript
cargo run -p plotnik -- exec query.ptk app.ts
cargo run -p plotnik -- exec -q 'Q = (identifier) @id' app.ts
cargo run -p plotnik -- exec -q 'Q = (identifier) @id' -s 'let x' -l javascript
```

Options: `--compact`, `--verbose-nodes`, `--check`, `--entry <NAME>`
Expand All @@ -256,9 +256,9 @@ trace -q <TEXT> -s <TEXT> -l <LANG> # all inline
```

```sh
cargo run -p plotnik-cli -- trace query.ptk app.ts
cargo run -p plotnik-cli -- trace -q 'Q = (identifier) @id' app.ts
cargo run -p plotnik-cli -- trace query.ptk app.ts --no-result -vv
cargo run -p plotnik -- trace query.ptk app.ts
cargo run -p plotnik -- trace -q 'Q = (identifier) @id' app.ts
cargo run -p plotnik -- trace query.ptk app.ts --no-result -vv
```

Options: `-v` (verbose), `-vv` (very verbose), `--no-result`, `--fuel <N>`
Expand All @@ -268,7 +268,7 @@ Options: `-v` (verbose), `-vv` (very verbose), `--no-result`, `--fuel <N>`
List supported tree-sitter languages.

```sh
cargo run -p plotnik-cli -- langs
cargo run -p plotnik -- langs
```

# Coding Rules
Expand Down
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ Tree-sitter gives you the syntax tree. Extracting structured data from it still
- [ ] LSP server
- [ ] Editor extensions

## Installation

```sh
cargo install plotnik
```

By default, 15 common languages are included. To add specific languages:

```sh
cargo install plotnik --features lang-ruby,lang-elixir
```

Or with all 80+ languages:

```sh
cargo install plotnik --features all-languages
```

## Example

Extract function signatures from Rust. `Type` references itself to handle nested generics like `Option<Vec<String>>`.
Expand Down Expand Up @@ -81,7 +99,7 @@ fn set(key: String, val: i32) {}
Plotnik infers TypeScript types from the query structure. `Type` is recursive: `args: Type[]`.

```sh
❯ plotnik infer query.ptk -l rust
❯ plotnik infer query.ptk --lang rust
export type Type =
| { $tag: "Simple"; $data: { name: string } }
| { $tag: "Generic"; $data: { name: string; args: Type[] } };
Expand Down
12 changes: 6 additions & 6 deletions crates/plotnik-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "plotnik-cli"
version = "0.1.1"
name = "plotnik"
version = "0.2.0"
edition = "2024"
license = "Apache-2.0"
description = "CLI for plotnik - typed query language for tree-sitter AST"
repository = "https://github.com/plotnik-lang/plotnik"
documentation = "https://docs.rs/plotnik-cli"
documentation = "https://docs.rs/plotnik"
keywords = ["tree-sitter", "query", "ast", "parser", "cli"]
categories = ["command-line-utilities", "development-tools"]
readme = "../../README.md"
Expand Down Expand Up @@ -234,9 +234,9 @@ lang-zsh = ["plotnik-langs/lang-zsh"]

[dependencies]
clap = { version = "4.5", features = ["derive"] }
plotnik-core = { version = "0.1.0", path = "../plotnik-core" }
plotnik-langs = { version = "0.1.0", path = "../plotnik-langs", default-features = false }
plotnik-lib = { version = "0.1.0", path = "../plotnik-lib" }
plotnik-core = { version = "0.2", path = "../plotnik-core" }
plotnik-langs = { version = "0.2", path = "../plotnik-langs", default-features = false }
plotnik-lib = { version = "0.2", path = "../plotnik-lib" }
arborium-tree-sitter = "2.5.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/plotnik-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plotnik-core"
version = "0.1.1"
version = "0.2.0"
edition = "2024"
license = "Apache-2.0"
description = "Core data structures for Plotnik"
Expand Down
6 changes: 3 additions & 3 deletions crates/plotnik-langs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plotnik-langs"
version = "0.1.1"
version = "0.2.0"
edition = "2024"
license = "Apache-2.0"
description = "Tree-sitter language bindings for Plotnik query language"
Expand Down Expand Up @@ -233,8 +233,8 @@ lang-zsh = ["dep:arborium-zsh", "plotnik-macros/lang-zsh"]

[dependencies]
paste = "1.0"
plotnik-core = { version = "0.1.0", path = "../plotnik-core" }
plotnik-macros = { version = "0.1.0", path = "../plotnik-macros" }
plotnik-core = { version = "0.2", path = "../plotnik-core" }
plotnik-macros = { version = "0.2", path = "../plotnik-macros" }
arborium-tree-sitter = "2.5.0"
arborium-ada = { version = "2.5.0", optional = true }
arborium-agda = { version = "2.5.0", optional = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/plotnik-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plotnik-lib"
version = "0.1.1"
version = "0.2.0"
edition = "2024"
license = "Apache-2.0"
description = "Typed query language for tree-sitter AST"
Expand All @@ -23,8 +23,8 @@ thiserror = "2.0.17"
arborium-tree-sitter = "2.5.0"
crc32fast = "1.4"
memmap2 = "0.9"
plotnik-core = { version = "0.1", path = "../plotnik-core" }
plotnik-langs = { version = "0.1", path = "../plotnik-langs", optional = true }
plotnik-core = { version = "0.2", path = "../plotnik-core" }
plotnik-langs = { version = "0.2", path = "../plotnik-langs", optional = true }

[features]
default = ["plotnik-langs"]
Expand Down
4 changes: 2 additions & 2 deletions crates/plotnik-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plotnik-macros"
version = "0.1.1"
version = "0.2.0"
edition = "2024"
license = "Apache-2.0"
description = "Procedural macros for Plotnik"
Expand Down Expand Up @@ -114,7 +114,7 @@ lang-zsh = ["dep:arborium-zsh"]
proc-macro2 = "1"
quote = "1"
syn = "2"
plotnik-core = { version = "0.1.0", path = "../plotnik-core" }
plotnik-core = { version = "0.2", path = "../plotnik-core" }
serde_json = "1"
arborium-tree-sitter = "2.5.0"
arborium-ada = { version = "2.5.0", optional = true }
Expand Down