mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +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
|
platform examples/multi-module
|
||||||
requires { main : Str }
|
requires {}{ main : Str }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports []
|
imports []
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform examples/multi-dep-thunk
|
platform examples/multi-dep-thunk
|
||||||
requires { main : Str }
|
requires {}{ main : Str }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports []
|
imports []
|
||||||
|
|
|
@ -1401,8 +1401,6 @@ where
|
||||||
look_up_builtins,
|
look_up_builtins,
|
||||||
);
|
);
|
||||||
|
|
||||||
dbg!(&result);
|
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(LoadingProblem::MsgChannelDied) => {
|
Err(LoadingProblem::MsgChannelDied) => {
|
||||||
|
|
|
@ -8,7 +8,6 @@ use crate::parser::{
|
||||||
use crate::string_literal;
|
use crate::string_literal;
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc_module::ident::{Lowercase, Uppercase};
|
|
||||||
use roc_region::all::Loc;
|
use roc_region::all::Loc;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::ast::{CommentOrNewline, Def, Module};
|
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::{
|
use crate::header::{
|
||||||
package_entry, package_name, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
package_entry, package_name, package_or_path, AppHeader, Effects, ExposesEntry, ImportsEntry,
|
||||||
InterfaceHeader, ModuleName, PackageEntry, PlatformHeader, PlatformRequires, PlatformRigid, To,
|
InterfaceHeader, ModuleName, PackageEntry, PlatformHeader, PlatformRequires, PlatformRigid, To,
|
||||||
|
@ -412,7 +412,7 @@ fn requires<'a>() -> impl Parser<
|
||||||
ERequires<'a>,
|
ERequires<'a>,
|
||||||
> {
|
> {
|
||||||
let min_indent = 0;
|
let min_indent = 0;
|
||||||
debug!(and!(
|
and!(
|
||||||
spaces_around_keyword(
|
spaces_around_keyword(
|
||||||
min_indent,
|
min_indent,
|
||||||
"requires",
|
"requires",
|
||||||
|
@ -422,17 +422,21 @@ fn requires<'a>() -> impl Parser<
|
||||||
ERequires::IndentListStart
|
ERequires::IndentListStart
|
||||||
),
|
),
|
||||||
platform_requires()
|
platform_requires()
|
||||||
))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn platform_requires<'a>() -> impl Parser<'a, PlatformRequires<'a>, ERequires<'a>> {
|
fn platform_requires<'a>() -> impl Parser<'a, PlatformRequires<'a>, ERequires<'a>> {
|
||||||
map!(and!(requires_rigids(0), requires_typed_ident()), |(
|
map!(
|
||||||
rigids,
|
and!(
|
||||||
signature,
|
skip_second!(
|
||||||
)| {
|
requires_rigids(0),
|
||||||
PlatformRequires { rigids, signature }
|
space0_e(0, ERequires::Space, ERequires::ListStart)
|
||||||
})
|
),
|
||||||
|
requires_typed_ident()
|
||||||
|
),
|
||||||
|
|(rigids, signature)| { PlatformRequires { rigids, signature } }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -440,10 +444,10 @@ fn requires_rigids<'a>(
|
||||||
min_indent: u16,
|
min_indent: u16,
|
||||||
) -> impl Parser<'a, Vec<'a, Located<PlatformRigid<'a>>>, ERequires<'a>> {
|
) -> impl Parser<'a, Vec<'a, Located<PlatformRigid<'a>>>, ERequires<'a>> {
|
||||||
collection_e!(
|
collection_e!(
|
||||||
word1(b'[', ERequires::ListStart),
|
word1(b'{', ERequires::ListStart),
|
||||||
specialize(|_, r, c| ERequires::Rigid(r, c), loc!(requires_rigid())),
|
specialize(|_, r, c| ERequires::Rigid(r, c), loc!(requires_rigid())),
|
||||||
word1(b',', ERequires::ListEnd),
|
word1(b',', ERequires::ListEnd),
|
||||||
word1(b']', ERequires::ListEnd),
|
word1(b'}', ERequires::ListEnd),
|
||||||
min_indent,
|
min_indent,
|
||||||
ERequires::Space,
|
ERequires::Space,
|
||||||
ERequires::IndentListEnd
|
ERequires::IndentListEnd
|
||||||
|
@ -466,7 +470,13 @@ fn requires_typed_ident<'a>() -> impl Parser<'a, Located<TypedIdent<'a>>, ERequi
|
||||||
skip_first!(
|
skip_first!(
|
||||||
word1(b'{', ERequires::ListStart),
|
word1(b'{', ERequires::ListStart),
|
||||||
skip_second!(
|
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)
|
word1(b'}', ERequires::ListStart)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -661,10 +671,10 @@ fn effects<'a>() -> impl Parser<'a, Effects<'a>, EEffects<'a>> {
|
||||||
.parse(arena, state)?;
|
.parse(arena, state)?;
|
||||||
|
|
||||||
// e.g. `fx.`
|
// 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()),
|
specialize(|_, r, c| EEffects::Shorthand(r, c), lowercase_ident()),
|
||||||
word1(b'.', EEffects::ShorthandDot)
|
word1(b'.', EEffects::ShorthandDot)
|
||||||
))
|
)
|
||||||
.parse(arena, state)?;
|
.parse(arena, state)?;
|
||||||
|
|
||||||
// the type name, e.g. Effects
|
// 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::ast::{self, Def, EscapedChar, Spaceable, TypeAnnotation, WhenBranch};
|
||||||
use roc_parse::header::{
|
use roc_parse::header::{
|
||||||
AppHeader, Effects, ExposesEntry, ImportsEntry, InterfaceHeader, ModuleName, PackageEntry,
|
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::module::module_defs;
|
||||||
use roc_parse::parser::{Parser, State, SyntaxError};
|
use roc_parse::parser::{Parser, State, SyntaxError};
|
||||||
|
@ -3128,10 +3129,35 @@ mod test_parse {
|
||||||
spaces_after_effects_keyword: &[],
|
spaces_after_effects_keyword: &[],
|
||||||
spaces_after_type_name: &[],
|
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 {
|
let header = PlatformHeader {
|
||||||
before_header: &[],
|
before_header: &[],
|
||||||
name: Located::new(0, 0, 9, 23, pkg_name),
|
name: Located::new(0, 0, 9, 23, pkg_name),
|
||||||
requires: Vec::new_in(&arena),
|
requires,
|
||||||
exposes: Vec::new_in(&arena),
|
exposes: Vec::new_in(&arena),
|
||||||
packages: Vec::new_in(&arena),
|
packages: Vec::new_in(&arena),
|
||||||
imports: 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 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()))
|
let actual = roc_parse::module::parse_header(&arena, State::new(src.as_bytes()))
|
||||||
.map(|tuple| tuple.0);
|
.map(|tuple| tuple.0);
|
||||||
|
|
||||||
|
@ -3188,10 +3214,36 @@ mod test_parse {
|
||||||
spaces_after_effects_keyword: &[],
|
spaces_after_effects_keyword: &[],
|
||||||
spaces_after_type_name: &[],
|
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 {
|
let header = PlatformHeader {
|
||||||
before_header: &[],
|
before_header: &[],
|
||||||
name: Located::new(0, 0, 9, 19, pkg_name),
|
name: Located::new(0, 0, 9, 19, pkg_name),
|
||||||
requires: Vec::new_in(&arena),
|
requires,
|
||||||
exposes: Vec::new_in(&arena),
|
exposes: Vec::new_in(&arena),
|
||||||
packages,
|
packages,
|
||||||
imports,
|
imports,
|
||||||
|
@ -3215,7 +3267,7 @@ mod test_parse {
|
||||||
let src = indoc!(
|
let src = indoc!(
|
||||||
r#"
|
r#"
|
||||||
platform foo/barbaz
|
platform foo/barbaz
|
||||||
requires {}
|
requires {model=>Model} { main : {} }
|
||||||
exposes []
|
exposes []
|
||||||
packages { foo: "./foo" }
|
packages { foo: "./foo" }
|
||||||
imports []
|
imports []
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform folkertdev/foo
|
platform folkertdev/foo
|
||||||
requires []{main : Effect {}}
|
requires {model=>Model, msg=>Msg} {main : Effect {}}
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports [ Task ]
|
imports [ Task ]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform rtfeldman/roc-cli
|
platform rtfeldman/roc-cli
|
||||||
requires { main : Task.Task {} * } # TODO FIXME
|
requires {}{ main : Task.Task {} * } # TODO FIXME
|
||||||
exposes [] # TODO FIXME actually expose modules
|
exposes [] # TODO FIXME actually expose modules
|
||||||
packages {}
|
packages {}
|
||||||
imports [ Task ] # TODO FIXME Task.{ Task }
|
imports [ Task ] # TODO FIXME Task.{ Task }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform examples/hello-world
|
platform examples/hello-world
|
||||||
requires { main : Str }
|
requires {}{ main : Str }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports []
|
imports []
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform examples/quicksort
|
platform examples/quicksort
|
||||||
requires { quicksort : List I64 -> List I64 }
|
requires {}{ quicksort : List I64 -> List I64 }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports []
|
imports []
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform folkertdev/foo
|
platform folkertdev/foo
|
||||||
requires { main : Task {} [] }
|
requires {}{ main : Task {} [] }
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports [ Task ]
|
imports [ Task ]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
platform folkertdev/foo
|
platform folkertdev/foo
|
||||||
requires []{foo:Str}
|
requires {}{foo:Str}
|
||||||
exposes []
|
exposes []
|
||||||
packages {}
|
packages {}
|
||||||
imports [Cmd]
|
imports [Cmd]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue