This module contains functionality to resolve names in the Elm code into Morphir fully-qualified names. The process
is relatively complex due to the many ways names can be imported in an Elm module. Here, we split up the overall process
into three main steps following the structure of an Elm module:
resolveModuleName : Morphir.IR.Repo.Repo -> List String -> Result Error QualifiedModuleName
Finds out the Morphir package and module name from an Elm module name and a Repo.
resolveImports : Morphir.IR.Repo.Repo -> List Elm.Syntax.Import.Import -> Result Error ResolvedImports
Resolve the imports into an internal data structure that makes it easier to resolve names within the module. This is
done once per module.
resolveLocalName : Morphir.IR.Repo.Repo -> Morphir.IR.Module.ModuleName -> VisibleNames -> ResolvedImports -> List String -> Morphir.IR.KindOfName.KindOfName -> String -> Result Error Morphir.IR.FQName.FQName
Resolve each individual name using the data structure mentioned above. This is done for each type, constructor and
value name in the module.
{ visibleNamesByModuleName : Dict QualifiedModuleName VisibleNames
, moduleNamesByAliasOrSingleModuleName : Dict String (Set QualifiedModuleName)
, moduleNamesByLocalTypeName : Dict Morphir.IR.Name.Name (Set QualifiedModuleName)
, moduleNamesByLocalValueName : Dict Morphir.IR.Name.Name (Set QualifiedModuleName)
, moduleNamesByLocalConstructorName : Dict Morphir.IR.Name.Name (Set QualifiedModuleName)
}
Internal data structure for efficient lookup of names based on imports.
{ types : Set Morphir.IR.Name.Name
, constructors : Set Morphir.IR.Name.Name
, values : Set Morphir.IR.Name.Name
}
Represents the names that a module exposes or makes internally available.
Errors
type Error = NoMorphirPackageFoundForElmModule (List String)
| ModuleNotImported (List String)
| ModuleOrAliasNotImported String
| ModuleDoesNotExposeLocalName Morphir.IR.Package.PackageName Morphir.IR.Module.ModuleName Morphir.IR.Name.Name Morphir.IR.KindOfName.KindOfName
| ModulesDoNotExposeLocalName String (List QualifiedModuleName) Morphir.IR.Name.Name Morphir.IR.KindOfName.KindOfName
| MultipleModulesExposeLocalName (List QualifiedModuleName) Morphir.IR.Name.Name Morphir.IR.KindOfName.KindOfName
| LocalNameNotImported Morphir.IR.Name.Name Morphir.IR.KindOfName.KindOfName
| ImportedModuleNotFound QualifiedModuleName
| ImportedLocalNameNotFound QualifiedModuleName Morphir.IR.Name.Name Morphir.IR.KindOfName.KindOfName
| ImportingConstructorsOfNonCustomType QualifiedModuleName Morphir.IR.Name.Name
Type that represents all the possible errors during the name resolution process. Here are the possible errors:
- NoMorphirPackageFoundForElmModule
- Reported during the process of mapping the Elm module name into a pair of Morphir package and module name.
- Arguments: Elm module name
- ModuleNotImported
- Reported when the module that a name refers to is not mentioned in the imports
- Arguments: Elm module name
- ModuleOrAliasNotImported
- Reported when a single name module prefix is not found in the imports. This could either refer to an alias or a
top-level module but we don't know which one since it's not imported.
- Arguments: Elm module name or alias
- ModuleDoesNotExposeLocalName
- Reported when we know which module a name is supposed to be in but that module does not expose or doesn't contain
that name.
- Arguments: package name, module name, local name, kind of name (type, constructor or value)
- ModulesDoNotExposeLocalName
- Reported when it's not clear which module should contain the local name but neither contains or exposes it.
- Arguments: the alias that was used in the Elm code, matching module names, local name, kind of name (type, constructor or value)
- MultipleModulesExposeLocalName
- Reported when multiple modules expose the local name and it's unclear which one the user meant.
- Arguments: matching module names, local name, kind of name (type, constructor or value)
- LocalNameNotImported
- Reported when a local name is not found in the imports.
- Arguments: local name, kind of name (type, constructor or value)
- ImportedModuleNotFound
- Reported when a module is imported but not available in the Repo.
- Arguments: package and module name
- ImportedLocalNameNotFound
- Reported when a local name is imported but not found in the Repo.
- Arguments: package and module name, local name, kind of name (type, constructor or value)
- ImportingConstructorsOfNonCustomType
- Reported when an import is trying to expose constructors of a type but the type name does not refer to a custom type
- Arguments: package and module name, local name