ghc-7.4.1: The GHC API

Safe HaskellSafe-Infered

SrcLoc

Contents

Description

This module contains types that relate to the positions of things in source files, and allow tagging of those things with locations

Synopsis

SrcLoc

data RealSrcLoc Source

Represents a single point within a file

Constructing SrcLoc

mkGeneralSrcLoc :: FastString -> SrcLocSource

Creates a bad SrcLoc that has no detailed information about its location

noSrcLoc, interactiveSrcLoc, generatedSrcLoc :: SrcLocSource

Built-in bad SrcLoc values for particular locations

advanceSrcLoc :: RealSrcLoc -> Char -> RealSrcLocSource

Move the SrcLoc down by one line if the character is a newline, to the next 8-char tabstop if it is a tab, and across by one character in any other case

Unsafely deconstructing SrcLoc

srcLocFile :: RealSrcLoc -> FastStringSource

Gives the filename of the RealSrcLoc

srcLocLine :: RealSrcLoc -> IntSource

Raises an error when used on a bad SrcLoc

srcLocCol :: RealSrcLoc -> IntSource

Raises an error when used on a bad SrcLoc

SrcSpan

data RealSrcSpan Source

A SrcSpan delimits a portion of a text file. It could be represented by a pair of (line,column) coordinates, but in fact we optimise slightly by using more compact representations for single-line and zero-length spans, both of which are quite common.

The end position is defined to be the column after the end of the span. That is, a span of (1,1)-(1,2) is one character long, and a span of (1,1)-(1,1) is zero characters long.

Constructing SrcSpan

mkGeneralSrcSpan :: FastString -> SrcSpanSource

Create a bad SrcSpan that has not location information

mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpanSource

Create a SrcSpan between two points in a file

mkRealSrcSpan :: RealSrcLoc -> RealSrcLoc -> RealSrcSpanSource

Create a SrcSpan between two points in a file

noSrcSpan, wiredInSrcSpan :: SrcSpanSource

Built-in bad SrcSpans for common sources of location uncertainty

srcLocSpan :: SrcLoc -> SrcSpanSource

Create a SrcSpan corresponding to a single point

combineSrcSpans :: SrcSpan -> SrcSpan -> SrcSpanSource

Combines two SrcSpan into one that spans at least all the characters within both spans. Assumes the file part is the same in both inputs

Deconstructing SrcSpan

srcSpanStart :: SrcSpan -> SrcLocSource

Returns the location at the start of the SrcSpan or a bad SrcSpan if that is unavailable

srcSpanEnd :: SrcSpan -> SrcLocSource

Returns the location at the end of the SrcSpan or a bad SrcSpan if that is unavailable

srcSpanFileName_maybe :: SrcSpan -> Maybe FastStringSource

Obtains the filename for a SrcSpan if it is good

Unsafely deconstructing SrcSpan

Predicates on SrcSpan

isGoodSrcSpan :: SrcSpan -> BoolSource

Test if a SrcSpan is good, i.e. has precise location information

isOneLineSpan :: SrcSpan -> BoolSource

True if the span is known to straddle only one line. For bad SrcSpan, it returns False

Located

data GenLocated l e Source

We attach SrcSpans to lots of things, so let's have a datatype for it.

Constructors

L l e 

Instances

Typeable2 GenLocated 
Functor (GenLocated l) 
(Eq l, Eq e) => Eq (GenLocated l e) 
(Data l, Data e) => Data (GenLocated l e) 
(Ord l, Ord e) => Ord (GenLocated l e) 
(Outputable l, Outputable e) => Outputable (GenLocated l e) 

Constructing Located

Deconstructing Located

Combining and comparing Located values

eqLocated :: Eq a => Located a -> Located a -> BoolSource

Tests whether the two located things are equal

cmpLocated :: Ord a => Located a -> Located a -> OrderingSource

Tests the ordering of the two located things

addCLoc :: Located a -> Located b -> c -> Located cSource

Combine locations from two Located things and add them to a third thing

leftmost_smallest, rightmost, leftmost_largest :: SrcSpan -> SrcSpan -> OrderingSource

Alternative strategies for ordering SrcSpans

spans :: SrcSpan -> (Int, Int) -> BoolSource

Determines whether a span encloses a given line and column index

isSubspanOfSource

Arguments

:: SrcSpan

The span that may be enclosed by the other

-> SrcSpan

The span it may be enclosed by

-> Bool 

Determines whether a span is enclosed by another one