@@ -13,48 +13,23 @@ use thiserror::Error;
1313use tokio:: task:: JoinHandle ;
1414use tokio_util:: sync:: CancellationToken ;
1515
16- use crate :: parser:: AssignmentOp ;
17- use crate :: parser:: BinaryOp ;
18- use crate :: parser:: Condition ;
19- use crate :: parser:: ConditionInner ;
20- use crate :: parser:: ElsePart ;
21- use crate :: parser:: IoFile ;
22- use crate :: parser:: PostArithmeticOp ;
23- use crate :: parser:: PreArithmeticOp ;
24- use crate :: parser:: RedirectOpInput ;
25- use crate :: parser:: RedirectOpOutput ;
26- use crate :: parser:: UnaryOp ;
27- use crate :: shell:: commands:: ShellCommand ;
28- use crate :: shell:: commands:: ShellCommandContext ;
29- use crate :: shell:: types:: pipe;
30- use crate :: shell:: types:: ArithmeticResult ;
31- use crate :: shell:: types:: ArithmeticValue ;
32- use crate :: shell:: types:: EnvChange ;
33- use crate :: shell:: types:: ExecuteResult ;
34- use crate :: shell:: types:: FutureExecuteResult ;
35- use crate :: shell:: types:: ShellPipeReader ;
36- use crate :: shell:: types:: ShellPipeWriter ;
37- use crate :: shell:: types:: ShellState ;
38-
39- use crate :: parser:: Arithmetic ;
40- use crate :: parser:: ArithmeticPart ;
41- use crate :: parser:: BinaryArithmeticOp ;
42- use crate :: parser:: Command ;
43- use crate :: parser:: CommandInner ;
44- use crate :: parser:: IfClause ;
45- use crate :: parser:: PipeSequence ;
46- use crate :: parser:: PipeSequenceOperator ;
47- use crate :: parser:: Pipeline ;
48- use crate :: parser:: PipelineInner ;
49- use crate :: parser:: Redirect ;
50- use crate :: parser:: RedirectFd ;
51- use crate :: parser:: RedirectOp ;
52- use crate :: parser:: Sequence ;
53- use crate :: parser:: SequentialList ;
54- use crate :: parser:: SimpleCommand ;
55- use crate :: parser:: Word ;
56- use crate :: parser:: WordPart ;
57- use crate :: shell:: types:: WordEvalResult ;
16+ use crate :: parser:: {
17+ AssignmentOp , BinaryOp , Condition , ConditionInner , ElsePart , IoFile ,
18+ RedirectOpInput , RedirectOpOutput , UnaryArithmeticOp , UnaryOp ,
19+ } ;
20+ use crate :: shell:: commands:: { ShellCommand , ShellCommandContext } ;
21+ use crate :: shell:: types:: {
22+ pipe, ArithmeticResult , ArithmeticValue , EnvChange , ExecuteResult ,
23+ FutureExecuteResult , ShellPipeReader , ShellPipeWriter , ShellState ,
24+ WordEvalResult ,
25+ } ;
26+
27+ use crate :: parser:: {
28+ Arithmetic , ArithmeticPart , BinaryArithmeticOp , Command , CommandInner ,
29+ IfClause , PipeSequence , PipeSequenceOperator , Pipeline , PipelineInner ,
30+ Redirect , RedirectFd , RedirectOp , Sequence , SequentialList , SimpleCommand ,
31+ Word , WordPart ,
32+ } ;
5833
5934use super :: command:: execute_unresolved_command_name;
6035use super :: command:: UnresolvedCommandName ;
@@ -643,13 +618,17 @@ async fn evaluate_arithmetic_part(
643618 let rhs = Box :: pin ( evaluate_arithmetic_part ( right, state) ) . await ?;
644619 apply_conditional_binary_op ( lhs, operator, rhs)
645620 }
646- ArithmeticPart :: PostArithmeticExpr { operand, operator } => {
621+ // ArithmeticPart::PostArithmeticExpr { operand, operator } => {
622+ // let val = Box::pin(evaluate_arithmetic_part(operand, state)).await?;
623+ // apply_post_op(state, *operator, val, operand)
624+ // }
625+ // ArithmeticPart::PreArithmeticExpr { operator, operand } => {
626+ // let val = Box::pin(evaluate_arithmetic_part(operand, state)).await?;
627+ // apply_pre_op(state, *operator, val, operand)
628+ // }
629+ ArithmeticPart :: UnaryAritheticExpr { operator, operand } => {
647630 let val = Box :: pin ( evaluate_arithmetic_part ( operand, state) ) . await ?;
648- apply_post_op ( state, * operator, val, operand)
649- }
650- ArithmeticPart :: PreArithmeticExpr { operator, operand } => {
651- let val = Box :: pin ( evaluate_arithmetic_part ( operand, state) ) . await ?;
652- apply_pre_op ( state, * operator, val, operand)
631+ apply_unary_op ( state, * operator, val, operand)
653632 }
654633 ArithmeticPart :: Variable ( name) => state
655634 . get_var ( name)
@@ -732,51 +711,16 @@ fn apply_conditional_binary_op(
732711 }
733712}
734713
735- fn apply_pre_op (
736- state : & mut ShellState ,
737- op : PreArithmeticOp ,
738- val : ArithmeticResult ,
739- operand : & ArithmeticPart ,
740- ) -> Result < ArithmeticResult , Error > {
741- match op {
742- PreArithmeticOp :: Increment => {
743- let result = val. pre_increment ( operand) ?;
744- let result_clone = result. clone ( ) ;
745- state. apply_changes ( & result_clone. changes ) ;
746- Ok ( result)
747- }
748- PreArithmeticOp :: Decrement => {
749- let result = val. pre_decreament ( operand) ?;
750- let result_clone = result. clone ( ) ;
751- state. apply_changes ( & result_clone. changes ) ;
752- Ok ( result)
753- }
754- _ => {
755- todo ! ( "Pre arithmetic operator {:?} is not implemented" , op)
756- }
757- }
758- }
759-
760- fn apply_post_op (
714+ fn apply_unary_op (
761715 state : & mut ShellState ,
762- op : PostArithmeticOp ,
716+ op : UnaryArithmeticOp ,
763717 val : ArithmeticResult ,
764718 operand : & ArithmeticPart ,
765719) -> Result < ArithmeticResult , Error > {
766- match op {
767- PostArithmeticOp :: Increment => {
768- let result = val. post_increment ( operand) ?;
769- let result_clone = result. clone ( ) ;
770- state. apply_changes ( & result_clone. changes ) ;
771- Ok ( result)
772- }
773- PostArithmeticOp :: Decrement => {
774- let result = val. post_decreament ( operand) ?;
775- let result_clone = result. clone ( ) ;
776- state. apply_changes ( & result_clone. changes ) ;
777- Ok ( result)
778- }
779- }
720+ let result = val. unary_op ( operand, op) ?;
721+ let result_clone = result. clone ( ) ;
722+ state. apply_changes ( & result_clone. changes ) ;
723+ Ok ( result)
780724}
781725
782726async fn execute_pipe_sequence (
0 commit comments