libhbb-0.4.1.0: Backend for text editors to provide better Haskell editing support.

Safe HaskellNone

Language.Haskell.HBB.Inline

Synopsis

Documentation

inline :: [String] -> InlineOptions -> FilePath -> BufLoc -> Maybe BufLoc -> IO (BufSpan, String)Source

This function implements the mode inline.

Inline takes a location or a span within a file which should be a function binding (as of 2014-09-16 excluding any parameter) and tries to produce an inlined version of the function. The inlined version of the function then is written to standard output.

 main :: IO ()
 main = inline ["-iexample"] defaultInlineOptions "example/Example.hs" (BufLoc 14 13)

It is important to know that the indentation of non-first lines (as of 2014-09-16) is always adapted to match the indentation of the location where the name should be replaced. If a second location isn't passed this function will use GHCs lexer to find out where the end of the variable or function name is. Consequently to inline a function and to simultaneously apply it to its arguments (which is not supported as of 2014-09-16) the second location must be passed.

The first three command line parameters are:

  • The GHC options as string list (as they should appear on the command line)
  • Some options to the mode inline that change the functions behaviour
  • The path to the GHC library folder (the module GHC.Paths exports libdir which can be used here)

inlineM :: GhcMonad m => InlineOptions -> FilePath -> BufLoc -> Maybe BufLoc -> m (BufSpan, String)Source

This is the monadic version of inline.

Instead of taking command line flags to alter the GHC environment this function can be used with a custom GhcMonad instance which allows more control about GHCs behaviour.

showInlineResult :: (BufSpan, String) -> StringSource

This function creates a string of the result returned by inline or inlineM.

The string has exactly the format that should be understood by text editors that are using the mode inline.

data BufLoc Source

This is just the combination of a line number and a column number.

Constructors

BufLoc Int Int

BufLoc line column

Instances

Eq BufLoc 
Data BufLoc 
Ord BufLoc 
Show BufLoc

BufLocs are shown by separating the line and the column number by a colon.

Typeable BufLoc 

data BufSpan Source

A BufSpan is simply defined by two times a BufLoc.

Constructors

BufSpan BufLoc BufLoc

BufSpan startLoc endLoc

Instances

Eq BufSpan 
Data BufSpan 
Show BufSpan 
Typeable BufSpan 

data NonFirstLinesIndenting Source

Instances of this data type control whether the non-first lines of a binding in mode inline or smart-inline should get some extra indentation to match the environment of the place where the binding should be written to.

Assumed that the following call to factorial should get inlined:

 result = factorial 3

The function factorial looks this way:

 factorial 1 = 1
 factorial x = x * factorial (x-1)

The lambda function that is produced in mode inline with IgnoreIndOfTargetEnv looks as follows:

 (x -> case x of 1 -> 1
                  y -> y * factorial (y - 1))

The lambda function produced in mode inline with AdaptIndToTargetEnv looks as follows:

 (x -> case x of 1 -> 1
                           y -> y * factorial (y - 1))

Constructors

AdaptIndToTargetEnv

Increase indentation of non-first lines by the column number the inlined version of the the function starts at (short: adapt indentation to caller environment)

IgnoreIndOfTargetEnv

Preserve indentation which means don't adapt the indentation to the environment of the caller.

data InlineOptions Source

The data type InlineOptions is to alter the behviour of the function inline.

If showContext is true inline not only prints the inlined version of the function or value binding but also the file context.

If showAnsiColored is true inline will use ANSI terminal colors to highlight different logical informations in the inlined version. Colors are used for areas that are identical with the original function or value binding (displays) and a bold grey is used for areas that have been added and do not occur in the original binding (additions).

defaultInlineOptions :: InlineOptionsSource

This value defines the default options for inlining.

Most text editors will need these settings (maybe adaptToTargetEnv should be adapted). The inlined version of the function or value binding is printed without ANSI colors and without context but with non-first lines being indented to a level that allows a text editor to replace the original name with the return value of mode inline.