1
0
This commit is contained in:
2024-11-01 05:16:51 +03:00
parent 552dec9401
commit f83c37287a
15 changed files with 684 additions and 207 deletions

View File

@@ -23,6 +23,10 @@ pub enum Command {
input: PathBuf,
output_tree: PathBuf,
},
Sem {
input: PathBuf,
output_tree: PathBuf,
},
}
impl Args {
@@ -55,6 +59,7 @@ fn validate_inner(args: ArgsInner) -> Result<ArgsInner, clap::Error> {
output_symbols,
} => validate_lex(input, output_tokens, output_symbols)?,
Command::Syn { input, output_tree } => validate_syn(input, output_tree)?,
Command::Sem { input, output_tree } => validate_sem(input, output_tree)?,
};
Ok(args)
@@ -106,3 +111,21 @@ fn validate_syn(input: &PathBuf, output_tree: &PathBuf) -> Result<(), clap::Erro
Ok(())
}
fn validate_sem(input: &PathBuf, output_tree: &PathBuf) -> Result<(), clap::Error> {
if !input.is_file() {
return Err(clap::Error::raw(
clap::error::ErrorKind::InvalidValue,
format!("Input file '{}' does not exist", input.display()),
));
}
if output_tree == input {
return Err(clap::Error::raw(
clap::error::ErrorKind::InvalidValue,
"Input and output files cannot be the same",
));
};
Ok(())
}