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 98351a3 commit cf23506
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/elements/expr/arithmetic/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ impl ArithmeticExpr {
Ok(true)
}

fn eat_array_elem(feeder: &mut Feeder, ans: &mut Self, core: &mut ShellCore) -> bool {
fn eat_array_elem(feeder: &mut Feeder, ans: &mut Self, core: &mut ShellCore) -> Result<bool, ParseError> {
let len = feeder.scanner_name(core);
if len == 0 {
return false;
return Ok(false);
}

let name = &feeder.consume(len);
ans.text += &name.clone();

if let Some(s) = Subscript::parse(feeder, core) {
if let Some(s) = Subscript::parse(feeder, core)? {
ans.text += &s.text.clone();
Self::eat_blank(feeder, ans, core);
let suffix = Self::eat_suffix(feeder, ans);
Expand All @@ -85,7 +85,7 @@ impl ArithmeticExpr {
ans.elements.push( ArithElem::Word(Word::from(name), suffix) );
};

true
Ok(true)
}

fn eat_word(feeder: &mut Feeder, ans: &mut Self, core: &mut ShellCore) -> bool {
Expand Down Expand Up @@ -204,7 +204,7 @@ impl ArithmeticExpr {
|| Self::eat_unary_operator(feeder, &mut ans, core)
|| Self::eat_paren(feeder, core, &mut ans)?
|| Self::eat_binary_operator(feeder, &mut ans, core)
|| Self::eat_array_elem(feeder, &mut ans, core)
|| Self::eat_array_elem(feeder, &mut ans, core)?
|| Self::eat_word(feeder, &mut ans, core) {
continue;
}
Expand Down
11 changes: 6 additions & 5 deletions src/elements/subscript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::{ShellCore, Feeder};
use crate::error::exec::ExecError;
use crate::error::parse::ParseError;
use super::expr::arithmetic::ArithmeticExpr;

#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -36,9 +37,9 @@ impl Subscript {
Err(ExecError::ArrayIndexInvalid("".to_string()))
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Option<Self> {
pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Result<Option<Self>, ParseError> {
if ! feeder.starts_with("[") {
return None;
return Ok(None);
}

let mut ans = Self::default();
Expand All @@ -50,16 +51,16 @@ impl Subscript {
}else if feeder.starts_with("*") {
ans.text += "*";
ans.inner_special = feeder.consume(1);
}else if let Ok(Some(a)) = ArithmeticExpr::parse(feeder, core, true) {
}else if let Some(a) = ArithmeticExpr::parse(feeder, core, true)? {
ans.text += &a.text.clone();
ans.inner = Some(a);
}

if ! feeder.starts_with("]") {
return None;
return Ok(None);
}

ans.text += &feeder.consume(1);
Some(ans)
Ok(Some(ans))
}
}
2 changes: 1 addition & 1 deletion src/elements/substitution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Substitution {
ans.name = name.clone();
ans.text += &name;

if let Some(s) = Subscript::parse(feeder, core) {
if let Some(s) = Subscript::parse(feeder, core)? {
ans.text += &s.text.clone();
ans.index = Some(s);
};
Expand Down
10 changes: 5 additions & 5 deletions src/elements/subword/braced_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,17 @@ impl BracedParam {
Ok(())
}

fn eat_subscript(feeder: &mut Feeder, ans: &mut Self, core: &mut ShellCore) -> bool {
if let Some(s) = Subscript::parse(feeder, core) {
fn eat_subscript(feeder: &mut Feeder, ans: &mut Self, core: &mut ShellCore) -> Result<bool, ParseError> {
if let Some(s) = Subscript::parse(feeder, core)? {
ans.text += &s.text;
if s.text.contains('@') {
ans.is_array = true;
}
ans.param.subscript = Some(s);
return true;
return Ok(true);
}

false
Ok(false)
}

fn eat_subwords(feeder: &mut Feeder, ans: &mut Self, ends: Vec<&str>, core: &mut ShellCore)
Expand Down Expand Up @@ -241,7 +241,7 @@ impl BracedParam {
}

if Self::eat_param(feeder, &mut ans, core) {
Self::eat_subscript(feeder, &mut ans, core);
Self::eat_subscript(feeder, &mut ans, core)?;
let _ = ValueCheck::eat(feeder, &mut ans, core)?
|| Substr::eat(feeder, &mut ans, core)
|| Remove::eat(feeder, &mut ans, core)?
Expand Down

0 comments on commit cf23506

Please sign in to comment.