megaparsec-4.0.0: Monadic parser combinators

Copyright© 2015 Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen
LicenseBSD3
MaintainerMark Karpov <markkarpov@opmbx.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Text.Megaparsec.Pos

Description

Textual source position.

Synopsis

Documentation

data SourcePos Source

The abstract data type SourcePos represents source positions. It contains the name of the source (i.e. file name), a line number and a column number. SourcePos is an instance of the Show, Eq and Ord class.

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.

incSourceLine :: SourcePos -> Int -> SourcePos Source

Increment the line number of a source position.

incSourceColumn :: SourcePos -> Int -> SourcePos Source

Increments the column number of a source position.

setSourceName :: SourcePos -> String -> SourcePos Source

Set the name of the source.

setSourceLine :: SourcePos -> Int -> SourcePos Source

Set the line number of a source position.

setSourceColumn :: SourcePos -> Int -> SourcePos Source

Set the column number of a source position.

newPos :: String -> Int -> Int -> SourcePos Source

Create a new SourcePos with the given source name, line number and column number.

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.

updatePosChar Source

Arguments

:: Int

Tab width

-> SourcePos

Initial position

-> Char

Character at the position

-> SourcePos 

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.

updatePosString Source

Arguments

:: Int

Tab width

-> SourcePos

Initial position

-> String

String to process

-> SourcePos 

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)

defaultTabWidth :: Int Source

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.