mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
refactor load/file logic
This commit is contained in:
parent
6c74d4847a
commit
e926bced10
2 changed files with 26 additions and 25 deletions
|
@ -1,6 +1,8 @@
|
|||
pub use roc_ident::IdentStr;
|
||||
use std::fmt;
|
||||
|
||||
use crate::symbol::PQModuleName;
|
||||
|
||||
/// This could be uppercase or lowercase, qualified or unqualified.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
|
||||
pub struct Ident(pub IdentStr);
|
||||
|
@ -21,6 +23,25 @@ pub struct QualifiedModuleName<'a> {
|
|||
pub module: ModuleName,
|
||||
}
|
||||
|
||||
impl<'a> QualifiedModuleName<'a> {
|
||||
pub fn into_pq_module_name(self, opt_shorthand: Option<&'a str>) -> PQModuleName<'a> {
|
||||
if self.is_builtin() {
|
||||
// If this is a builtin, it must be unqualified, and we should *never* prefix it
|
||||
// with the package shorthand! The user intended to import the module as-is here.
|
||||
debug_assert!(self.opt_package.is_none());
|
||||
PQModuleName::Unqualified(self.module)
|
||||
} else {
|
||||
match self.opt_package {
|
||||
None => match opt_shorthand {
|
||||
Some(shorthand) => PQModuleName::Qualified(shorthand, self.module),
|
||||
None => PQModuleName::Unqualified(self.module),
|
||||
},
|
||||
Some(package) => PQModuleName::Qualified(package, self.module),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ModuleName(IdentStr);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue