Toml.Syntax.Position

toml-parser-2.0.1.0: TOML 1.0.0 parser

Copyright | (c) Eric Mertens 2023
License | ISC
Maintainer | emertens@gmail.com
Safe Haskell | None
Language | Haskell2010

Toml.Syntax.Position

Description

This module provides the `Position` type for tracking locations in files while doing lexing and parsing for providing more useful error messages.

This module assumes 8 column wide tab stops.

Synopsis

- data Located a = Located {
  - locPosition :: !Position
  - locThing :: !a
  }
- data Position = Position {
  - posIndex :: !Int
  - posLine :: !Int
  - posColumn :: !Int
  }
- startPos :: Position
- move :: Char -> Position -> Position

# Documentation

data Located a #

A value annotated with its text file position

Constructors

Located |
Fields locPosition :: !Position position locThing :: !a thing at position

#### Instances

Instances details

Functor Located # | Default instance
Instance details Defined in Toml.Syntax.Position Methods fmap :: (a -> b) -> Located a -> Located b # (<$) :: a -> Located b -> Located a #
Foldable Located # | Default instance
Instance details Defined in Toml.Syntax.Position Methods fold :: Monoid m => Located m -> m # foldMap :: Monoid m => (a -> m) -> Located a -> m # foldMap' :: Monoid m => (a -> m) -> Located a -> m # foldr :: (a -> b -> b) -> b -> Located a -> b # foldr' :: (a -> b -> b) -> b -> Located a -> b # foldl :: (b -> a -> b) -> b -> Located a -> b # foldl' :: (b -> a -> b) -> b -> Located a -> b # foldr1 :: (a -> a -> a) -> Located a -> a # foldl1 :: (a -> a -> a) -> Located a -> a # toList :: Located a -> [a] # null :: Located a -> Bool # length :: Located a -> Int # elem :: Eq a => a -> Located a -> Bool # maximum :: Ord a => Located a -> a # minimum :: Ord a => Located a -> a # sum :: Num a => Located a -> a # product :: Num a => Located a -> a #
Traversable Located # | Default instance
Instance details Defined in Toml.Syntax.Position Methods traverse :: Applicative f => (a -> f b) -> Located a -> f (Located b) # sequenceA :: Applicative f => Located (f a) -> f (Located a) # mapM :: Monad m => (a -> m b) -> Located a -> m (Located b) # sequence :: Monad m => Located (m a) -> m (Located a) #
Read a => Read (Located a) # | Default instance
Instance details Defined in Toml.Syntax.Position Methods readsPrec :: Int -> ReadS (Located a) # readList :: ReadS [Located a] # readPrec :: ReadPrec (Located a) # readListPrec :: ReadPrec [Located a] #
Show a => Show (Located a) # | Default instance
Instance details Defined in Toml.Syntax.Position Methods showsPrec :: Int -> Located a -> ShowS # show :: Located a -> String # showList :: [Located a] -> ShowS #

data Position #

A position in a text file

Constructors

Position |
Fields posIndex :: !Int code-point index (zero-based) posLine :: !Int line index (one-based) posColumn :: !Int column index (one-based)

#### Instances

Instances details

Read Position # | Default instance
Instance details Defined in Toml.Syntax.Position Methods readsPrec :: Int -> ReadS Position # readList :: ReadS [Position] # readPrec :: ReadPrec Position # readListPrec :: ReadPrec [Position] #
Show Position # | Default instance
Instance details Defined in Toml.Syntax.Position Methods showsPrec :: Int -> Position -> ShowS # show :: Position -> String # showList :: [Position] -> ShowS #
Eq Position # | Default instance
Instance details Defined in Toml.Syntax.Position Methods (==) :: Position -> Position -> Bool # (/=) :: Position -> Position -> Bool #
Ord Position # | Default instance
Instance details Defined in Toml.Syntax.Position Methods compare :: Position -> Position -> Ordering # (<) :: Position -> Position -> Bool # (<=) :: Position -> Position -> Bool # (>) :: Position -> Position -> Bool # (>=) :: Position -> Position -> Bool # max :: Position -> Position -> Position # min :: Position -> Position -> Position #

startPos :: Position #

The initial `Position` for the start of a file

move :: Char -> Position -> Position #

Adjust a file position given a single character handling newlines and tabs. All other characters are considered to fill exactly one column.