Skip to content

Commit a92c3a5

Browse files
committed
reader supports nil
1 parent 4eeaa34 commit a92c3a5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/reader.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,17 @@ pub fn try_read_bool(input: &str) -> IResult<&str, Value> {
307307
Ok((rest_input, Value::Boolean(bool.parse().unwrap())))
308308
}
309309

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+
310321
/// Tries to parse &str into Value::double
311322
///
312323
pub fn try_read_f64(input: &str) -> IResult<&str, Value> {
@@ -459,6 +470,7 @@ pub fn try_read(input: &str) -> IResult<&str, Value> {
459470
try_read_f64,
460471
try_read_i32,
461472
try_read_bool,
473+
try_read_nil,
462474
try_read_symbol,
463475
try_read_keyword,
464476
try_read_list,
@@ -674,6 +686,16 @@ mod tests {
674686
}
675687
}
676688

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+
677699
mod try_read_symbol_tests {
678700
use crate::reader::try_read_symbol;
679701
use crate::symbol::Symbol;

0 commit comments

Comments
 (0)