Skip to content

Commit ec32533

Browse files
author
Leo Pourcelot
committed
Added consume_clojure_whitespaces.
This function will consume whitespaces (as Clojure defines them) from an input stream, and returns it. Under the hood, it uses another function entitled `is_clojure_whitespace`, which returns whether if a character is a whitespace. Clojure specifications state that `,` is a whitespace, which has been implemented here.
1 parent 6fa0abf commit ec32533

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/reader.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,18 @@ pub fn debug_try_read(input: &[u8]) -> IResult<&[u8], Value> {
248248
reading
249249
}
250250

251+
/// Consumes one or more whitespaces from the input.
252+
///
253+
/// A whitespace is either an ASCII whitespace or a comma.
254+
fn consume_clojure_whitespaces(input: &[u8]) -> IResult<&[u8], ()> {
255+
named!(parser, take_while1!(is_clojure_whitespace));
256+
parser(input).map(|(rest, _)| (rest, ()))
257+
}
258+
259+
/// Returns whether if a given character is a whitespace.
260+
///
261+
/// Clojure defines a whitespace as either a comma or an ASCII whitespace.
262+
fn is_clojure_whitespace(c: u8) -> bool {
263+
// ASCII symbol of `,` is 44.
264+
c.is_ascii_whitespace() || c == 44
265+
}

0 commit comments

Comments
 (0)