ihaskell-0.9.0.3: A Haskell backend kernel for the IPython project.

Safe HaskellNone
LanguageHaskell2010

IHaskell.Eval.Parser

Synopsis

Documentation

parseString :: String -> Ghc [Located CodeBlock] #

Parse a string into code blocks.

data CodeBlock #

A block of code to be evaluated. Each block contains a single element - one declaration, statement, expression, etc. If parsing of the block failed, the block is instead a ParseError, which has the error location and error message.

Constructors

Expression String

A Haskell expression.

Declaration String

A data type or function declaration.

Statement String

A Haskell statement (as if in a `do` block).

Import String

An import statement.

TypeSignature String

A lonely type signature (not above a function declaration).

Directive DirectiveType String

An IHaskell directive.

Module String

A full Haskell module, to be compiled and loaded.

ParseError StringLoc ErrMsg

An error indicating that parsing the code block failed.

Pragma PragmaType [String]

A list of GHC pragmas (from a {--} block)

data StringLoc :: * #

A location in an input string.

data DirectiveType #

Directive types. Each directive is associated with a string in the directive code block.

Constructors

GetType

Get the type of an expression via ':type' (or unique prefixes)

GetInfo

Get info about the identifier via ':info' (or unique prefixes)

SetDynFlag

Enable or disable an extensions, packages etc. via `:set`. Emulates GHCi's `:set`

LoadFile

Load a Haskell module.

SetOption

Set IHaskell kernel option `:option`.

SetExtension

`:extension Foo` is a shortcut for `:set -XFoo`

ShellCmd

Execute a shell command.

GetHelp

General help via :? or ':help'.

SearchHoogle

Search for something via Hoogle.

GetDoc

Get documentation for an identifier via Hoogle.

GetKind

Get the kind of a type via ':kind'.

LoadModule

Load and unload modules via ':module'.

type LineNumber = Int #

A line number in an input string.

type ColumnNumber = Int #

A column number in an input string.

type ErrMsg = String #

An error message string.

layoutChunks :: String -> [Located String] #

Split an input string into chunks based on indentation. A chunk is a line and all lines immediately following that are indented beyond the indentation of the first line. This parses Haskell layout rules properly, and allows using multiline expressions via indentation.

Quasiquotes are allowed via a post-processing step.

parseDirective #

Arguments

:: String

Directive string.

-> Int

Line number at which the directive appears.

-> CodeBlock

Directive code block or a parse error.

Parse a directive of the form :directiveName.

getModuleName :: GhcMonad m => String -> m [String] #

Parse a module and return the name declared in the 'module X where' line. That line is required, and if it does not exist, this will error. Names with periods in them are returned piece by piece.

data Located a :: * -> * #

Store locations along with a value.

Constructors

Located 

Fields

Instances

Functor Located 

Methods

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

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

Eq a => Eq (Located a) 

Methods

(==) :: Located a -> Located a -> Bool #

(/=) :: Located a -> Located a -> Bool #

Show a => Show (Located a) 

Methods

showsPrec :: Int -> Located a -> ShowS #

show :: Located a -> String #

showList :: [Located a] -> ShowS #

data PragmaType #

Pragma types. Only LANGUAGE pragmas are currently supported. Other pragma types are kept around as a string for error reporting.