@@ -326,6 +326,17 @@ pub fn try_read_bool(input: &str) -> IResult<&str, Value> {
326
326
Ok ( ( rest_input, Value :: Boolean ( bool. parse ( ) . unwrap ( ) ) ) )
327
327
}
328
328
329
+ // Tries to parse &str into Value::Nil
330
+ /// Expects:
331
+ /// nil
332
+ /// Example success:
333
+ /// nil => Value::Nil
334
+ pub fn try_read_nil ( input : & str ) -> IResult < & str , Value > {
335
+ named ! ( nil_parser<& str , & str >, tag!( "nil" ) ) ;
336
+ let ( rest_input, nil) = nil_parser ( input) ?;
337
+ Ok ( ( rest_input, Value :: Nil ) )
338
+ }
339
+
329
340
/// Tries to parse &str into Value::double
330
341
///
331
342
pub fn try_read_f64 ( input : & str ) -> IResult < & str , Value > {
@@ -490,6 +501,7 @@ pub fn try_read(input: &str) -> IResult<&str, Value> {
490
501
try_read_f64,
491
502
try_read_i32,
492
503
try_read_bool,
504
+ try_read_nil,
493
505
try_read_symbol,
494
506
try_read_keyword,
495
507
try_read_list,
@@ -698,6 +710,16 @@ mod tests {
698
710
}
699
711
}
700
712
713
+ mod try_read_nil_tests {
714
+ use crate :: reader:: try_read_nil;
715
+ use crate :: value:: Value ;
716
+
717
+ #[ test]
718
+ fn try_read_nil_test ( ) {
719
+ assert_eq ! ( Value :: Nil , try_read_nil( "nil " ) . ok( ) . unwrap( ) . 1 ) ;
720
+ }
721
+ }
722
+
701
723
mod try_read_symbol_tests {
702
724
use crate :: reader:: try_read_symbol;
703
725
use crate :: symbol:: Symbol ;
0 commit comments