mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Parse app module headers.
This commit is contained in:
parent
61f836e964
commit
d994d11760
2 changed files with 43 additions and 3 deletions
|
@ -36,9 +36,14 @@ pub struct WhenBranch<'a> {
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct AppHeader<'a> {
|
pub struct AppHeader<'a> {
|
||||||
|
pub name: Loc<ModuleName<'a>>,
|
||||||
|
pub provides: Vec<'a, Loc<ExposesEntry<'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 after_interface: &'a [CommentOrNewline<'a>],
|
||||||
|
pub before_provides: &'a [CommentOrNewline<'a>],
|
||||||
|
pub after_provides: &'a [CommentOrNewline<'a>],
|
||||||
pub before_imports: &'a [CommentOrNewline<'a>],
|
pub before_imports: &'a [CommentOrNewline<'a>],
|
||||||
pub after_imports: &'a [CommentOrNewline<'a>],
|
pub after_imports: &'a [CommentOrNewline<'a>],
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,9 +127,30 @@ pub fn module_name<'a>() -> impl Parser<'a, ModuleName<'a>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>> {
|
fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>> {
|
||||||
move |_, _| {
|
parser::map(
|
||||||
panic!("TODO parse app header");
|
and!(
|
||||||
|
skip_first!(string("app"), and!(space1(1), loc!(module_name()))),
|
||||||
|
and!(provides(), imports())
|
||||||
|
),
|
||||||
|
|(
|
||||||
|
(after_interface, name),
|
||||||
|
(
|
||||||
|
((before_provides, after_provides), provides),
|
||||||
|
((before_imports, after_imports), imports),
|
||||||
|
),
|
||||||
|
)| {
|
||||||
|
AppHeader {
|
||||||
|
name,
|
||||||
|
provides,
|
||||||
|
imports,
|
||||||
|
after_interface,
|
||||||
|
before_provides,
|
||||||
|
after_provides,
|
||||||
|
before_imports,
|
||||||
|
after_imports,
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -137,6 +158,20 @@ pub fn module_defs<'a>() -> impl Parser<'a, Vec<'a, Located<Def<'a>>>> {
|
||||||
zero_or_more!(space0_around(loc(def(0)), 0))
|
zero_or_more!(space0_around(loc(def(0)), 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn provides<'a>() -> impl Parser<
|
||||||
|
'a,
|
||||||
|
(
|
||||||
|
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
||||||
|
Vec<'a, Located<ExposesEntry<'a>>>,
|
||||||
|
),
|
||||||
|
> {
|
||||||
|
and!(
|
||||||
|
and!(skip_second!(space1(1), string("provides")), space1(1)),
|
||||||
|
collection!(char('['), loc!(exposes_entry()), char(','), char(']'), 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn exposes<'a>() -> impl Parser<
|
fn exposes<'a>() -> impl Parser<
|
||||||
'a,
|
'a,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue