megaparsec-7.0.5: Monadic parser combinators

Copyright | © 2015–2019 Megaparsec contributors
License | FreeBSD
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Text.Megaparsec.Pos

Contents

- Abstract position
- Source position

Description

Textual source position. The position includes name of file, line number, and column number.

You probably do not want to import this module directly because Text.Megaparsec re-exports it anyway.

Synopsis

- data Pos
- mkPos :: Int -> Pos
- unPos :: Pos -> Int
- pos1 :: Pos
- defaultTabWidth :: Pos
- newtype InvalidPosException = InvalidPosException Int
- data SourcePos = SourcePos {
  - sourceName :: FilePath
  - sourceLine :: !Pos
  - sourceColumn :: !Pos
  }
- initialPos :: FilePath -> SourcePos
- sourcePosPretty :: SourcePos -> String

# Abstract position

data Pos Source #

`Pos` is the type for positive integers. This is used to represent line number, column number, and similar things like indentation level. `Semigroup` instance can be used to safely and efficiently add `Pos`es together.

Since: 5.0.0

Instances

Eq Pos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods (==) :: Pos -> Pos -> Bool Source # (/=) :: Pos -> Pos -> Bool Source #
Data Pos Source # |

Instance details

Defined in Text.Megaparsec.Pos

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Pos -> c Pos Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Pos Source #

toConstr :: Pos -> Constr Source #

dataTypeOf :: Pos -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Pos) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pos) Source #

gmapT :: (forall b. Data b => b -> b) -> Pos -> Pos Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pos -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pos -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Pos -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Pos -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Pos -> m Pos Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Pos -> m Pos Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Pos -> m Pos Source #

Ord Pos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods compare :: Pos -> Pos -> Ordering Source # (<) :: Pos -> Pos -> Bool Source # (<=) :: Pos -> Pos -> Bool Source # (>) :: Pos -> Pos -> Bool Source # (>=) :: Pos -> Pos -> Bool Source # max :: Pos -> Pos -> Pos Source # min :: Pos -> Pos -> Pos Source #
Read Pos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods readsPrec :: Int -> ReadS Pos Source # readList :: ReadS [Pos] Source # readPrec :: ReadPrec Pos Source # readListPrec :: ReadPrec [Pos] Source #
Show Pos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods showsPrec :: Int -> Pos -> ShowS Source # show :: Pos -> String Source # showList :: [Pos] -> ShowS Source #
Semigroup Pos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods (<>) :: Pos -> Pos -> Pos Source # sconcat :: NonEmpty Pos -> Pos Source # stimes :: Integral b => b -> Pos -> Pos Source #
NFData Pos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods rnf :: Pos -> () Source #

mkPos :: Int -> Pos Source #

Construction of `Pos` from `Int`. The function throws `InvalidPosException` when given a non-positive argument.

Since: 6.0.0

unPos :: Pos -> Int Source #

Extract `Int` from `Pos`.

Since: 6.0.0

pos1 :: Pos Source #

Position with value 1.

Since: 6.0.0

defaultTabWidth :: Pos Source #

Value of tab width used by default. Always prefer this constant when you want to refer to the default tab width because actual value may change in future.

Currently:

    defaultTabWidth = mkPos 8

Since: 5.0.0

newtype InvalidPosException Source #

The exception is thrown by `mkPos` when its argument is not a positive number.

Since: 5.0.0

Constructors

InvalidPosException Int | Contains the actual value that was passed to `mkPos`

Instances

Eq InvalidPosException Source # |
Instance details Defined in Text.Megaparsec.Pos Methods (==) :: InvalidPosException -> InvalidPosException -> Bool Source # (/=) :: InvalidPosException -> InvalidPosException -> Bool Source #
Data InvalidPosException Source # |

Instance details

Defined in Text.Megaparsec.Pos

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> InvalidPosException -> c InvalidPosException Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c InvalidPosException Source #

toConstr :: InvalidPosException -> Constr Source #

dataTypeOf :: InvalidPosException -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c InvalidPosException) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InvalidPosException) Source #

gmapT :: (forall b. Data b => b -> b) -> InvalidPosException -> InvalidPosException Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> InvalidPosException -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> InvalidPosException -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> InvalidPosException -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> InvalidPosException -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> InvalidPosException -> m InvalidPosException Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> InvalidPosException -> m InvalidPosException Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> InvalidPosException -> m InvalidPosException Source #

Show InvalidPosException Source # |
Instance details Defined in Text.Megaparsec.Pos Methods showsPrec :: Int -> InvalidPosException -> ShowS Source # show :: InvalidPosException -> String Source # showList :: [InvalidPosException] -> ShowS Source #
Generic InvalidPosException Source # |
Instance details Defined in Text.Megaparsec.Pos Associated Types type Rep InvalidPosException :: Type -> Type Source # Methods from :: InvalidPosException -> Rep InvalidPosException x Source # to :: Rep InvalidPosException x -> InvalidPosException Source #
Exception InvalidPosException Source # |
Instance details Defined in Text.Megaparsec.Pos Methods toException :: InvalidPosException -> SomeException Source # fromException :: SomeException -> Maybe InvalidPosException Source # displayException :: InvalidPosException -> String Source #
NFData InvalidPosException Source # |
Instance details Defined in Text.Megaparsec.Pos Methods rnf :: InvalidPosException -> () Source #
type Rep InvalidPosException Source # |
Instance details Defined in Text.Megaparsec.Pos type Rep InvalidPosException = D1 (MetaData "InvalidPosException" "Text.Megaparsec.Pos" "megaparsec-7.0.5-9OiUpJcOWCR1wzkkpW1WSp" True) (C1 (MetaCons "InvalidPosException" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Int)))

# Source position

data SourcePos Source #

The data type `SourcePos` represents source positions. It contains the name of the source file, a line number, and a column number. Source line and column positions change intensively during parsing, so we need to make them strict to avoid memory leaks.

Constructors

SourcePos |

Fields

- sourceName :: FilePath

  Name of source file

- sourceLine :: !Pos

  Line number

- sourceColumn :: !Pos

  Column number

Instances

Eq SourcePos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods (==) :: SourcePos -> SourcePos -> Bool Source # (/=) :: SourcePos -> SourcePos -> Bool Source #
Data SourcePos Source # |

Instance details

Defined in Text.Megaparsec.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 Source # |

Instance details

Defined in Text.Megaparsec.Pos

Methods

compare :: SourcePos -> SourcePos -> Ordering Source #

(<) :: SourcePos -> SourcePos -> Bool Source #

(<=) :: SourcePos -> SourcePos -> Bool Source #

(>) :: SourcePos -> SourcePos -> Bool Source #

(>=) :: SourcePos -> SourcePos -> Bool Source #

max :: SourcePos -> SourcePos -> SourcePos Source #

min :: SourcePos -> SourcePos -> SourcePos Source #

Read SourcePos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods readsPrec :: Int -> ReadS SourcePos Source # readList :: ReadS [SourcePos] Source # readPrec :: ReadPrec SourcePos Source # readListPrec :: ReadPrec [SourcePos] Source #
Show SourcePos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods showsPrec :: Int -> SourcePos -> ShowS Source # show :: SourcePos -> String Source # showList :: [SourcePos] -> ShowS Source #
Generic SourcePos Source # |
Instance details Defined in Text.Megaparsec.Pos Associated Types type Rep SourcePos :: Type -> Type Source # Methods from :: SourcePos -> Rep SourcePos x Source # to :: Rep SourcePos x -> SourcePos Source #
NFData SourcePos Source # |
Instance details Defined in Text.Megaparsec.Pos Methods rnf :: SourcePos -> () Source #
type Rep SourcePos Source # |

Instance details

Defined in Text.Megaparsec.Pos

type Rep SourcePos = D1 (MetaData "SourcePos" "Text.Megaparsec.Pos" "megaparsec-7.0.5-9OiUpJcOWCR1wzkkpW1WSp" False) (C1 (MetaCons "SourcePos" PrefixI True) (S1 (MetaSel (Just "sourceName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 FilePath) :*: (S1 (MetaSel (Just "sourceLine") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Pos) :*: S1 (MetaSel (Just "sourceColumn") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Pos))))

initialPos :: FilePath -> SourcePos Source #

Construct initial position (line 1, column 1) given name of source file.

sourcePosPretty :: SourcePos -> String Source #

Pretty-print a `SourcePos`.

Since: 5.0.0