haskell-names-0.9.1: 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. The modules can appear in any order and can be mutually recursive.

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

Fields

Method

class method

Fields

Selector

record field selector

Fields

Constructor

data constructor

Fields

Type

type synonym

Fields

Data

data type

Fields

NewType

newtype

Fields

TypeFam

type family

Fields

DataFam

data family

Fields

Class

type class

Fields

PatternConstructor

pattern synonym constructor

PatternSelector

pattern synonym selector

Instances

Eq Symbol Source # 

Methods

(==) :: Symbol -> Symbol -> Bool #

(/=) :: Symbol -> Symbol -> Bool #

Data Symbol Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Symbol -> c Symbol #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Symbol #

toConstr :: Symbol -> Constr #

dataTypeOf :: Symbol -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Symbol) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Symbol) #

gmapT :: (forall b. Data b => b -> b) -> Symbol -> Symbol #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Symbol -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Symbol -> r #

gmapQ :: (forall d. Data d => d -> u) -> Symbol -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Symbol -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Symbol -> m Symbol #

Ord Symbol Source # 
Show Symbol Source # 

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 

Instances

Functor Scoped Source # 

Methods

fmap :: (a -> b) -> Scoped a -> Scoped b #

(<$) :: a -> Scoped b -> Scoped a #

Foldable Scoped Source # 

Methods

fold :: Monoid m => Scoped m -> m #

foldMap :: Monoid m => (a -> m) -> Scoped a -> m #

foldr :: (a -> b -> b) -> b -> Scoped a -> b #

foldr' :: (a -> b -> b) -> b -> Scoped a -> b #

foldl :: (b -> a -> b) -> b -> Scoped a -> b #

foldl' :: (b -> a -> b) -> b -> Scoped a -> b #

foldr1 :: (a -> a -> a) -> Scoped a -> a #

foldl1 :: (a -> a -> a) -> Scoped a -> a #

toList :: Scoped a -> [a] #

null :: Scoped a -> Bool #

length :: Scoped a -> Int #

elem :: Eq a => a -> Scoped a -> Bool #

maximum :: Ord a => Scoped a -> a #

minimum :: Ord a => Scoped a -> a #

sum :: Num a => Scoped a -> a #

product :: Num a => Scoped a -> a #

Traversable Scoped Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Scoped a -> f (Scoped b) #

sequenceA :: Applicative f => Scoped (f a) -> f (Scoped a) #

mapM :: Monad m => (a -> m b) -> Scoped a -> m (Scoped b) #

sequence :: Monad m => Scoped (m a) -> m (Scoped a) #

Eq l => Eq (Scoped l) Source # 

Methods

(==) :: Scoped l -> Scoped l -> Bool #

(/=) :: Scoped l -> Scoped l -> Bool #

Data l => Data (Scoped l) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Scoped l -> c (Scoped l) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Scoped l) #

toConstr :: Scoped l -> Constr #

dataTypeOf :: Scoped l -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Scoped l)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Scoped l)) #

gmapT :: (forall b. Data b => b -> b) -> Scoped l -> Scoped l #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Scoped l -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Scoped l -> r #

gmapQ :: (forall d. Data d => d -> u) -> Scoped l -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Scoped l -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Scoped l -> m (Scoped l) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Scoped l -> m (Scoped l) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Scoped l -> m (Scoped l) #

Ord l => Ord (Scoped l) Source # 

Methods

compare :: Scoped l -> Scoped l -> Ordering #

(<) :: Scoped l -> Scoped l -> Bool #

(<=) :: Scoped l -> Scoped l -> Bool #

(>) :: Scoped l -> Scoped l -> Bool #

(>=) :: Scoped l -> Scoped l -> Bool #

max :: Scoped l -> Scoped l -> Scoped l #

min :: Scoped l -> Scoped l -> Scoped l #

Show l => Show (Scoped l) Source # 

Methods

showsPrec :: Int -> Scoped l -> ShowS #

show :: Scoped l -> String #

showList :: [Scoped l] -> ShowS #

SrcInfo l => SrcInfo (Scoped l) Source # 

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 [(Symbol, 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

Instances

Functor NameInfo Source # 

Methods

fmap :: (a -> b) -> NameInfo a -> NameInfo b #

(<$) :: a -> NameInfo b -> NameInfo a #

Foldable NameInfo Source # 

Methods

fold :: Monoid m => NameInfo m -> m #

foldMap :: Monoid m => (a -> m) -> NameInfo a -> m #

foldr :: (a -> b -> b) -> b -> NameInfo a -> b #

foldr' :: (a -> b -> b) -> b -> NameInfo a -> b #

foldl :: (b -> a -> b) -> b -> NameInfo a -> b #

foldl' :: (b -> a -> b) -> b -> NameInfo a -> b #

foldr1 :: (a -> a -> a) -> NameInfo a -> a #

foldl1 :: (a -> a -> a) -> NameInfo a -> a #

toList :: NameInfo a -> [a] #

null :: NameInfo a -> Bool #

length :: NameInfo a -> Int #

elem :: Eq a => a -> NameInfo a -> Bool #

maximum :: Ord a => NameInfo a -> a #

minimum :: Ord a => NameInfo a -> a #

sum :: Num a => NameInfo a -> a #

product :: Num a => NameInfo a -> a #

Traversable NameInfo Source # 

Methods

traverse :: Applicative f => (a -> f b) -> NameInfo a -> f (NameInfo b) #

sequenceA :: Applicative f => NameInfo (f a) -> f (NameInfo a) #

mapM :: Monad m => (a -> m b) -> NameInfo a -> m (NameInfo b) #

sequence :: Monad m => NameInfo (m a) -> m (NameInfo a) #

Eq l => Eq (NameInfo l) Source # 

Methods

(==) :: NameInfo l -> NameInfo l -> Bool #

(/=) :: NameInfo l -> NameInfo l -> Bool #

Data l => Data (NameInfo l) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> NameInfo l -> c (NameInfo l) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (NameInfo l) #

toConstr :: NameInfo l -> Constr #

dataTypeOf :: NameInfo l -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (NameInfo l)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (NameInfo l)) #

gmapT :: (forall b. Data b => b -> b) -> NameInfo l -> NameInfo l #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NameInfo l -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NameInfo l -> r #

gmapQ :: (forall d. Data d => d -> u) -> NameInfo l -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> NameInfo l -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> NameInfo l -> m (NameInfo l) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> NameInfo l -> m (NameInfo l) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> NameInfo l -> m (NameInfo l) #

Ord l => Ord (NameInfo l) Source # 

Methods

compare :: NameInfo l -> NameInfo l -> Ordering #

(<) :: NameInfo l -> NameInfo l -> Bool #

(<=) :: NameInfo l -> NameInfo l -> Bool #

(>) :: NameInfo l -> NameInfo l -> Bool #

(>=) :: NameInfo l -> NameInfo l -> Bool #

max :: NameInfo l -> NameInfo l -> NameInfo l #

min :: NameInfo l -> NameInfo l -> NameInfo l #

Show l => Show (NameInfo l) Source # 

Methods

showsPrec :: Int -> NameInfo l -> ShowS #

show :: NameInfo l -> String #

showList :: [NameInfo l] -> ShowS #

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

Instances

Functor Error Source # 

Methods

fmap :: (a -> b) -> Error a -> Error b #

(<$) :: a -> Error b -> Error a #

Foldable Error Source # 

Methods

fold :: Monoid m => Error m -> m #

foldMap :: Monoid m => (a -> m) -> Error a -> m #

foldr :: (a -> b -> b) -> b -> Error a -> b #

foldr' :: (a -> b -> b) -> b -> Error a -> b #

foldl :: (b -> a -> b) -> b -> Error a -> b #

foldl' :: (b -> a -> b) -> b -> Error a -> b #

foldr1 :: (a -> a -> a) -> Error a -> a #

foldl1 :: (a -> a -> a) -> Error a -> a #

toList :: Error a -> [a] #

null :: Error a -> Bool #

length :: Error a -> Int #

elem :: Eq a => a -> Error a -> Bool #

maximum :: Ord a => Error a -> a #

minimum :: Ord a => Error a -> a #

sum :: Num a => Error a -> a #

product :: Num a => Error a -> a #

Traversable Error Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Error a -> f (Error b) #

sequenceA :: Applicative f => Error (f a) -> f (Error a) #

mapM :: Monad m => (a -> m b) -> Error a -> m (Error b) #

sequence :: Monad m => Error (m a) -> m (Error a) #

Eq l => Eq (Error l) Source # 

Methods

(==) :: Error l -> Error l -> Bool #

(/=) :: Error l -> Error l -> Bool #

Data l => Data (Error l) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Error l -> c (Error l) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Error l) #

toConstr :: Error l -> Constr #

dataTypeOf :: Error l -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Error l)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Error l)) #

gmapT :: (forall b. Data b => b -> b) -> Error l -> Error l #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Error l -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Error l -> r #

gmapQ :: (forall d. Data d => d -> u) -> Error l -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Error l -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Error l -> m (Error l) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Error l -> m (Error l) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Error l -> m (Error l) #

Ord l => Ord (Error l) Source # 

Methods

compare :: Error l -> Error l -> Ordering #

(<) :: Error l -> Error l -> Bool #

(<=) :: Error l -> Error l -> Bool #

(>) :: Error l -> Error l -> Bool #

(>=) :: Error l -> Error l -> Bool #

max :: Error l -> Error l -> Error l #

min :: Error l -> Error l -> Error l #

Show l => Show (Error l) Source # 

Methods

showsPrec :: Int -> Error l -> ShowS #

show :: Error l -> String #

showList :: [Error l] -> ShowS #

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.