parser support differentiate newline and space

This commit is contained in:
Eric 2022-04-04 15:15:56 +08:00
parent 9015bb0a95
commit 82ecd16f20
2 changed files with 5 additions and 1 deletions

View File

@ -314,9 +314,12 @@ pub(crate) fn white_space(s: Span) -> IResult<Span, WhiteSpace> {
})(s) })(s)
} else { } else {
alt(( alt((
map(multispace1, |x: Span| { map(space1, |x: Span| {
WhiteSpace::Space(Box::new(into_locate(x))) WhiteSpace::Space(Box::new(into_locate(x)))
}), }),
map(multispace1, |x: Span| {
WhiteSpace::Newline(Box::new(into_locate(x)))
}),
map(preceded(peek(char('/')), comment), |x| { map(preceded(peek(char('/')), comment), |x| {
WhiteSpace::Comment(Box::new(x)) WhiteSpace::Comment(Box::new(x))
}), }),

View File

@ -14,6 +14,7 @@ pub struct Keyword {
#[derive(Clone, Debug, PartialEq, Node)] #[derive(Clone, Debug, PartialEq, Node)]
pub enum WhiteSpace { pub enum WhiteSpace {
Newline(Box<Locate>),
Space(Box<Locate>), Space(Box<Locate>),
Comment(Box<Comment>), Comment(Box<Comment>),
CompilerDirective(Box<CompilerDirective>), CompilerDirective(Box<CompilerDirective>),