@@ -74,7 +74,7 @@ impl Forth {
74
74
}
75
75
76
76
fn eval_digits ( & mut self , mut input : & str ) -> String {
77
- while let ( Some ( head) , tail) = Self :: parse_digit ( & input. clone ( ) ) {
77
+ while let ( Some ( head) , tail) = Self :: parse_digit ( & input) {
78
78
self . stack . push ( head) ;
79
79
input = tail;
80
80
}
@@ -204,24 +204,16 @@ impl Forth {
204
204
}
205
205
206
206
fn parse_word_delcaration ( input : & str ) -> Result < ( Option < Command > , String ) , Error > {
207
- if input. is_empty ( ) || input . chars ( ) . nth ( 0 ) . unwrap ( ) != ':' {
207
+ if ! input. starts_with ( ':' ) {
208
208
return Ok ( ( None , "" . to_string ( ) ) ) ;
209
209
}
210
210
let body = input
211
211
. chars ( )
212
212
. skip ( 1 )
213
213
. take_while ( |& chr| chr != ';' )
214
214
. collect :: < String > ( )
215
- . trim ( )
215
+ . trim_left ( )
216
216
. to_string ( ) ;
217
- let rest = input
218
- . chars ( )
219
- . skip_while ( |& chr| chr != ';' )
220
- . skip ( 1 )
221
- . collect :: < String > ( )
222
- . trim ( )
223
- . to_string ( ) ;
224
-
225
217
let key: String = body. chars ( ) . take_while ( |& chr| chr != ' ' ) . collect ( ) ;
226
218
let value: String = body. chars ( ) . skip_while ( |& chr| chr != ' ' ) . skip ( 1 ) . collect ( ) ;
227
219
@@ -237,7 +229,16 @@ impl Forth {
237
229
None => return Err ( Error :: InvalidWord ) ,
238
230
}
239
231
240
- Ok ( ( Some ( Word ( ( key. to_lowercase ( ) , value) ) ) , rest) )
232
+ let rest: String = input
233
+ . chars ( )
234
+ . skip_while ( |& chr| chr != ';' )
235
+ . skip ( 1 )
236
+ . collect ( ) ;
237
+
238
+ Ok ( (
239
+ Some ( Word ( ( key. to_lowercase ( ) , value) ) ) ,
240
+ rest. trim_left ( ) . to_string ( ) ,
241
+ ) )
241
242
}
242
243
243
244
fn parse_word < ' a > ( & self , input : & ' a str ) -> ( Option < String > , & ' a str ) {
0 commit comments