Copyright | © 2015–present Megaparsec contributors |
---|---|
License | FreeBSD |
Maintainer | Mark Karpov <markkarpov92@gmail.com> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
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
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 # | |
Data Pos Source # | |
Defined in Text.Megaparsec.Pos 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 :: forall r r'. (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 # | |
Read Pos Source # | |
Show Pos Source # | |
Generic Pos Source # | |
Semigroup Pos Source # | |
NFData Pos Source # | |
Defined in Text.Megaparsec.Pos |
|
type Rep Pos Source # | |
Defined in Text.Megaparsec.Pos |
Construction of
Pos
from
Int
. The function throws
InvalidPosException
when given a non-positive argument.
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
InvalidPosException Int |
Contains the actual value that was passed to
|
Instances
Source position
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.
SourcePos | |
|
Instances
Eq SourcePos Source # | |
Data SourcePos Source # | |
Defined in Text.Megaparsec.Pos 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 :: forall r r'. (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 # | |
Defined in Text.Megaparsec.Pos |
|
Read SourcePos Source # | |
Show SourcePos Source # | |
Generic SourcePos Source # | |
NFData SourcePos Source # | |
Defined in Text.Megaparsec.Pos |
|
type Rep SourcePos Source # | |
Defined in Text.Megaparsec.Pos
type
Rep
SourcePos
=
D1
('
MetaData
"SourcePos" "Text.Megaparsec.Pos" "megaparsec-9.2.1-EI4cRL0SAfYAOxBOfPeCV9" '
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.