mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
fix and test
This commit is contained in:
parent
64bc92c746
commit
c68cd2fb2d
12 changed files with 89 additions and 30 deletions
|
@ -1,5 +1,5 @@
|
|||
platform examples/multi-module
|
||||
requires { main : Str }
|
||||
requires {}{ main : Str }
|
||||
exposes []
|
||||
packages {}
|
||||
imports []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform examples/multi-dep-thunk
|
||||
requires { main : Str }
|
||||
requires {}{ main : Str }
|
||||
exposes []
|
||||
packages {}
|
||||
imports []
|
||||
|
|
|
@ -1401,8 +1401,6 @@ where
|
|||
look_up_builtins,
|
||||
);
|
||||
|
||||
dbg!(&result);
|
||||
|
||||
match result {
|
||||
Ok(()) => {}
|
||||
Err(LoadingProblem::MsgChannelDied) => {
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::parser::{
|
|||
use crate::string_literal;
|
||||
use bumpalo::collections::Vec;
|
||||
use inlinable_string::InlinableString;
|
||||
use roc_module::ident::{Lowercase, Uppercase};
|
||||
use roc_region::all::Loc;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::ast::{CommentOrNewline, Def, Module};
|
||||
use crate::blankspace::{space0_before_e, space0_e};
|
||||
use crate::blankspace::{space0_around_ee, space0_before_e, space0_e};
|
||||
use crate::header::{
|
||||
package_entry, package_name, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
||||
InterfaceHeader, ModuleName, PackageEntry, PlatformHeader, PlatformRequires, PlatformRigid, To,
|
||||
|
@ -412,7 +412,7 @@ fn requires<'a>() -> impl Parser<
|
|||
ERequires<'a>,
|
||||
> {
|
||||
let min_indent = 0;
|
||||
debug!(and!(
|
||||
and!(
|
||||
spaces_around_keyword(
|
||||
min_indent,
|
||||
"requires",
|
||||
|
@ -422,17 +422,21 @@ fn requires<'a>() -> impl Parser<
|
|||
ERequires::IndentListStart
|
||||
),
|
||||
platform_requires()
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn platform_requires<'a>() -> impl Parser<'a, PlatformRequires<'a>, ERequires<'a>> {
|
||||
map!(and!(requires_rigids(0), requires_typed_ident()), |(
|
||||
rigids,
|
||||
signature,
|
||||
)| {
|
||||
PlatformRequires { rigids, signature }
|
||||
})
|
||||
map!(
|
||||
and!(
|
||||
skip_second!(
|
||||
requires_rigids(0),
|
||||
space0_e(0, ERequires::Space, ERequires::ListStart)
|
||||
),
|
||||
requires_typed_ident()
|
||||
),
|
||||
|(rigids, signature)| { PlatformRequires { rigids, signature } }
|
||||
)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -440,10 +444,10 @@ fn requires_rigids<'a>(
|
|||
min_indent: u16,
|
||||
) -> impl Parser<'a, Vec<'a, Located<PlatformRigid<'a>>>, ERequires<'a>> {
|
||||
collection_e!(
|
||||
word1(b'[', ERequires::ListStart),
|
||||
word1(b'{', ERequires::ListStart),
|
||||
specialize(|_, r, c| ERequires::Rigid(r, c), loc!(requires_rigid())),
|
||||
word1(b',', ERequires::ListEnd),
|
||||
word1(b']', ERequires::ListEnd),
|
||||
word1(b'}', ERequires::ListEnd),
|
||||
min_indent,
|
||||
ERequires::Space,
|
||||
ERequires::IndentListEnd
|
||||
|
@ -466,7 +470,13 @@ fn requires_typed_ident<'a>() -> impl Parser<'a, Located<TypedIdent<'a>>, ERequi
|
|||
skip_first!(
|
||||
word1(b'{', ERequires::ListStart),
|
||||
skip_second!(
|
||||
specialize(ERequires::TypedIdent, loc!(typed_ident())),
|
||||
space0_around_ee(
|
||||
specialize(ERequires::TypedIdent, loc!(typed_ident()),),
|
||||
0,
|
||||
ERequires::Space,
|
||||
ERequires::ListStart,
|
||||
ERequires::ListEnd
|
||||
),
|
||||
word1(b'}', ERequires::ListStart)
|
||||
)
|
||||
)
|
||||
|
@ -661,10 +671,10 @@ fn effects<'a>() -> impl Parser<'a, Effects<'a>, EEffects<'a>> {
|
|||
.parse(arena, state)?;
|
||||
|
||||
// e.g. `fx.`
|
||||
let (_, type_shortname, state) = debug!(skip_second!(
|
||||
let (_, type_shortname, state) = skip_second!(
|
||||
specialize(|_, r, c| EEffects::Shorthand(r, c), lowercase_ident()),
|
||||
word1(b'.', EEffects::ShorthandDot)
|
||||
))
|
||||
)
|
||||
.parse(arena, state)?;
|
||||
|
||||
// the type name, e.g. Effects
|
||||
|
|
|
@ -26,7 +26,8 @@ mod test_parse {
|
|||
use roc_parse::ast::{self, Def, EscapedChar, Spaceable, TypeAnnotation, WhenBranch};
|
||||
use roc_parse::header::{
|
||||
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
|
||||
PackageName, PackageOrPath, PlatformHeader, To,
|
||||
PackageName, PackageOrPath, PlatformHeader, PlatformRequires, PlatformRigid, To,
|
||||
TypedIdent,
|
||||
};
|
||||
use roc_parse::module::module_defs;
|
||||
use roc_parse::parser::{Parser, State, SyntaxError};
|
||||
|
@ -3128,10 +3129,35 @@ mod test_parse {
|
|||
spaces_after_effects_keyword: &[],
|
||||
spaces_after_type_name: &[],
|
||||
};
|
||||
|
||||
let requires = {
|
||||
let region1 = Region::new(0, 0, 38, 47);
|
||||
let region2 = Region::new(0, 0, 45, 47);
|
||||
|
||||
PlatformRequires {
|
||||
rigids: Vec::new_in(&arena),
|
||||
signature: Located::at(
|
||||
region1,
|
||||
TypedIdent::Entry {
|
||||
ident: Located::new(0, 0, 38, 42, "main"),
|
||||
spaces_before_colon: &[],
|
||||
ann: Located::at(
|
||||
region2,
|
||||
TypeAnnotation::Record {
|
||||
fields: &[],
|
||||
ext: None,
|
||||
final_comments: &[],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
}
|
||||
};
|
||||
|
||||
let header = PlatformHeader {
|
||||
before_header: &[],
|
||||
name: Located::new(0, 0, 9, 23, pkg_name),
|
||||
requires: Vec::new_in(&arena),
|
||||
requires,
|
||||
exposes: Vec::new_in(&arena),
|
||||
packages: Vec::new_in(&arena),
|
||||
imports: Vec::new_in(&arena),
|
||||
|
@ -3152,7 +3178,7 @@ mod test_parse {
|
|||
|
||||
let expected = roc_parse::ast::Module::Platform { header };
|
||||
|
||||
let src = "platform rtfeldman/blah requires {} exposes [] packages {} imports [] provides [] effects fx.Blah {}";
|
||||
let src = "platform rtfeldman/blah requires {} { main : {} } exposes [] packages {} imports [] provides [] effects fx.Blah {}";
|
||||
let actual = roc_parse::module::parse_header(&arena, State::new(src.as_bytes()))
|
||||
.map(|tuple| tuple.0);
|
||||
|
||||
|
@ -3188,10 +3214,36 @@ mod test_parse {
|
|||
spaces_after_effects_keyword: &[],
|
||||
spaces_after_type_name: &[],
|
||||
};
|
||||
|
||||
let requires = {
|
||||
let region1 = Region::new(1, 1, 30, 39);
|
||||
let region2 = Region::new(1, 1, 37, 39);
|
||||
let region3 = Region::new(1, 1, 14, 26);
|
||||
|
||||
PlatformRequires {
|
||||
rigids: bumpalo::vec![ in &arena; Located::at(region3, PlatformRigid::Entry { alias: "Model", rigid: "model" }) ],
|
||||
signature: Located::at(
|
||||
region1,
|
||||
TypedIdent::Entry {
|
||||
ident: Located::new(1, 1, 30, 34, "main"),
|
||||
spaces_before_colon: &[],
|
||||
ann: Located::at(
|
||||
region2,
|
||||
TypeAnnotation::Record {
|
||||
fields: &[],
|
||||
ext: None,
|
||||
final_comments: &[],
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
}
|
||||
};
|
||||
|
||||
let header = PlatformHeader {
|
||||
before_header: &[],
|
||||
name: Located::new(0, 0, 9, 19, pkg_name),
|
||||
requires: Vec::new_in(&arena),
|
||||
requires,
|
||||
exposes: Vec::new_in(&arena),
|
||||
packages,
|
||||
imports,
|
||||
|
@ -3215,7 +3267,7 @@ mod test_parse {
|
|||
let src = indoc!(
|
||||
r#"
|
||||
platform foo/barbaz
|
||||
requires {}
|
||||
requires {model=>Model} { main : {} }
|
||||
exposes []
|
||||
packages { foo: "./foo" }
|
||||
imports []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform folkertdev/foo
|
||||
requires []{main : Effect {}}
|
||||
requires {model=>Model, msg=>Msg} {main : Effect {}}
|
||||
exposes []
|
||||
packages {}
|
||||
imports [ Task ]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform rtfeldman/roc-cli
|
||||
requires { main : Task.Task {} * } # TODO FIXME
|
||||
requires {}{ main : Task.Task {} * } # TODO FIXME
|
||||
exposes [] # TODO FIXME actually expose modules
|
||||
packages {}
|
||||
imports [ Task ] # TODO FIXME Task.{ Task }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform examples/hello-world
|
||||
requires { main : Str }
|
||||
requires {}{ main : Str }
|
||||
exposes []
|
||||
packages {}
|
||||
imports []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform examples/quicksort
|
||||
requires { quicksort : List I64 -> List I64 }
|
||||
requires {}{ quicksort : List I64 -> List I64 }
|
||||
exposes []
|
||||
packages {}
|
||||
imports []
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform folkertdev/foo
|
||||
requires { main : Task {} [] }
|
||||
requires {}{ main : Task {} [] }
|
||||
exposes []
|
||||
packages {}
|
||||
imports [ Task ]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
platform folkertdev/foo
|
||||
requires []{foo:Str}
|
||||
requires {}{foo:Str}
|
||||
exposes []
|
||||
packages {}
|
||||
imports [Cmd]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue