Text.Megaparsec.Pos

megaparsec-9.7.0: Monadic parser combinators

Copyright | © 2015–present Megaparsec contributors
License | FreeBSD
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | Safe
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 #

`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

Instances details

NFData Pos # |
Instance details Defined in Text.Megaparsec.Pos Methods rnf :: Pos -> () #
Semigroup Pos # |
Instance details Defined in Text.Megaparsec.Pos Methods (<>) :: Pos -> Pos -> Pos # sconcat :: NonEmpty Pos -> Pos # stimes :: Integral b => b -> Pos -> Pos #
Data Pos # |
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 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Pos # toConstr :: Pos -> Constr # dataTypeOf :: Pos -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Pos) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Pos) # gmapT :: (forall b. Data b => b -> b) -> Pos -> Pos # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pos -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pos -> r # gmapQ :: (forall d. Data d => d -> u) -> Pos -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Pos -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Pos -> m Pos # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Pos -> m Pos # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Pos -> m Pos #
Generic Pos # |
Instance details Defined in Text.Megaparsec.Pos Associated Types
type Rep Pos |
Instance details Defined in Text.Megaparsec.Pos type Rep Pos = D1 ('MetaData "Pos" "Text.Megaparsec.Pos" "megaparsec-9.7.0-CbJmYAiMrhRJAq8uh4lqvD" 'True) (C1 ('MetaCons "Pos" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
Methods from :: Pos -> Rep Pos x # to :: Rep Pos x -> Pos #
Read Pos # |
Instance details Defined in Text.Megaparsec.Pos Methods readsPrec :: Int -> ReadS Pos # readList :: ReadS [Pos] # readPrec :: ReadPrec Pos # readListPrec :: ReadPrec [Pos] #
Show Pos # |
Instance details Defined in Text.Megaparsec.Pos Methods showsPrec :: Int -> Pos -> ShowS # show :: Pos -> String # showList :: [Pos] -> ShowS #
Eq Pos # |
Instance details Defined in Text.Megaparsec.Pos Methods (==) :: Pos -> Pos -> Bool # (/=) :: Pos -> Pos -> Bool #
Ord Pos # |
Instance details Defined in Text.Megaparsec.Pos Methods compare :: Pos -> Pos -> Ordering # (<) :: Pos -> Pos -> Bool # (<=) :: Pos -> Pos -> Bool # (>) :: Pos -> Pos -> Bool # (>=) :: Pos -> Pos -> Bool # max :: Pos -> Pos -> Pos # min :: Pos -> Pos -> Pos #
type Rep Pos # |
Instance details Defined in Text.Megaparsec.Pos type Rep Pos = D1 ('MetaData "Pos" "Text.Megaparsec.Pos" "megaparsec-9.7.0-CbJmYAiMrhRJAq8uh4lqvD" 'True) (C1 ('MetaCons "Pos" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

mkPos :: Int -> Pos #

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

Since: 6.0.0

unPos :: Pos -> Int #

Extract `Int` from `Pos`.

Since: 6.0.0

pos1 :: Pos #

Position with value 1.

Since: 6.0.0

defaultTabWidth :: Pos #

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 #

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

Instances details

NFData InvalidPosException # |
Instance details Defined in Text.Megaparsec.Pos Methods rnf :: InvalidPosException -> () #
Data InvalidPosException # |
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 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c InvalidPosException # toConstr :: InvalidPosException -> Constr # dataTypeOf :: InvalidPosException -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c InvalidPosException) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c InvalidPosException) # gmapT :: (forall b. Data b => b -> b) -> InvalidPosException -> InvalidPosException # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> InvalidPosException -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> InvalidPosException -> r # gmapQ :: (forall d. Data d => d -> u) -> InvalidPosException -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> InvalidPosException -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> InvalidPosException -> m InvalidPosException # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> InvalidPosException -> m InvalidPosException # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> InvalidPosException -> m InvalidPosException #
Exception InvalidPosException # |
Instance details Defined in Text.Megaparsec.Pos Methods toException :: InvalidPosException -> SomeException # fromException :: SomeException -> Maybe InvalidPosException # displayException :: InvalidPosException -> String # backtraceDesired :: InvalidPosException -> Bool #
Generic InvalidPosException # |
Instance details Defined in Text.Megaparsec.Pos Associated Types
type Rep InvalidPosException |
Instance details Defined in Text.Megaparsec.Pos type Rep InvalidPosException = D1 ('MetaData "InvalidPosException" "Text.Megaparsec.Pos" "megaparsec-9.7.0-CbJmYAiMrhRJAq8uh4lqvD" 'True) (C1 ('MetaCons "InvalidPosException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))
Methods from :: InvalidPosException -> Rep InvalidPosException x # to :: Rep InvalidPosException x -> InvalidPosException #
Show InvalidPosException # |
Instance details Defined in Text.Megaparsec.Pos Methods showsPrec :: Int -> InvalidPosException -> ShowS # show :: InvalidPosException -> String # showList :: [InvalidPosException] -> ShowS #
Eq InvalidPosException # |
Instance details Defined in Text.Megaparsec.Pos Methods (==) :: InvalidPosException -> InvalidPosException -> Bool # (/=) :: InvalidPosException -> InvalidPosException -> Bool #
type Rep InvalidPosException # |
Instance details Defined in Text.Megaparsec.Pos type Rep InvalidPosException = D1 ('MetaData "InvalidPosException" "Text.Megaparsec.Pos" "megaparsec-9.7.0-CbJmYAiMrhRJAq8uh4lqvD" 'True) (C1 ('MetaCons "InvalidPosException" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int)))

# Source position

data SourcePos #

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

Instances details

NFData SourcePos # |
Instance details Defined in Text.Megaparsec.Pos Methods rnf :: SourcePos -> () #
Data SourcePos # |
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 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SourcePos # toConstr :: SourcePos -> Constr # dataTypeOf :: SourcePos -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SourcePos) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SourcePos) # gmapT :: (forall b. Data b => b -> b) -> SourcePos -> SourcePos # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SourcePos -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SourcePos -> r # gmapQ :: (forall d. Data d => d -> u) -> SourcePos -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> SourcePos -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SourcePos -> m SourcePos #
Generic SourcePos # |
Instance details Defined in Text.Megaparsec.Pos Associated Types
type Rep SourcePos |
Instance details Defined in Text.Megaparsec.Pos type Rep SourcePos = D1 ('MetaData "SourcePos" "Text.Megaparsec.Pos" "megaparsec-9.7.0-CbJmYAiMrhRJAq8uh4lqvD" '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))))
Methods from :: SourcePos -> Rep SourcePos x # to :: Rep SourcePos x -> SourcePos #
Read SourcePos # |
Instance details Defined in Text.Megaparsec.Pos Methods readsPrec :: Int -> ReadS SourcePos # readList :: ReadS [SourcePos] # readPrec :: ReadPrec SourcePos # readListPrec :: ReadPrec [SourcePos] #
Show SourcePos # |
Instance details Defined in Text.Megaparsec.Pos Methods showsPrec :: Int -> SourcePos -> ShowS # show :: SourcePos -> String # showList :: [SourcePos] -> ShowS #
Eq SourcePos # |
Instance details Defined in Text.Megaparsec.Pos Methods (==) :: SourcePos -> SourcePos -> Bool # (/=) :: SourcePos -> SourcePos -> Bool #
Ord SourcePos # |
Instance details Defined in Text.Megaparsec.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 #
type Rep SourcePos # |
Instance details Defined in Text.Megaparsec.Pos type Rep SourcePos = D1 ('MetaData "SourcePos" "Text.Megaparsec.Pos" "megaparsec-9.7.0-CbJmYAiMrhRJAq8uh4lqvD" '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 #

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

sourcePosPretty :: SourcePos -> String #

Pretty-print a `SourcePos`.

Since: 5.0.0