haskell-names-0.6.0: Name resolution library for Haskell

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.Names

Contents

Synopsis

Functions

resolve :: (Data l, Eq l) => [Module l] -> Environment -> Environment Source

Takes a list of modules and an environment and updates the environment with each of the given modules' exported symbols.

annotate :: (Data l, Eq l, SrcInfo l) => Environment -> Module l -> Module (Scoped l) Source

Annotate a module with scoping information using the given environment. All imports of the given module should be in the environment.

Types

type Environment = Map ModuleName [Symbol] Source

A map from module name to list of symbols it exports.

data Symbol Source

Information about an entity. Carries at least the module it was originally declared in and its name.

Constructors

Value

value or function

Method

class method

Selector

record field selector

Constructor

data constructor

Type

type synonym

Data

data type

NewType

newtype

TypeFam

type family

DataFam

data family

Class

type class

data Scoped l Source

A pair of the name information and original annotation. Used as an annotation type for AST.

Constructors

Scoped (NameInfo l) l 

data NameInfo l Source

Information about the names used in an AST.

Constructors

GlobalSymbol Symbol QName

global entitiy and the way it is referenced

LocalValue SrcLoc

local value, and location where it is bound

TypeVar SrcLoc

type variable, and location where it is bound

ValueBinder

here the value name is bound

TypeBinder

here the type name is defined

Import (Map QName [Symbol])

import declaration, and the table of symbols that it introduces

ImportPart [Symbol]

part of an import declaration

Export [Symbol]

part of an export declaration

RecPatWildcard [Symbol]

wildcard in a record pattern. The list contains resolved names of the fields that are brought in scope by this pattern.

RecExpWildcard [(Name, NameInfo l)]

wildcard in a record construction expression. The list contains resolved names of the fields and information about values assigned to those fields.

None

no annotation

ScopeError (Error l)

scope error

data Error l Source

Errors during name resolution.

Constructors

ENotInScope (QName l)

name is not in scope

EAmbiguous (QName l) [Symbol]

name is ambiguous

ETypeAsClass (QName l)

type is used where a type class is expected

EClassAsType (QName l)

type class is used where a type is expected

ENotExported (Maybe (Name l)) (Name l) (ModuleName l)

Attempt to explicitly import a name which is not exported (or, possibly, does not even exist). For example:

import Prelude(Bool(Right))

The fields are:

  1. optional parent in the import list, e.g. Bool in Bool(Right)
  2. the name which is not exported
  3. the module which does not export the name
EModNotFound (ModuleName l)

module not found

EInternal String

internal error

Reading and writing environments

readSymbols :: FilePath -> IO [Symbol] Source

Read symbols from a file.

writeSymbols :: FilePath -> [Symbol] -> IO () Source

Write symbols to a file.

loadBase :: IO Environment Source

Load a basic environment that contains modules very similar to GHC's base package.

Pretty printing

ppError :: SrcInfo l => Error l -> String Source

Display an error.

Note: can span multiple lines; the trailing newline is included.

ppSymbol :: Symbol -> String Source

Pretty print a symbol.