@@ -307,6 +307,17 @@ pub fn try_read_bool(input: &str) -> IResult<&str, Value> {
307
307
Ok ( ( rest_input, Value :: Boolean ( bool. parse ( ) . unwrap ( ) ) ) )
308
308
}
309
309
310
+ // Tries to parse &str into Value::Nil
311
+ /// Expects:
312
+ /// nil
313
+ /// Example success:
314
+ /// nil => Value::Nil
315
+ pub fn try_read_nil ( input : & str ) -> IResult < & str , Value > {
316
+ named ! ( nil_parser<& str , & str >, tag!( "nil" ) ) ;
317
+ let ( rest_input, nil) = nil_parser ( input) ?;
318
+ Ok ( ( rest_input, Value :: Nil ) )
319
+ }
320
+
310
321
/// Tries to parse &str into Value::double
311
322
///
312
323
pub fn try_read_f64 ( input : & str ) -> IResult < & str , Value > {
@@ -459,6 +470,7 @@ pub fn try_read(input: &str) -> IResult<&str, Value> {
459
470
try_read_f64,
460
471
try_read_i32,
461
472
try_read_bool,
473
+ try_read_nil,
462
474
try_read_symbol,
463
475
try_read_keyword,
464
476
try_read_list,
@@ -674,6 +686,16 @@ mod tests {
674
686
}
675
687
}
676
688
689
+ mod try_read_nil_tests {
690
+ use crate :: reader:: try_read_nil;
691
+ use crate :: value:: Value ;
692
+
693
+ #[ test]
694
+ fn try_read_nil_test ( ) {
695
+ assert_eq ! ( Value :: Nil , try_read_nil( "nil " ) . ok( ) . unwrap( ) . 1 ) ;
696
+ }
697
+ }
698
+
677
699
mod try_read_symbol_tests {
678
700
use crate :: reader:: try_read_symbol;
679
701
use crate :: symbol:: Symbol ;
0 commit comments