@@ -13,81 +13,65 @@ use crate::elements::pipeline::Pipeline;
13
13
use crate :: elements:: job:: Job ;
14
14
15
15
impl SimpleCommand {
16
- pub fn eat_substitution (
17
- feeder : & mut Feeder ,
18
- ans : & mut Self ,
19
- core : & mut ShellCore ,
20
- ) -> Result < bool , ParseError > {
21
- match Substitution :: parse ( feeder, core, false ) {
22
- Ok ( Some ( s) ) => {
23
- ans. text += & s. text ;
24
- ans. substitutions . push ( s) ;
16
+ pub fn eat_substitution ( & mut self , feeder : & mut Feeder , core : & mut ShellCore )
17
+ -> Result < bool , ParseError > {
18
+ match Substitution :: parse ( feeder, core, false ) ? {
19
+ Some ( s) => {
20
+ self . text += & s. text ;
21
+ self . substitutions . push ( s) ;
25
22
Ok ( true )
26
23
}
27
- Ok ( None ) => Ok ( false ) ,
28
- Err ( e) => {
29
- feeder. rewind ( ) ;
30
- Err ( e)
31
- }
24
+ None => Ok ( false ) ,
32
25
}
33
26
}
34
27
35
- pub fn eat_substitution_as_arg (
36
- feeder : & mut Feeder ,
37
- ans : & mut Self ,
38
- core : & mut ShellCore ,
39
- ) -> Result < bool , ParseError > {
28
+ pub fn eat_substitution_as_arg ( & mut self , feeder : & mut Feeder , core : & mut ShellCore )
29
+ -> Result < bool , ParseError > {
40
30
if let Some ( s) = Substitution :: parse_as_arg ( feeder, core) ? {
41
- ans . text += & s. text ;
42
- ans . substitutions_as_args
31
+ self . text += & s. text ;
32
+ self . substitutions_as_args
43
33
. push ( SubsArgType :: Subs ( Box :: new ( s) ) ) ;
44
34
return Ok ( true ) ;
45
35
}
46
36
47
37
if let Some ( w) = Word :: parse ( feeder, core, None ) ? {
48
- ans . text += & w. text ;
49
- ans . substitutions_as_args . push ( SubsArgType :: Other ( w) ) ;
38
+ self . text += & w. text ;
39
+ self . substitutions_as_args . push ( SubsArgType :: Other ( w) ) ;
50
40
return Ok ( true ) ;
51
41
}
52
42
53
43
Ok ( false )
54
44
}
55
45
56
- fn eat_word (
57
- feeder : & mut Feeder ,
58
- ans : & mut SimpleCommand ,
59
- core : & mut ShellCore ,
60
- ) -> Result < bool , ParseError > {
46
+ fn eat_word ( & mut self , feeder : & mut Feeder , core : & mut ShellCore )
47
+ -> Result < bool , ParseError > {
61
48
let mut mode = None ;
62
- if ans . command_name == "eval" || ans . command_name == "let" {
49
+ if self . command_name == "eval" || self . command_name == "let" {
63
50
mode = Some ( WordMode :: EvalLet ) ;
64
51
}
65
52
66
- let w = match Word :: parse ( feeder, core, mode) {
67
- Ok ( Some ( w) ) => w,
68
- Err ( e) => {
69
- feeder. rewind ( ) ;
70
- return Err ( e) ;
71
- }
53
+ let w = match Word :: parse ( feeder, core, mode) ? {
54
+ Some ( w) => w,
72
55
_ => return Ok ( false ) ,
73
56
} ;
74
57
75
- if ans . words . is_empty ( ) {
76
- ans . lineno = feeder. lineno ;
58
+ if self . words . is_empty ( ) {
59
+ self . lineno = feeder. lineno ;
77
60
if utils:: reserved ( & w. text ) {
78
61
return Ok ( false ) ;
79
62
}
80
63
81
- ans . command_name = w. text . clone ( ) ;
64
+ self . command_name = w. text . clone ( ) ;
82
65
}
83
66
84
- if ( ans. words . is_empty ( ) || ans. continue_alias_check ) && alias:: set ( ans, & w, core, feeder) ?
85
- {
67
+ if ( self . words . is_empty ( )
68
+ || self . continue_alias_check )
69
+ && alias:: set ( self , & w, core, feeder) ? {
86
70
return Ok ( true ) ;
87
71
}
88
72
89
- ans . text += & w. text ;
90
- ans . words . push ( w) ;
73
+ self . text += & w. text ;
74
+ self . words . push ( w) ;
91
75
92
76
Ok ( true )
93
77
}
@@ -121,19 +105,19 @@ impl SimpleCommand {
121
105
feeder. set_backup ( ) ;
122
106
123
107
while command:: eat_redirects ( feeder, core, & mut ans. redirects , & mut ans. text ) ?
124
- || Self :: eat_substitution ( feeder, & mut ans , core) ? { }
108
+ || ans . eat_substitution ( feeder, core) ? { }
125
109
126
110
loop {
127
111
command:: eat_redirects ( feeder, core, & mut ans. redirects , & mut ans. text ) ?;
128
112
129
113
if core. subst_builtins . contains_key ( & ans. command_name ) {
130
- if Self :: eat_substitution_as_arg ( feeder, & mut ans , core) ? {
114
+ if ans . eat_substitution_as_arg ( feeder, core) ? {
131
115
continue ;
132
116
}
133
117
}
134
118
135
119
command:: eat_blank_with_comment ( feeder, core, & mut ans. text ) ;
136
- if ! Self :: eat_word ( feeder, & mut ans , core) ? {
120
+ if ! ans . eat_word ( feeder, core) ? {
137
121
break ;
138
122
}
139
123
}
0 commit comments