Skip to content

Commit c262f29

Browse files
authored
Fix and document debug artifacts (#64)
1 parent 8fe88f5 commit c262f29

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,7 @@ pub struct CommaSeparatedExprs {
235235

236236
### `Box<T>`
237237
Boxes are automatically constructed around the inner type when parsing, but Rust Sitter doesn't do anything extra beyond that.
238+
239+
## Debugging
240+
241+
To view the generated grammar, you can set the `RUST_SITTER_EMIT_ARTIFACTS` environment variable to `true`. This will cause the generated grammar to be written to wherever cargo sets `OUT_DIR` (usually `target/debug/build/<crate>-<hash>/out`).

tool/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ pub fn build_parsers(root_file: &Path) {
5959

6060
let dir = if emit_artifacts {
6161
let grammar_dir = Path::new(out_dir.as_str()).join(format!("grammar_{grammar_name}",));
62-
std::fs::remove_dir_all(&grammar_dir).expect("Couldn't clear old artifacts");
62+
if grammar_dir.is_dir() {
63+
std::fs::remove_dir_all(&grammar_dir).expect("Couldn't clear old artifacts");
64+
}
6365
std::fs::DirBuilder::new()
6466
.recursive(true)
6567
.create(grammar_dir.clone())

0 commit comments

Comments
 (0)