mirror of
https://github.com/tree-sitter/tree-sitter.git
synced 2026-09-10 07:26:23 -04:00
fix(generate)!: error when nonexistent _file_ path is passed to
`generate_parser_in_directory`.
This commit is contained in:
parent
43623ec9bf
commit
cde84508ac
|
|
@ -82,6 +82,8 @@ pub enum GenerateError {
|
|||
#[cfg(feature = "load")]
|
||||
#[error(transparent)]
|
||||
LoadGrammarFile(#[from] LoadGrammarError),
|
||||
#[error("Grammar file `{0}` not found")]
|
||||
GrammarFileNotFound(PathBuf),
|
||||
#[error(transparent)]
|
||||
ParseGrammar(#[from] ParseGrammarError),
|
||||
#[error(transparent)]
|
||||
|
|
@ -347,6 +349,11 @@ where
|
|||
.try_exists()
|
||||
.map_err(|e| GenerateError::GrammarPath(e.to_string()))?
|
||||
{
|
||||
// A nonexistent path with an extension (i.e. tree-sitter-foo/grammar.json)
|
||||
// is a missing input file, not a directory to create.
|
||||
if path_buf.extension().is_some() {
|
||||
return Err(GenerateError::GrammarFileNotFound(path_buf));
|
||||
}
|
||||
fs::create_dir_all(&path_buf)
|
||||
.map_err(|e| GenerateError::IO(IoError::new(e, Some(path_buf.as_path()))))?;
|
||||
repo_path = path_buf;
|
||||
|
|
|
|||
Loading…
Reference in a new issue