diff --git a/src/parse/execute.rs b/src/parse/execute.rs index 552a50e..0315d29 100644 --- a/src/parse/execute.rs +++ b/src/parse/execute.rs @@ -359,10 +359,12 @@ impl Dispatcher { let func_name = argv.remove(0).span.as_str().to_string(); let argv = prepare_argv(argv)?; - let result = if let Some(func) = read_logic(|l| l.get_func(&func_name)) { + let result = if let Some(ref mut func_body) = read_logic(|l| l.get_func(&func_name)) { let _guard = ScopeGuard::exclusive_scope(Some(argv)); - if let Err(e) = self.exec_brc_grp((*func).clone()) { + func_body.body_mut().flags = func.flags; + + if let Err(e) = self.exec_brc_grp(func_body.body().clone()) { match e.kind() { ShErrKind::FuncReturn(code) => { state::set_status(*code); @@ -385,7 +387,6 @@ impl Dispatcher { result } fn exec_brc_grp(&mut self, brc_grp: Node) -> ShResult<()> { - let blame = brc_grp.get_span().clone(); let NdRule::BraceGrp { body } = brc_grp.class else { unreachable!() }; @@ -411,7 +412,7 @@ impl Dispatcher { } }) } else { - brc_grp_logic(self).try_blame(blame) + brc_grp_logic(self) } } fn exec_case(&mut self, case_stmt: Node) -> ShResult<()> { diff --git a/src/state.rs b/src/state.rs index 8784a35..3059d3a 100644 --- a/src/state.rs +++ b/src/state.rs @@ -271,11 +271,9 @@ thread_local! { /// A shell function /// -/// Consists of the BraceGrp Node and the stored ParsedSrc that the node refers -/// to The Node must be stored with the ParsedSrc because the tokens of the node +/// Consists of the BraceGrp Node and the stored ParsedSrc that the node refers to. +/// The Node must be stored with the ParsedSrc because the tokens of the node /// contain an Arc Which refers to the String held in ParsedSrc -/// -/// Can be dereferenced to pull out the wrapped Node #[derive(Clone, Debug)] pub struct ShFunc(Node); @@ -294,13 +292,12 @@ impl ShFunc { let ConjunctNode { cmd, operator: _ } = conjunct_node; *cmd } -} - -impl Deref for ShFunc { - type Target = Node; - fn deref(&self) -> &Self::Target { - &self.0 - } + pub fn body(&self) -> &Node { + &self.0 + } + pub fn body_mut(&mut self) -> &mut Node { + &mut self.0 + } } /// The logic table for the shell diff --git a/src/tests/error.rs b/src/tests/error.rs index 3f98311..22aa352 100644 --- a/src/tests/error.rs +++ b/src/tests/error.rs @@ -59,12 +59,10 @@ fn unclosed_squote() { fn unclosed_brc_grp() { let input = "{ foo bar"; let tokens = LexStream::new(Arc::new(input.into()), LexFlags::empty()) - .map(|tk| tk.unwrap()) - .collect::>(); + .collect::>>(); - let node = ParseStream::new(tokens).next().unwrap(); - let Err(err) = node else { - panic!(); + let Err(err) = tokens else { + panic!("Expected an error, got {:?}", tokens); }; let err_fmt = format!("{err}");