Text.ParserCombinators.Parsec.Pos

parsec-3.1.13.0: Monadic parser combinators

Copyright | (c) Paolo Martini 2007
License | BSD-style (see the LICENSE file)
Maintainer | derek.a.elkins@gmail.com
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Text.ParserCombinators.Parsec.Pos

Description

Parsec compatibility module

Synopsis

- type SourceName = String
- type Line = Int
- type Column = Int
- data SourcePos
- sourceLine :: SourcePos -> Line
- sourceColumn :: SourcePos -> Column
- sourceName :: SourcePos -> SourceName
- incSourceLine :: SourcePos -> Line -> SourcePos
- incSourceColumn :: SourcePos -> Column -> SourcePos
- setSourceLine :: SourcePos -> Line -> SourcePos
- setSourceColumn :: SourcePos -> Column -> SourcePos
- setSourceName :: SourcePos -> SourceName -> SourcePos
- newPos :: SourceName -> Line -> Column -> SourcePos
- initialPos :: SourceName -> SourcePos
- updatePosChar :: SourcePos -> Char -> SourcePos
- updatePosString :: SourcePos -> String -> SourcePos

# Documentation

type SourceName = String #

type Line = Int #

type Column = Int #

data SourcePos #

The abstract data type `SourcePos` represents source positions. It contains the name of the source (i.e. file name), a line number and a column number. `SourcePos` is an instance of the `Show`, `Eq` and `Ord` class.

Instances

Eq SourcePos # |
Instance details Defined in Text.Parsec.Pos Methods (==) :: SourcePos -> SourcePos -> Bool # (/=) :: SourcePos -> SourcePos -> Bool #
Data SourcePos # |
Instance details Defined in Text.Parsec.Pos Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SourcePos -> c SourcePos Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SourcePos Source # toConstr :: SourcePos -> Constr Source # dataTypeOf :: SourcePos -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SourcePos) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SourcePos) Source # gmapT :: (forall b. Data b => b -> b) -> SourcePos -> SourcePos Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SourcePos -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SourcePos -> r Source # gmapQ :: (forall d. Data d => d -> u) -> SourcePos -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> SourcePos -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos Source #
Ord SourcePos # |
Instance details Defined in Text.Parsec.Pos Methods compare :: SourcePos -> SourcePos -> Ordering # (<) :: SourcePos -> SourcePos -> Bool # (<=) :: SourcePos -> SourcePos -> Bool # (>) :: SourcePos -> SourcePos -> Bool # (>=) :: SourcePos -> SourcePos -> Bool # max :: SourcePos -> SourcePos -> SourcePos # min :: SourcePos -> SourcePos -> SourcePos #
Show SourcePos # |
Instance details Defined in Text.Parsec.Pos Methods showsPrec :: Int -> SourcePos -> ShowS Source # show :: SourcePos -> String Source # showList :: [SourcePos] -> ShowS Source #

sourceLine :: SourcePos -> Line #

Extracts the line number from a source position.

sourceColumn :: SourcePos -> Column #

Extracts the column number from a source position.

sourceName :: SourcePos -> SourceName #

Extracts the name of the source from a source position.

incSourceLine :: SourcePos -> Line -> SourcePos #

Increments the line number of a source position.

incSourceColumn :: SourcePos -> Column -> SourcePos #

Increments the column number of a source position.

setSourceLine :: SourcePos -> Line -> SourcePos #

Set the line number of a source position.

setSourceColumn :: SourcePos -> Column -> SourcePos #

Set the column number of a source position.

setSourceName :: SourcePos -> SourceName -> SourcePos #

Set the name of the source.

newPos :: SourceName -> Line -> Column -> SourcePos #

Create a new `SourcePos` with the given source name, line number and column number.

initialPos :: SourceName -> SourcePos #

Create a new `SourcePos` with the given source name, and line number and column number set to 1, the upper left.

updatePosChar :: SourcePos -> Char -> SourcePos #

Update a source position given a character. If the character is a newline ('\n') or carriage return ('\r') the line number is incremented by 1. If the character is a tab ('t') the column number is incremented to the nearest 8'th column, ie. `column + 8 - ((column-1) `mod` 8)`. In all other cases, the column is incremented by 1.

updatePosString :: SourcePos -> String -> SourcePos #

The expression `updatePosString pos s` updates the source position `pos` by calling `updatePosChar` on every character in `s`, ie. `foldl updatePosChar pos string`.