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::{
|
use nom::{
|
||||||
AsBytes, AsChar, Compare, FindToken, Finish, IResult, Input, Offset, Parser as NomParser,
|
AsBytes, AsChar, Compare, FindToken, Finish, IResult, Input, Offset, Parser as NomParser,
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::{tag, take},
|
bytes::complete::{tag, take, take_till},
|
||||||
character::{complete::char, streaming::one_of},
|
character::{
|
||||||
|
complete::{char, space1},
|
||||||
|
streaming::one_of,
|
||||||
|
},
|
||||||
combinator::value,
|
combinator::value,
|
||||||
error::{Error, ErrorKind},
|
error::{Error, ErrorKind},
|
||||||
multi::many0,
|
multi::many0,
|
||||||
sequence::preceded,
|
sequence::{delimited, preceded},
|
||||||
};
|
};
|
||||||
use nom_locate::LocatedSpan;
|
use nom_locate::LocatedSpan;
|
||||||
|
|
||||||
|
@ -41,12 +44,22 @@ where
|
||||||
pub fn parse_all(
|
pub fn parse_all(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<Vec<Box<dyn Token>>, Error<nom_locate::LocatedSpan<&'i str>>> {
|
) -> 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),
|
Silence::parser().map(into_box),
|
||||||
Marker::parser().map(into_box),
|
Marker::parser().map(into_box),
|
||||||
Note::parser(self.notes).map(into_box),
|
Note::parser(self.notes).map(into_box),
|
||||||
VariableChange::parser::<LocatedSpan<&'i str>, C>(self.variables).map(into_box),
|
VariableChange::parser::<LocatedSpan<&'i str>, C>(self.variables).map(into_box),
|
||||||
)))
|
)),
|
||||||
|
space_or_comment(),
|
||||||
|
))
|
||||||
.parse_complete(LocatedSpan::new(self.input))
|
.parse_complete(LocatedSpan::new(self.input))
|
||||||
.finish()
|
.finish()
|
||||||
.map(|(_, o)| o)
|
.map(|(_, o)| o)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue