mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
Require packages and imports once again
This commit is contained in:
parent
a7eb568267
commit
09d107e469
4 changed files with 12 additions and 67 deletions
|
@ -1,5 +1,6 @@
|
||||||
app "quicksort"
|
app "quicksort"
|
||||||
packages { base: "./platform" }
|
packages { base: "./platform" }
|
||||||
|
imports []
|
||||||
provides [ swap, partition, partitionHelp, quicksort ] to base
|
provides [ swap, partition, partitionHelp, quicksort ] to base
|
||||||
|
|
||||||
quicksort : List (Num a), Int, Int -> List (Num a)
|
quicksort : List (Num a), Int, Int -> List (Num a)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
app "quicksort" packages { base: "./platform" } provides [ quicksort ] to base
|
app "quicksort" packages { base: "./platform" } imports [] provides [ quicksort ] to base
|
||||||
|
|
||||||
quicksort = \originalList ->
|
quicksort = \originalList ->
|
||||||
quicksortHelp : List (Num a), Int, Int -> List (Num a)
|
quicksortHelp : List (Num a), Int, Int -> List (Num a)
|
||||||
|
|
|
@ -175,50 +175,30 @@ pub fn module_name<'a>() -> impl Parser<'a, ModuleName<'a>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>> {
|
pub fn app_header<'a>() -> impl Parser<'a, AppHeader<'a>> {
|
||||||
map_with_arena!(
|
map!(
|
||||||
and!(
|
and!(
|
||||||
skip_first!(
|
skip_first!(
|
||||||
ascii_string("app"),
|
ascii_string("app"),
|
||||||
and!(space1(1), loc!(string_literal::parse()))
|
and!(space1(1), loc!(string_literal::parse()))
|
||||||
),
|
),
|
||||||
and!(
|
and!(packages(), and!(imports(), provides_to()))
|
||||||
optional(packages()),
|
|
||||||
and!(optional(imports()), provides_to())
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|arena, ((after_app_keyword, name), (opt_pkgs, (opt_imports, provides)))| {
|
|(
|
||||||
let (before_packages, after_packages, package_entries) = match opt_pkgs {
|
(after_app_keyword, name),
|
||||||
Some(pkgs) => {
|
(pkgs, (((before_imports, after_imports), imports), provides)),
|
||||||
let pkgs: Packages<'a> = pkgs; // rustc must be told the type here
|
)| {
|
||||||
|
let pkgs: Packages<'a> = pkgs; // rustc must be told the type here
|
||||||
(
|
|
||||||
pkgs.before_packages_keyword,
|
|
||||||
pkgs.after_packages_keyword,
|
|
||||||
pkgs.entries,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
None => (&[] as _, &[] as _, Vec::new_in(arena)),
|
|
||||||
};
|
|
||||||
|
|
||||||
// rustc must be told the type here
|
|
||||||
let opt_imports: Option<(
|
|
||||||
(&'a [CommentOrNewline<'a>], &'a [CommentOrNewline<'a>]),
|
|
||||||
Vec<'a, Located<ImportsEntry<'a>>>,
|
|
||||||
)> = opt_imports;
|
|
||||||
|
|
||||||
let ((before_imports, after_imports), imports) =
|
|
||||||
opt_imports.unwrap_or_else(|| ((&[] as _, &[] as _), Vec::new_in(arena)));
|
|
||||||
let provides: ProvidesTo<'a> = provides; // rustc must be told the type here
|
let provides: ProvidesTo<'a> = provides; // rustc must be told the type here
|
||||||
|
|
||||||
AppHeader {
|
AppHeader {
|
||||||
name,
|
name,
|
||||||
packages: package_entries,
|
packages: pkgs.entries,
|
||||||
imports,
|
imports,
|
||||||
provides: provides.entries,
|
provides: provides.entries,
|
||||||
to: provides.to,
|
to: provides.to,
|
||||||
after_app_keyword,
|
after_app_keyword,
|
||||||
before_packages,
|
before_packages: pkgs.before_packages_keyword,
|
||||||
after_packages,
|
after_packages: pkgs.after_packages_keyword,
|
||||||
before_imports,
|
before_imports,
|
||||||
after_imports,
|
after_imports,
|
||||||
before_provides: provides.before_provides_keyword,
|
before_provides: provides.before_provides_keyword,
|
||||||
|
|
|
@ -2235,42 +2235,6 @@ mod test_parse {
|
||||||
assert_eq!(Ok(expected), actual);
|
assert_eq!(Ok(expected), actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn minimal_app_header() {
|
|
||||||
let arena = Bump::new();
|
|
||||||
let packages = Vec::new_in(&arena);
|
|
||||||
let imports = Vec::new_in(&arena);
|
|
||||||
let provides = Vec::new_in(&arena);
|
|
||||||
let module_name = StrLiteral::PlainLine("test-app");
|
|
||||||
let expected = AppHeader {
|
|
||||||
name: Located::new(0, 0, 4, 14, module_name),
|
|
||||||
packages,
|
|
||||||
imports,
|
|
||||||
provides,
|
|
||||||
to: Located::new(0, 0, 30, 34, "blah"),
|
|
||||||
after_app_keyword: &[],
|
|
||||||
before_packages: &[],
|
|
||||||
after_packages: &[],
|
|
||||||
before_imports: &[],
|
|
||||||
after_imports: &[],
|
|
||||||
before_provides: &[],
|
|
||||||
after_provides: &[],
|
|
||||||
before_to: &[],
|
|
||||||
after_to: &[],
|
|
||||||
};
|
|
||||||
|
|
||||||
let src = indoc!(
|
|
||||||
r#"
|
|
||||||
app "test-app" provides [] to blah
|
|
||||||
"#
|
|
||||||
);
|
|
||||||
let actual = app_header()
|
|
||||||
.parse(&arena, State::new(src.as_bytes(), Attempting::Module))
|
|
||||||
.map(|tuple| tuple.0);
|
|
||||||
|
|
||||||
assert_eq!(Ok(expected), actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn full_app_header() {
|
fn full_app_header() {
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue