treewide: enforce strict clippy check
This commit is contained in:
+34
-19
@@ -20,33 +20,49 @@ struct Cli {
|
||||
enum Command {
|
||||
Compile {
|
||||
#[clap(flatten)]
|
||||
source: ExprSource,
|
||||
source: ExprSourceArgs,
|
||||
#[arg(long)]
|
||||
silent: bool,
|
||||
},
|
||||
Eval {
|
||||
#[clap(flatten)]
|
||||
source: ExprSource,
|
||||
source: ExprSourceArgs,
|
||||
},
|
||||
Repl,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
#[group(required = true, multiple = false)]
|
||||
struct ExprSource {
|
||||
struct ExprSourceArgs {
|
||||
#[clap(short, long)]
|
||||
expr: Option<String>,
|
||||
#[clap(short, long)]
|
||||
file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
enum ExprSource {
|
||||
Expr(String),
|
||||
File(PathBuf),
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::unreachable,
|
||||
reason = "clap's arg group guarantees exactly one of --expr/--file is set"
|
||||
)]
|
||||
impl From<ExprSourceArgs> for ExprSource {
|
||||
fn from(args: ExprSourceArgs) -> Self {
|
||||
match (args.expr, args.file) {
|
||||
(Some(expr), None) => ExprSource::Expr(expr),
|
||||
(None, Some(file)) => ExprSource::File(file),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()> {
|
||||
let src = if let Some(expr) = src.expr {
|
||||
Source::new_eval(expr)?
|
||||
} else if let Some(file) = src.file {
|
||||
Source::new_file(file)?
|
||||
} else {
|
||||
unreachable!()
|
||||
let src = match src {
|
||||
ExprSource::Expr(expr) => Source::new_eval(expr)?,
|
||||
ExprSource::File(file) => Source::new_file(file)?,
|
||||
};
|
||||
match eval.compile_bytecode(src) {
|
||||
Ok(ip) => {
|
||||
@@ -63,12 +79,9 @@ fn run_compile(eval: &mut Evaluator, src: ExprSource, silent: bool) -> Result<()
|
||||
}
|
||||
|
||||
fn run_eval(eval: &mut Evaluator, src: ExprSource) -> Result<()> {
|
||||
let src = if let Some(expr) = src.expr {
|
||||
Source::new_eval(expr)?
|
||||
} else if let Some(file) = src.file {
|
||||
Source::new_file(file)?
|
||||
} else {
|
||||
unreachable!()
|
||||
let src = match src {
|
||||
ExprSource::Expr(expr) => Source::new_eval(expr)?,
|
||||
ExprSource::File(file) => Source::new_file(file)?,
|
||||
};
|
||||
match eval.eval_deep(src) {
|
||||
Ok(value) => {
|
||||
@@ -93,7 +106,9 @@ fn run_repl(eval: &mut Evaluator) -> Result<()> {
|
||||
if line.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
let _ = rl.add_history_entry(line.as_str());
|
||||
if let Err(err) = rl.add_history_entry(line.as_str()) {
|
||||
eprintln!("[WARN] Failed to add history entry: {err}");
|
||||
}
|
||||
if let Some([Some(_), Some(ident), Some(rest)]) = RE.exec(&line) {
|
||||
if let Some(expr) = rest.strip_prefix('=') {
|
||||
let expr = expr.trim_start();
|
||||
@@ -137,15 +152,15 @@ fn run_repl(eval: &mut Evaluator) -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
fix::logging::init_logging();
|
||||
fix::logging::init_logging()?;
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
let mut eval = Evaluator::new();
|
||||
|
||||
match cli.command {
|
||||
Command::Compile { source, silent } => run_compile(&mut eval, source, silent),
|
||||
Command::Eval { source } => run_eval(&mut eval, source),
|
||||
Command::Compile { source, silent } => run_compile(&mut eval, source.into(), silent),
|
||||
Command::Eval { source } => run_eval(&mut eval, source.into()),
|
||||
Command::Repl => run_repl(&mut eval),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user