Language.Haskell.Exts.SrcLoc

haskell-src-exts-1.17.1: Manipulating Haskell source: abstract syntax, lexer, parser, and pretty-printer

Copyright | (c) Niklas Broberg 2009
License | BSD-style (see the file LICENSE.txt)
Maintainer | Niklas Broberg, d00nibro@chalmers.se
Stability | stable
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Language.Haskell.Exts.SrcLoc

Description

This module defines various data types representing source location information, of varying degree of preciseness.

Synopsis

- data SrcLoc = SrcLoc {
  - srcFilename :: String
  - srcLine :: Int
  - srcColumn :: Int
  }
- noLoc :: SrcLoc
- data SrcSpan = SrcSpan {
  - srcSpanFilename :: String
  - srcSpanStartLine :: Int
  - srcSpanStartColumn :: Int
  - srcSpanEndLine :: Int
  - srcSpanEndColumn :: Int
  }
- srcSpanStart :: SrcSpan -> (Int, Int)
- srcSpanEnd :: SrcSpan -> (Int, Int)
- mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan
- mergeSrcSpan :: SrcSpan -> SrcSpan -> SrcSpan
- isNullSpan :: SrcSpan -> Bool
- spanSize :: SrcSpan -> (Int, Int)
- data Loc a = Loc {
  - loc :: SrcSpan
  - unLoc :: a
  }
- data SrcSpanInfo = SrcSpanInfo {
  - srcInfoSpan :: SrcSpan
  - srcInfoPoints :: [SrcSpan]
  }
- noInfoSpan :: SrcSpan -> SrcSpanInfo
- infoSpan :: SrcSpan -> [SrcSpan] -> SrcSpanInfo
- combSpanInfo :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
- combSpanMaybe :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo
- (<++>) :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
- (<+?>) :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo
- (<?+>) :: Maybe SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo
- (<**) :: SrcSpanInfo -> [SrcSpan] -> SrcSpanInfo
- (<^^>) :: SrcSpan -> SrcSpan -> SrcSpanInfo
- class SrcInfo si where
  - toSrcInfo :: SrcLoc -> [SrcSpan] -> SrcLoc -> si
  - fromSrcInfo :: SrcSpanInfo -> si
  - getPointLoc :: si -> SrcLoc
  - fileName :: si -> String
  - startLine :: si -> Int
  - startColumn :: si -> Int

# Documentation

data SrcLoc

A single position in the source.

Constructors

SrcLoc |
Fields srcFilename :: String srcLine :: Int srcColumn :: Int

Instances

Eq SrcLoc |
Data SrcLoc |
Ord SrcLoc |
Show SrcLoc |
Generic SrcLoc |
SrcInfo SrcLoc |
Pretty SrcLoc |
type Rep SrcLoc |

noLoc :: SrcLoc

data SrcSpan

A portion of the source, spanning one or more lines and zero or more columns.

Constructors

SrcSpan |
Fields srcSpanFilename :: String srcSpanStartLine :: Int srcSpanStartColumn :: Int srcSpanEndLine :: Int srcSpanEndColumn :: Int

Instances

Eq SrcSpan |
Data SrcSpan |
Ord SrcSpan |
Show SrcSpan |
SrcInfo SrcSpan |
Pretty SrcSpan |

srcSpanStart :: SrcSpan -> (Int, Int)

Returns `srcSpanStartLine` and `srcSpanStartColumn` in a pair.

srcSpanEnd :: SrcSpan -> (Int, Int)

Returns `srcSpanEndLine` and `srcSpanEndColumn` in a pair.

mkSrcSpan :: SrcLoc -> SrcLoc -> SrcSpan

Combine two locations in the source to denote a span.

mergeSrcSpan :: SrcSpan -> SrcSpan -> SrcSpan

Merge two source spans into a single span from the start of the first to the end of the second. Assumes that the two spans relate to the same source file.

isNullSpan :: SrcSpan -> Bool

Test if a given span starts and ends at the same location.

spanSize :: SrcSpan -> (Int, Int)

data Loc a

An entity located in the source.

Constructors

Loc |
Fields loc :: SrcSpan unLoc :: a

Instances

Eq a => Eq (Loc a) |
Ord a => Ord (Loc a) |
Show a => Show (Loc a) |

data SrcSpanInfo

A portion of the source, extended with information on the position of entities within the span.

Constructors

SrcSpanInfo |
Fields srcInfoSpan :: SrcSpan srcInfoPoints :: [SrcSpan]

Instances

Eq SrcSpanInfo |
Data SrcSpanInfo |
Ord SrcSpanInfo |
Show SrcSpanInfo |
SrcInfo SrcSpanInfo |
Parseable (NonGreedy (ListOf (ModulePragma SrcSpanInfo))) |
Parseable (NonGreedy (ModuleHeadAndImports SrcSpanInfo)) |
Parseable (NonGreedy (PragmasAndModuleHead SrcSpanInfo)) |
Parseable (NonGreedy (PragmasAndModuleName SrcSpanInfo)) |

noInfoSpan :: SrcSpan -> SrcSpanInfo

Generate a `SrcSpanInfo` with no positional information for entities.

infoSpan :: SrcSpan -> [SrcSpan] -> SrcSpanInfo

Generate a `SrcSpanInfo` with the supplied positional information for entities.

combSpanInfo :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo

Combine two `SrcSpanInfo`s into one that spans the combined source area of the two arguments, leaving positional information blank.

combSpanMaybe :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo

Like '(+?)', but it also concatenates the `srcInfoPoints`.

(<++>) :: SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo infixl 5

Short name for `combSpanInfo`

(<+?>) :: SrcSpanInfo -> Maybe SrcSpanInfo -> SrcSpanInfo infixl 4

Optionally combine the first argument with the second, or return it unchanged if the second argument is `Nothing`.

(<?+>) :: Maybe SrcSpanInfo -> SrcSpanInfo -> SrcSpanInfo infixl 4

Optionally combine the second argument with the first, or return it unchanged if the first argument is `Nothing`.

(<**) :: SrcSpanInfo -> [SrcSpan] -> SrcSpanInfo infixl 4

Add more positional information for entities of a span.

(<^^>) :: SrcSpan -> SrcSpan -> SrcSpanInfo infixl 6

Merge two `SrcSpan`s and lift them to a `SrcInfoSpan` with no positional information for entities.

class SrcInfo si where

A class to work over all kinds of source location information.

Minimal complete definition

toSrcInfo, fromSrcInfo, fileName, startLine, startColumn

Methods

toSrcInfo :: SrcLoc -> [SrcSpan] -> SrcLoc -> si

fromSrcInfo :: SrcSpanInfo -> si

getPointLoc :: si -> SrcLoc

fileName :: si -> String

startLine :: si -> Int

startColumn :: si -> Int

Instances

SrcInfo SrcSpanInfo |
SrcInfo SrcSpan |
SrcInfo SrcLoc |