Skip to content

Commit

Permalink
Change return type
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 17, 2025
1 parent 6d54e86 commit 5c32e98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/elements/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod r#while;
pub mod r#if;

use crate::{proc_ctrl, ShellCore, Feeder, Script};
use crate::error::parse::ParseError;
use crate::utils::exit;
use self::arithmetic::ArithmeticCommand;
use self::case::CaseCommand;
Expand Down Expand Up @@ -132,16 +133,16 @@ pub fn eat_redirects(feeder: &mut Feeder, core: &mut ShellCore,
}
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Option<Box<dyn Command>> {
if let Some(a) = FunctionDefinition::parse(feeder, core) { Some(Box::new(a)) }
else if let Ok(Some(a)) = SimpleCommand::parse(feeder, core){ Some(Box::new(a)) }
else if let Some(a) = IfCommand::parse(feeder, core) { Some(Box::new(a)) }
else if let Some(a) = ArithmeticCommand::parse(feeder, core) { Some(Box::new(a)) }
else if let Some(a) = ParenCommand::parse(feeder, core, false) { Some(Box::new(a)) }
else if let Some(a) = BraceCommand::parse(feeder, core) { Some(Box::new(a)) }
else if let Some(a) = ForCommand::parse(feeder, core) { Some(Box::new(a)) }
else if let Some(a) = WhileCommand::parse(feeder, core) { Some(Box::new(a)) }
else if let Some(a) = CaseCommand::parse(feeder, core) { Some(Box::new(a)) }
else if let Some(a) = TestCommand::parse(feeder, core) { Some(Box::new(a)) }
else{ None }
pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Result<Option<Box<dyn Command>>, ParseError> {
if let Some(a) = FunctionDefinition::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = SimpleCommand::parse(feeder, core)? { Ok(Some(Box::new(a))) }
else if let Some(a) = IfCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = ArithmeticCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = ParenCommand::parse(feeder, core, false) { Ok(Some(Box::new(a))) }
else if let Some(a) = BraceCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = ForCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = WhileCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = CaseCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else if let Some(a) = TestCommand::parse(feeder, core) { Ok(Some(Box::new(a))) }
else{ Ok(None) }
}
2 changes: 1 addition & 1 deletion src/elements/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Pipeline {
}

fn eat_command(feeder: &mut Feeder, ans: &mut Pipeline, core: &mut ShellCore) -> bool {
if let Some(command) = command::parse(feeder, core){
if let Ok(Some(command)) = command::parse(feeder, core){
ans.text += &command.get_text();
ans.commands.push(command);

Expand Down

0 comments on commit 5c32e98

Please sign in to comment.