Skip to content

Commit

Permalink
Removed a level of indent
Browse files Browse the repository at this point in the history
  • Loading branch information
rben01 committed Nov 30, 2024
1 parent 3610031 commit 923d604
Showing 1 changed file with 62 additions and 60 deletions.
122 changes: 62 additions & 60 deletions numbat-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,74 +413,76 @@ impl Cli {
let readline = rl.readline(&self.config.prompt);
match readline {
Ok(line) => {
if !line.trim().is_empty() {
rl.add_history_entry(&line)?;

// if we enter here, the line looks like a command
if let Some(sourceless_parser) =
SourcelessCommandParser::new(&line, &cmd_runner)
{
let mut parser = CommandParser::new(
sourceless_parser,
self.context
.lock()
.unwrap()
.resolver_mut()
.add_code_source(CodeSource::Text, &line),
);

match parser.parse_command() {
Ok(cmd) => {
let mut context = self.context.lock().unwrap();
match cmd_runner.run(
cmd,
CommandContext {
ctx: &mut context,
editor: rl,
session_history: &session_history,
interactive,
},
) {
CommandControlFlow::Normal => {}
CommandControlFlow::Continue => continue,
CommandControlFlow::Return => return Ok(()),
}
}
Err(e) => {
self.print_diagnostic(e);
continue;
}
}

continue;
}
if line.trim().is_empty() {
continue;
}

let ParseEvaluationOutcome {
control_flow,
result,
} = self.parse_and_evaluate(
&line,
CodeSource::Text,
if interactive {
ExecutionMode::Interactive
} else {
ExecutionMode::Normal
},
self.config.pretty_print,
rl.add_history_entry(&line)?;

// if we enter here, the line looks like a command
if let Some(sourceless_parser) =
SourcelessCommandParser::new(&line, &cmd_runner)
{
let mut parser = CommandParser::new(
sourceless_parser,
self.context
.lock()
.unwrap()
.resolver_mut()
.add_code_source(CodeSource::Text, &line),
);

match control_flow {
std::ops::ControlFlow::Continue(()) => {}
std::ops::ControlFlow::Break(ExitStatus::Success) => {
return Ok(());
match parser.parse_command() {
Ok(cmd) => {
let mut context = self.context.lock().unwrap();
match cmd_runner.run(
cmd,
CommandContext {
ctx: &mut context,
editor: rl,
session_history: &session_history,
interactive,
},
) {
CommandControlFlow::Normal => {}
CommandControlFlow::Continue => continue,
CommandControlFlow::Return => return Ok(()),
}
}
std::ops::ControlFlow::Break(ExitStatus::Error) => {
bail!("Interpreter stopped due to error")
Err(e) => {
self.print_diagnostic(e);
continue;
}
}

session_history.push(CompactString::from(line), result);
continue;
}

let ParseEvaluationOutcome {
control_flow,
result,
} = self.parse_and_evaluate(
&line,
CodeSource::Text,
if interactive {
ExecutionMode::Interactive
} else {
ExecutionMode::Normal
},
self.config.pretty_print,
);

match control_flow {
std::ops::ControlFlow::Continue(()) => {}
std::ops::ControlFlow::Break(ExitStatus::Success) => {
return Ok(());
}
std::ops::ControlFlow::Break(ExitStatus::Error) => {
bail!("Interpreter stopped due to error")
}
}

session_history.push(CompactString::from(line), result);
}
Err(ReadlineError::Interrupted) => {}
Err(ReadlineError::Eof) => {
Expand Down

0 comments on commit 923d604

Please sign in to comment.