finos / morphir-elm / Morphir.Elm.IncrementalResolve

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.


type alias ResolvedImports =
{ 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.


type alias VisibleNames =
{ 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: