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
27 changes: 15 additions & 12 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,16 @@ docs/

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

| Command | Purpose |
| ------- | ------------------------------- |
| `ast` | Show AST of query and/or source |
| `check` | Validate query |
| `dump` | Show compiled bytecode |
| `infer` | Generate TypeScript types |
| `exec` | Execute query, output JSON |
| `trace` | Trace execution for debugging |
| `langs` | List supported languages |
| Command | Purpose |
| ----------- | ------------------------------- |
| `ast` | Show AST of query and/or source |
| `check` | Validate query |
| `dump` | Show compiled bytecode |
| `infer` | Generate TypeScript types |
| `exec` | Execute query, output JSON |
| `trace` | Trace execution for debugging |
| `lang list` | List supported languages |
| `lang dump` | Dump grammar for a language |

## ast

Expand Down Expand Up @@ -265,12 +266,14 @@ cargo run -p plotnik -- trace query.ptk app.ts --no-result -vv

Options: `-v` (verbose), `-vv` (very verbose), `--no-result`, `--fuel <N>`

## langs
## lang

List supported tree-sitter languages.
Language information and grammar tools.

```sh
cargo run -p plotnik -- langs
cargo run -p plotnik -- lang list # List languages with aliases
cargo run -p plotnik -- lang dump json # Dump JSON grammar
cargo run -p plotnik -- lang dump typescript # Dump TypeScript grammar
```

# Coding Rules
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion crates/plotnik-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,7 @@ plotnik-lib = { version = "0.2", path = "../plotnik-lib" }
arborium-tree-sitter = "2.5.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "2.0"
thiserror = "2.0"

[dev-dependencies]
insta = "=1.46.0"
28 changes: 25 additions & 3 deletions crates/plotnik-cli/src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn build_cli() -> Command {
.subcommand(infer_command())
.subcommand(exec_command())
.subcommand(trace_command())
.subcommand(langs_command())
.subcommand(lang_command())
}

/// Show AST of query and/or source file.
Expand Down Expand Up @@ -260,7 +260,29 @@ pub fn trace_command() -> Command {
)
}

/// Language information commands.
pub fn lang_command() -> Command {
Command::new("lang")
.about("Language information and grammar dump")
.subcommand_required(true)
.arg_required_else_help(true)
.subcommand(lang_list_command())
.subcommand(lang_dump_command())
}

/// List supported languages.
pub fn langs_command() -> Command {
Command::new("langs").about("List supported languages")
fn lang_list_command() -> Command {
Command::new("list").about("List supported languages with aliases")
}

/// Dump grammar for a language.
fn lang_dump_command() -> Command {
Command::new("dump")
.about("Dump grammar in Plotnik-like syntax")
.arg(
clap::Arg::new("lang")
.help("Language name or alias")
.required(true)
.index(1),
)
}
16 changes: 14 additions & 2 deletions crates/plotnik-cli/src/cli/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,26 @@ impl From<TraceParams> for TraceArgs {
}
}

pub struct LangsParams;
pub struct LangListParams;

impl LangsParams {
impl LangListParams {
pub fn from_matches(_m: &ArgMatches) -> Self {
Self
}
}

pub struct LangDumpParams {
pub lang: String,
}

impl LangDumpParams {
pub fn from_matches(m: &ArgMatches) -> Self {
Self {
lang: m.get_one::<String>("lang").cloned().unwrap(),
}
}
}

/// Parse --color flag into ColorChoice.
fn parse_color(m: &ArgMatches) -> ColorChoice {
match m.get_one::<String>("color").map(|s| s.as_str()) {
Expand Down
3 changes: 2 additions & 1 deletion crates/plotnik-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ mod dispatch_tests;

pub use commands::build_cli;
pub use dispatch::{
AstParams, CheckParams, DumpParams, ExecParams, InferParams, LangsParams, TraceParams,
AstParams, CheckParams, DumpParams, ExecParams, InferParams, LangDumpParams, LangListParams,
TraceParams,
};

/// Color output mode for CLI commands.
Expand Down
Loading