Implement support for multiline comments
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-01-11 18:41:01 +01:00
parent 692cb204ac
commit e626352e87
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -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, ""))
}