Skip to content

Commit f93fb92

Browse files
authored
feat: Add lang list and lang dump commands (#320)
1 parent 39531f1 commit f93fb92

File tree

16 files changed

+824
-63
lines changed

16 files changed

+824
-63
lines changed

AGENTS.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,16 @@ docs/
172172

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

175-
| Command | Purpose |
176-
| ------- | ------------------------------- |
177-
| `ast` | Show AST of query and/or source |
178-
| `check` | Validate query |
179-
| `dump` | Show compiled bytecode |
180-
| `infer` | Generate TypeScript types |
181-
| `exec` | Execute query, output JSON |
182-
| `trace` | Trace execution for debugging |
183-
| `langs` | List supported languages |
175+
| Command | Purpose |
176+
| ----------- | ------------------------------- |
177+
| `ast` | Show AST of query and/or source |
178+
| `check` | Validate query |
179+
| `dump` | Show compiled bytecode |
180+
| `infer` | Generate TypeScript types |
181+
| `exec` | Execute query, output JSON |
182+
| `trace` | Trace execution for debugging |
183+
| `lang list` | List supported languages |
184+
| `lang dump` | Dump grammar for a language |
184185

185186
## ast
186187

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

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

268-
## langs
269+
## lang
269270

270-
List supported tree-sitter languages.
271+
Language information and grammar tools.
271272

272273
```sh
273-
cargo run -p plotnik -- langs
274+
cargo run -p plotnik -- lang list # List languages with aliases
275+
cargo run -p plotnik -- lang dump json # Dump JSON grammar
276+
cargo run -p plotnik -- lang dump typescript # Dump TypeScript grammar
274277
```
275278

276279
# Coding Rules

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/plotnik-cli/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,7 @@ plotnik-lib = { version = "0.2", path = "../plotnik-lib" }
240240
arborium-tree-sitter = "2.5.0"
241241
serde = { version = "1.0", features = ["derive"] }
242242
serde_json = "1.0"
243-
thiserror = "2.0"
243+
thiserror = "2.0"
244+
245+
[dev-dependencies]
246+
insta = "=1.46.0"

crates/plotnik-cli/src/cli/commands.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn build_cli() -> Command {
5353
.subcommand(infer_command())
5454
.subcommand(exec_command())
5555
.subcommand(trace_command())
56-
.subcommand(langs_command())
56+
.subcommand(lang_command())
5757
}
5858

5959
/// Show AST of query and/or source file.
@@ -260,7 +260,29 @@ pub fn trace_command() -> Command {
260260
)
261261
}
262262

263+
/// Language information commands.
264+
pub fn lang_command() -> Command {
265+
Command::new("lang")
266+
.about("Language information and grammar dump")
267+
.subcommand_required(true)
268+
.arg_required_else_help(true)
269+
.subcommand(lang_list_command())
270+
.subcommand(lang_dump_command())
271+
}
272+
263273
/// List supported languages.
264-
pub fn langs_command() -> Command {
265-
Command::new("langs").about("List supported languages")
274+
fn lang_list_command() -> Command {
275+
Command::new("list").about("List supported languages with aliases")
276+
}
277+
278+
/// Dump grammar for a language.
279+
fn lang_dump_command() -> Command {
280+
Command::new("dump")
281+
.about("Dump grammar in Plotnik-like syntax")
282+
.arg(
283+
clap::Arg::new("lang")
284+
.help("Language name or alias")
285+
.required(true)
286+
.index(1),
287+
)
266288
}

crates/plotnik-cli/src/cli/dispatch.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,26 @@ impl From<TraceParams> for TraceArgs {
310310
}
311311
}
312312

313-
pub struct LangsParams;
313+
pub struct LangListParams;
314314

315-
impl LangsParams {
315+
impl LangListParams {
316316
pub fn from_matches(_m: &ArgMatches) -> Self {
317317
Self
318318
}
319319
}
320320

321+
pub struct LangDumpParams {
322+
pub lang: String,
323+
}
324+
325+
impl LangDumpParams {
326+
pub fn from_matches(m: &ArgMatches) -> Self {
327+
Self {
328+
lang: m.get_one::<String>("lang").cloned().unwrap(),
329+
}
330+
}
331+
}
332+
321333
/// Parse --color flag into ColorChoice.
322334
fn parse_color(m: &ArgMatches) -> ColorChoice {
323335
match m.get_one::<String>("color").map(|s| s.as_str()) {

crates/plotnik-cli/src/cli/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ mod dispatch_tests;
77

88
pub use commands::build_cli;
99
pub use dispatch::{
10-
AstParams, CheckParams, DumpParams, ExecParams, InferParams, LangsParams, TraceParams,
10+
AstParams, CheckParams, DumpParams, ExecParams, InferParams, LangDumpParams, LangListParams,
11+
TraceParams,
1112
};
1213

1314
/// Color output mode for CLI commands.

0 commit comments

Comments
 (0)