mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
accept comments before the header
This commit is contained in:
parent
4ad57888b2
commit
1977e36459
2 changed files with 34 additions and 6 deletions
|
@ -71,6 +71,7 @@ pub struct InterfaceHeader<'a> {
|
||||||
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
||||||
|
|
||||||
// Potential comments and newlines - these will typically all be empty.
|
// Potential comments and newlines - these will typically all be empty.
|
||||||
|
pub before_header: &'a [CommentOrNewline<'a>],
|
||||||
pub after_interface_keyword: &'a [CommentOrNewline<'a>],
|
pub after_interface_keyword: &'a [CommentOrNewline<'a>],
|
||||||
pub before_exposes: &'a [CommentOrNewline<'a>],
|
pub before_exposes: &'a [CommentOrNewline<'a>],
|
||||||
pub after_exposes: &'a [CommentOrNewline<'a>],
|
pub after_exposes: &'a [CommentOrNewline<'a>],
|
||||||
|
@ -93,6 +94,7 @@ pub struct AppHeader<'a> {
|
||||||
pub to: Loc<To<'a>>,
|
pub to: Loc<To<'a>>,
|
||||||
|
|
||||||
// Potential comments and newlines - these will typically all be empty.
|
// Potential comments and newlines - these will typically all be empty.
|
||||||
|
pub before_header: &'a [CommentOrNewline<'a>],
|
||||||
pub after_app_keyword: &'a [CommentOrNewline<'a>],
|
pub after_app_keyword: &'a [CommentOrNewline<'a>],
|
||||||
pub before_packages: &'a [CommentOrNewline<'a>],
|
pub before_packages: &'a [CommentOrNewline<'a>],
|
||||||
pub after_packages: &'a [CommentOrNewline<'a>],
|
pub after_packages: &'a [CommentOrNewline<'a>],
|
||||||
|
@ -112,6 +114,7 @@ pub struct PackageHeader<'a> {
|
||||||
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
pub imports: Vec<'a, Loc<ImportsEntry<'a>>>,
|
||||||
|
|
||||||
// Potential comments and newlines - these will typically all be empty.
|
// Potential comments and newlines - these will typically all be empty.
|
||||||
|
pub before_header: &'a [CommentOrNewline<'a>],
|
||||||
pub after_package_keyword: &'a [CommentOrNewline<'a>],
|
pub after_package_keyword: &'a [CommentOrNewline<'a>],
|
||||||
pub before_exposes: &'a [CommentOrNewline<'a>],
|
pub before_exposes: &'a [CommentOrNewline<'a>],
|
||||||
pub after_exposes: &'a [CommentOrNewline<'a>],
|
pub after_exposes: &'a [CommentOrNewline<'a>],
|
||||||
|
@ -132,6 +135,7 @@ pub struct PlatformHeader<'a> {
|
||||||
pub effects: Effects<'a>,
|
pub effects: Effects<'a>,
|
||||||
|
|
||||||
// Potential comments and newlines - these will typically all be empty.
|
// Potential comments and newlines - these will typically all be empty.
|
||||||
|
pub before_header: &'a [CommentOrNewline<'a>],
|
||||||
pub after_platform_keyword: &'a [CommentOrNewline<'a>],
|
pub after_platform_keyword: &'a [CommentOrNewline<'a>],
|
||||||
pub before_requires: &'a [CommentOrNewline<'a>],
|
pub before_requires: &'a [CommentOrNewline<'a>],
|
||||||
pub after_requires: &'a [CommentOrNewline<'a>],
|
pub after_requires: &'a [CommentOrNewline<'a>],
|
||||||
|
|
|
@ -57,16 +57,37 @@ fn header<'a>() -> impl Parser<'a, Module<'a>, EHeader<'a>> {
|
||||||
|
|
||||||
one_of![
|
one_of![
|
||||||
map!(
|
map!(
|
||||||
skip_first!(keyword_e("app", EHeader::Start), app_header()),
|
and!(
|
||||||
|header| { Module::App { header } }
|
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!(
|
map!(
|
||||||
skip_first!(keyword_e("platform", EHeader::Start), platform_header()),
|
and!(
|
||||||
|header| { Module::Platform { header } }
|
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!(
|
map!(
|
||||||
skip_first!(keyword_e("interface", EHeader::Start), interface_header()),
|
and!(
|
||||||
|header| { Module::Interface { header } }
|
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 }
|
||||||
|
}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -89,6 +110,7 @@ fn interface_header<'a>() -> impl Parser<'a, InterfaceHeader<'a>, EHeader<'a>> {
|
||||||
name,
|
name,
|
||||||
exposes,
|
exposes,
|
||||||
imports,
|
imports,
|
||||||
|
before_header: &[] as &[_],
|
||||||
after_interface_keyword,
|
after_interface_keyword,
|
||||||
before_exposes,
|
before_exposes,
|
||||||
after_exposes,
|
after_exposes,
|
||||||
|
@ -210,6 +232,7 @@ fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>, EHeader<'a>> {
|
||||||
imports,
|
imports,
|
||||||
provides: provides.entries,
|
provides: provides.entries,
|
||||||
to: provides.to,
|
to: provides.to,
|
||||||
|
before_header: &[] as &[_],
|
||||||
after_app_keyword,
|
after_app_keyword,
|
||||||
before_packages,
|
before_packages,
|
||||||
after_packages,
|
after_packages,
|
||||||
|
@ -259,6 +282,7 @@ fn platform_header<'a>() -> impl Parser<'a, PlatformHeader<'a>, EHeader<'a>> {
|
||||||
imports,
|
imports,
|
||||||
provides,
|
provides,
|
||||||
effects,
|
effects,
|
||||||
|
before_header: &[] as &[_],
|
||||||
after_platform_keyword,
|
after_platform_keyword,
|
||||||
before_requires,
|
before_requires,
|
||||||
after_requires,
|
after_requires,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue