Parse interfaces with leading newlines

Closes #2420
This commit is contained in:
ayazhafiz 2022-01-29 23:52:00 -05:00
parent eb17d88ebb
commit 8ae2d9d407
4 changed files with 55 additions and 34 deletions

View file

@ -52,41 +52,44 @@ pub fn parse_header<'a>(
fn header<'a>() -> impl Parser<'a, Module<'a>, EHeader<'a>> {
use crate::parser::keyword_e;
one_of![
map!(
and!(
space0_e(0, EHeader::Space, EHeader::IndentStart),
skip_first!(keyword_e("app", EHeader::Start), app_header())
),
|(spaces, mut header): (&'a [CommentOrNewline], AppHeader<'a>)| {
header.before_header = spaces;
Module::App { header }
}
map!(
and!(
space0_e(0, EHeader::Space, EHeader::IndentStart),
one_of![
map!(
skip_first!(keyword_e("app", EHeader::Start), app_header()),
|mut header: AppHeader<'a>| -> Box<dyn FnOnce(&'a [CommentOrNewline]) -> Module<'a>> {
Box::new(|spaces| {
header.before_header = spaces;
Module::App { header }
})
}
),
map!(
skip_first!(keyword_e("platform", EHeader::Start), platform_header()),
|mut header: PlatformHeader<'a>| -> Box<dyn FnOnce(&'a [CommentOrNewline]) -> Module<'a>> {
Box::new(|spaces| {
header.before_header = spaces;
Module::Platform { header }
})
}
),
map!(
skip_first!(keyword_e("interface", EHeader::Start), interface_header()),
|mut header: InterfaceHeader<'a>| -> Box<dyn FnOnce(&'a [CommentOrNewline]) -> Module<'a>> {
Box::new(|spaces| {
header.before_header = spaces;
Module::Interface { header }
})
}
)
]
),
map!(
and!(
space0_e(0, EHeader::Space, EHeader::IndentStart),
skip_first!(keyword_e("platform", EHeader::Start), platform_header())
),
|(spaces, mut header): (&'a [CommentOrNewline], PlatformHeader<'a>)| {
header.before_header = spaces;
Module::Platform { header }
}
),
map!(
and!(
space0_e(0, EHeader::Space, EHeader::IndentStart),
skip_first!(keyword_e("interface", EHeader::Start), interface_header())
),
|(spaces, mut header): (&'a [CommentOrNewline], InterfaceHeader<'a>)| {
header.before_header = spaces;
Module::Interface { header }
}
)
]
|(spaces, make_header): (
&'a [CommentOrNewline],
Box<dyn FnOnce(&'a [CommentOrNewline]) -> Module<'a>>
)| { make_header(spaces) }
)
}
#[inline(always)]