parser: add possible space or comment
This commit is contained in:
parent
4fa49e2181
commit
6cb3633cd1
1 changed files with 22 additions and 9 deletions
|
@ -8,12 +8,15 @@ use fasteval::Evaler;
|
|||
use nom::{
|
||||
AsBytes, AsChar, Compare, FindToken, Finish, IResult, Input, Offset, Parser as NomParser,
|
||||
branch::alt,
|
||||
bytes::complete::{tag, take},
|
||||
character::{complete::char, streaming::one_of},
|
||||
bytes::complete::{tag, take, take_till},
|
||||
character::{
|
||||
complete::{char, space1},
|
||||
streaming::one_of,
|
||||
},
|
||||
combinator::value,
|
||||
error::{Error, ErrorKind},
|
||||
multi::many0,
|
||||
sequence::preceded,
|
||||
sequence::{delimited, preceded},
|
||||
};
|
||||
use nom_locate::LocatedSpan;
|
||||
|
||||
|
@ -41,12 +44,22 @@ where
|
|||
pub fn parse_all(
|
||||
&self,
|
||||
) -> Result<Vec<Box<dyn Token>>, Error<nom_locate::LocatedSpan<&'i str>>> {
|
||||
many0(alt((
|
||||
let space_or_comment = || {
|
||||
value(
|
||||
(),
|
||||
many0(value((), char('#').and(take_till(|c| c == '\n'))).or(value((), space1))),
|
||||
)
|
||||
};
|
||||
many0(delimited(
|
||||
space_or_comment(),
|
||||
alt((
|
||||
Silence::parser().map(into_box),
|
||||
Marker::parser().map(into_box),
|
||||
Note::parser(self.notes).map(into_box),
|
||||
VariableChange::parser::<LocatedSpan<&'i str>, C>(self.variables).map(into_box),
|
||||
)))
|
||||
)),
|
||||
space_or_comment(),
|
||||
))
|
||||
.parse_complete(LocatedSpan::new(self.input))
|
||||
.finish()
|
||||
.map(|(_, o)| o)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue