Copyright | © 2015–2016 Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen |
---|---|
License | FreeBSD |
Maintainer | Mark Karpov <markkarpov@opmbx.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Textual source position.
- data SourcePos
- sourceName :: SourcePos -> String
- sourceLine :: SourcePos -> Int
- sourceColumn :: SourcePos -> Int
- data InvalidTextualPosition = InvalidTextualPosition String Int Int
- newPos :: String -> Int -> Int -> SourcePos
- initialPos :: String -> SourcePos
- incSourceLine :: SourcePos -> Int -> SourcePos
- incSourceColumn :: SourcePos -> Int -> SourcePos
- setSourceName :: SourcePos -> String -> SourcePos
- setSourceLine :: SourcePos -> Int -> SourcePos
- setSourceColumn :: SourcePos -> Int -> SourcePos
- updatePosChar :: Int -> SourcePos -> Char -> SourcePos
- updatePosString :: Int -> SourcePos -> String -> SourcePos
- defaultTabWidth :: Int
Documentation
sourceName :: SourcePos -> String Source
Extract the name of the source from a source position.
sourceLine :: SourcePos -> Int Source
Extract the line number from a source position.
sourceColumn :: SourcePos -> Int Source
Extract the column number from a source position.
data InvalidTextualPosition Source
This exception is thrown when some action on SourcePos
is performed
that would make column number or line number inside this data structure
non-positive.
The InvalidTextualPosition
structure includes in order:
- name of file
- line number (possibly non-positive value)
- column number (possibly non-positive value)
Create a new SourcePos
with the given source name, line number and
column number.
If line number of column number is not positive, InvalidTextualPosition
will be thrown.
initialPos :: String -> SourcePos Source
Create a new SourcePos
with the given source name, and line number
and column number set to 1, the upper left.
incSourceLine :: SourcePos -> Int -> SourcePos Source
Increment the line number of a source position. If resulting line
number is not positive, InvalidTextualPosition
will be thrown.
incSourceColumn :: SourcePos -> Int -> SourcePos Source
Increment the column number of a source position. If resulting column
number is not positive, InvalidTextualPosition
will be thrown.
setSourceName :: SourcePos -> String -> SourcePos Source
Set the name of the source.
setSourceLine :: SourcePos -> Int -> SourcePos Source
Set the line number of a source position. If the line number is not
positive, InvalidTextualPosition
will be thrown.
setSourceColumn :: SourcePos -> Int -> SourcePos Source
Set the column number of a source position. If the line number is not
positive, InvalidTextualPosition
will be thrown.
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, i.e. column +
width - ((column - 1) `rem` width)
. In all other cases, the column is
incremented by 1.
If given tab width is not positive, defaultTabWidth
will be used.
The expression updatePosString pos s
updates the source position
pos
by calling updatePosChar
on every character in s
, i.e.
updatePosString width = foldl (updatePosChar width)
Value of tab width used by default. This is used as fall-back by
updatePosChar
and possibly in other cases. Always prefer this constant
when you want to refer to default tab width because actual value may
change in future. Current value is 8
.