| Copyright | © 2015–2016 Megaparsec contributors |
|---|---|
| License | FreeBSD |
| Maintainer | Mark Karpov <[email protected]> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.Megaparsec.Pos
Description
Textual source position. The position includes name of file, line number, and column number. List of such positions can be used to model stack of include files.
- data Pos
- mkPos :: (Integral a, MonadThrow m) => a -> m Pos
- unPos :: Pos -> Word
- unsafePos :: Word -> Pos
- data InvalidPosException = InvalidPosException
- data SourcePos = SourcePos {
- sourceName :: FilePath
- sourceLine :: !Pos
- sourceColumn :: !Pos
- initialPos :: String -> SourcePos
- sourcePosPretty :: SourcePos -> String
- defaultUpdatePos :: Pos -> SourcePos -> Char -> (SourcePos, SourcePos)
- defaultTabWidth :: Pos
Abstract position
mkPos :: (Integral a, MonadThrow m) => a -> m Pos Source #
Construction of Pos from an instance of Integral. The function
throws InvalidPosException when given non-positive argument. Note that
the function is polymorphic with respect to MonadThrow m, so you can
get result inside of Maybe, for example.
Since: 5.0.0
unsafePos :: Word -> Pos Source #
Dangerous construction of Pos. Use when you know for sure that
argument is positive.
Since: 5.0.0
data InvalidPosException Source #
The exception is thrown by mkPos when its argument is not a positive
number.
Since: 5.0.0
Constructors
| InvalidPosException |
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.
Constructors
| SourcePos | |
Fields
| |
initialPos :: String -> SourcePos Source #
Construct initial position (line 1, column 1) given name of source file.
Helpers implementing default behaviors
Arguments
| :: Pos | Tab width |
| -> SourcePos | Current position |
| -> Char | Current token |
| -> (SourcePos, SourcePos) | Actual position and incremented position |
Update a source position given a character. The first argument specifies tab width. If the character is a newline ('\n') the line number is incremented by 1. If the character is a tab ('\t') the column number is incremented to the nearest tab position. In all other cases, the column is incremented by 1.
Since: 5.0.0
defaultTabWidth :: Pos Source #
Value of tab width used by default. Always prefer this constant when
you want to refer to default tab width because actual value may change
in future. Current value is 8.