Move syntax tree CLI flag to a command
This commit is contained in:
parent
3e1765e810
commit
c736e3be8f
22
src/main.rs
22
src/main.rs
@ -29,10 +29,6 @@ struct Args {
|
|||||||
#[arg(short = 'p', long)]
|
#[arg(short = 'p', long)]
|
||||||
input_path: Option<String>,
|
input_path: Option<String>,
|
||||||
|
|
||||||
/// Show the syntax tree.
|
|
||||||
#[arg(short = 't', long = "tree")]
|
|
||||||
show_syntax_tree: bool,
|
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
cli_command: Option<CliCommand>,
|
cli_command: Option<CliCommand>,
|
||||||
|
|
||||||
@ -42,7 +38,11 @@ struct Args {
|
|||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
|
/// Output a formatted version of the input.
|
||||||
Format,
|
Format,
|
||||||
|
|
||||||
|
/// Output a concrete syntax tree of the input.
|
||||||
|
Syntax,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -80,14 +80,22 @@ fn main() {
|
|||||||
|
|
||||||
let mut interpreter = Interpreter::new(context);
|
let mut interpreter = Interpreter::new(context);
|
||||||
|
|
||||||
if args.show_syntax_tree {
|
if let Some(CliCommand::Syntax) = args.cli_command {
|
||||||
interpreter.parse(&source).unwrap();
|
interpreter.parse(&source).unwrap();
|
||||||
|
|
||||||
println!("{}", interpreter.syntax_tree().unwrap());
|
println!("{}", interpreter.syntax_tree().unwrap());
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let eval_result = interpreter.run(&source);
|
let eval_result = interpreter.run(&source);
|
||||||
|
|
||||||
|
if let Some(CliCommand::Format) = args.cli_command {
|
||||||
|
println!("{}", interpreter.format());
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
match eval_result {
|
match eval_result {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
if !value.is_none() {
|
if !value.is_none() {
|
||||||
@ -96,10 +104,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
Err(error) => eprintln!("{error}"),
|
Err(error) => eprintln!("{error}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(CliCommand::Format) = args.cli_command {
|
|
||||||
println!("{}", interpreter.format());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Helper, Completer, Validator)]
|
#[derive(Helper, Completer, Validator)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user