mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Parse hosted modules
This commit is contained in:
parent
8633cedf4d
commit
484ce2fbc9
5 changed files with 217 additions and 18 deletions
|
@ -1801,7 +1801,6 @@ fn update<'a>(
|
|||
//
|
||||
// e.g. for `app "blah"` we should generate an output file named "blah"
|
||||
match &parsed.module_name {
|
||||
ModuleNameEnum::PkgConfig => {}
|
||||
ModuleNameEnum::App(output_str) => match output_str {
|
||||
StrLiteral::PlainLine(path) => {
|
||||
state.output_path = Some(path);
|
||||
|
@ -1810,7 +1809,9 @@ fn update<'a>(
|
|||
todo!("TODO gracefully handle a malformed string literal after `app` keyword.");
|
||||
}
|
||||
},
|
||||
ModuleNameEnum::Interface(_) => {}
|
||||
ModuleNameEnum::PkgConfig
|
||||
| ModuleNameEnum::Interface(_)
|
||||
| ModuleNameEnum::Hosted(_) => {}
|
||||
}
|
||||
|
||||
let module_id = parsed.module_id;
|
||||
|
@ -2409,6 +2410,12 @@ fn load_pkg_config<'a>(
|
|||
|
||||
Ok(Msg::Many(vec![effects_module_msg, pkg_config_module_msg]))
|
||||
}
|
||||
Ok((ast::Module::Hosted { header }, _parse_state)) => {
|
||||
Err(LoadingProblem::UnexpectedHeader(format!(
|
||||
"expected platform/package module, got Hosted module with header\n{:?}",
|
||||
header
|
||||
)))
|
||||
}
|
||||
Err(fail) => Err(LoadingProblem::ParsingFailed(
|
||||
fail.map_problem(SyntaxError::Header)
|
||||
.into_file_error(filename),
|
||||
|
@ -2655,6 +2662,29 @@ fn parse_header<'a>(
|
|||
header,
|
||||
module_timing,
|
||||
)),
|
||||
Ok((ast::Module::Hosted { header }, parse_state)) => {
|
||||
let info = HeaderInfo {
|
||||
loc_name: Loc {
|
||||
region: header.name.region,
|
||||
value: ModuleNameEnum::Hosted(header.name.value),
|
||||
},
|
||||
filename,
|
||||
is_root_module,
|
||||
opt_shorthand,
|
||||
packages: &[],
|
||||
exposes: unspace(arena, header.exposes.items),
|
||||
imports: unspace(arena, header.imports.items),
|
||||
to_platform: None,
|
||||
};
|
||||
|
||||
Ok(send_header(
|
||||
info,
|
||||
parse_state,
|
||||
module_ids,
|
||||
ident_ids_by_module,
|
||||
module_timing,
|
||||
))
|
||||
}
|
||||
Err(fail) => Err(LoadingProblem::ParsingFailed(
|
||||
fail.map_problem(SyntaxError::Header)
|
||||
.into_file_error(filename),
|
||||
|
@ -2728,6 +2758,7 @@ enum ModuleNameEnum<'a> {
|
|||
/// A filename
|
||||
App(StrLiteral<'a>),
|
||||
Interface(roc_parse::header::ModuleName<'a>),
|
||||
Hosted(roc_parse::header::ModuleName<'a>),
|
||||
PkgConfig,
|
||||
}
|
||||
|
||||
|
@ -2767,7 +2798,7 @@ fn send_header<'a>(
|
|||
let declared_name: ModuleName = match &loc_name.value {
|
||||
PkgConfig => unreachable!(),
|
||||
App(_) => ModuleName::APP.into(),
|
||||
Interface(module_name) => {
|
||||
Interface(module_name) | Hosted(module_name) => {
|
||||
// TODO check to see if module_name is consistent with filename.
|
||||
// If it isn't, report a problem!
|
||||
|
||||
|
@ -3663,12 +3694,14 @@ where
|
|||
let module_docs = match module_name {
|
||||
ModuleNameEnum::PkgConfig => None,
|
||||
ModuleNameEnum::App(_) => None,
|
||||
ModuleNameEnum::Interface(name) => Some(crate::docs::generate_module_docs(
|
||||
module_output.scope,
|
||||
name.as_str().into(),
|
||||
&module_output.ident_ids,
|
||||
parsed_defs,
|
||||
)),
|
||||
ModuleNameEnum::Interface(name) | ModuleNameEnum::Hosted(name) => {
|
||||
Some(crate::docs::generate_module_docs(
|
||||
module_output.scope,
|
||||
name.as_str().into(),
|
||||
&module_output.ident_ids,
|
||||
parsed_defs,
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let constraint = constrain_module(&module_output.declarations, module_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue