cli: Create src directory before writing grammar.json

Fixes #278
This commit is contained in:
Max Brunsfeld 2019-02-14 10:57:33 -08:00
parent b08f8dc855
commit 5debf3cbcc

View file

@ -34,6 +34,10 @@ pub fn generate_parser_in_directory(
state_ids_to_log: Vec<usize>,
) -> Result<()> {
let repo_src_path = repo_path.join("src");
let repo_header_path = repo_src_path.join("tree_sitter");
fs::create_dir_all(&repo_src_path)?;
fs::create_dir_all(&repo_header_path)?;
let grammar_json;
match grammar_path {
@ -49,9 +53,6 @@ pub fn generate_parser_in_directory(
let (language_name, c_code) =
generate_parser_for_grammar_with_opts(&grammar_json, minimize, state_ids_to_log)?;
let repo_header_path = repo_src_path.join("tree_sitter");
fs::create_dir_all(&repo_src_path)?;
fs::create_dir_all(&repo_header_path)?;
fs::write(&repo_src_path.join("parser.c"), c_code)
.map_err(|e| format!("Failed to write parser.c: {}", e))?;
fs::write(