Implement support for multiline comments
Some checks are pending
ci/woodpecker/push/woodpecker Pipeline is pending
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:
parent
692cb204ac
commit
e626352e87
1 changed files with 15 additions and 3 deletions
18
src/lib.rs
18
src/lib.rs
|
@ -14,7 +14,7 @@ use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{tag, take_until, take_until1, take_while, take_while1},
|
bytes::complete::{tag, take_until, take_until1, take_while, take_while1},
|
||||||
character::complete::{multispace0, space0},
|
character::complete::{multispace0, space0},
|
||||||
combinator::recognize,
|
combinator::{opt, recognize},
|
||||||
error::{ErrorKind, ParseError},
|
error::{ErrorKind, ParseError},
|
||||||
multi::{many0, many1},
|
multi::{many0, many1},
|
||||||
sequence::{delimited, tuple},
|
sequence::{delimited, tuple},
|
||||||
|
@ -47,11 +47,23 @@ pub struct Spec {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn allspaces(i: &str) -> IResult<&str, &str> {
|
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> {
|
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, ""))
|
Ok((i, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue