diff --git a/src/lib.rs b/src/lib.rs index b758579..88c0513 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ use nom::{ branch::alt, bytes::complete::{tag, take_until, take_until1, take_while, take_while1}, character::complete::{multispace0, space0}, - combinator::recognize, + combinator::{opt, recognize}, error::{ErrorKind, ParseError}, multi::{many0, many1}, sequence::{delimited, tuple}, @@ -47,11 +47,23 @@ pub struct Spec { } fn allspaces(i: &str) -> IResult<&str, &str> { - alt((delimited(multispace0, comment, multispace0), multispace0))(i) + let (i, (_, comments)) = tuple((multispace0, opt(comment)))(i)?; + + let mut i = i; + if let Some(_) = comments { + let (j, _) = multispace0(i)?; + i = j; + } + + Ok((i, "")) } fn comment(i: &str) -> IResult<&str, &str> { - let (i, _) = delimited(alt((tag("#"), tag("//"))), take_until("\n"), tag("\n"))(i)?; + let (i, _) = many1(delimited( + alt((tag("#"), tag("//"))), + take_until("\n"), + tag("\n"), + ))(i)?; Ok((i, "")) }