megaparsec-9.7.0: Monadic parser combinators

Copyright | © 2015–present Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen
License | FreeBSD
Maintainer | Mark Karpov <markkarpov92@gmail.com>
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Text.Megaparsec.State

Description

Definition of Megaparsec's `State`.

Since: 6.5.0

Synopsis

- data State s e = State {
  - stateInput :: s
  - stateOffset :: !Int
  - statePosState :: PosState s
  - stateParseErrors :: [ParseError s e]
  }
- initialState :: FilePath -> s -> State s e
- data PosState s = PosState {
  - pstateInput :: s
  - pstateOffset :: !Int
  - pstateSourcePos :: !SourcePos
  - pstateTabWidth :: Pos
  - pstateLinePrefix :: String
  }
- initialPosState :: FilePath -> s -> PosState s

# Documentation

data State s e Source #

This is the Megaparsec's state parametrized over stream type `s` and custom error component type `e`.

Constructors

State |

Fields

- stateInput :: s

  The rest of input to process

- stateOffset :: !Int

  Number of processed tokens so far

  Since: 7.0.0

- statePosState :: PosState s

  State that is used for line/column calculation

  Since: 7.0.0

- stateParseErrors :: [ParseError s e]

  Collection of “delayed” `ParseError`s in reverse order. This means that the last registered error is the first element of the list.

  Since: 8.0.0

#### Instances

Instances details

(NFData s, NFData (ParseError s e)) => NFData (State s e) Source # |
Instance details Defined in Text.Megaparsec.State Methods rnf :: State s e -> () Source #
(Data e, Data (ParseError s e), Data s) => Data (State s e) Source # |

Instance details

Defined in Text.Megaparsec.State

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> State s e -> c (State s e) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (State s e) Source #

toConstr :: State s e -> Constr Source #

dataTypeOf :: State s e -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (State s e)) Source #

dataCast2 :: Typeable t => (forall d e0. (Data d, Data e0) => c (t d e0)) -> Maybe (c (State s e)) Source #

gmapT :: (forall b. Data b => b -> b) -> State s e -> State s e Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> State s e -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> State s e -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> State s e -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> State s e -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> State s e -> m (State s e) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> State s e -> m (State s e) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> State s e -> m (State s e) Source #

Generic (State s e) Source # |

Instance details

Defined in Text.Megaparsec.State

Associated Types

type Rep (State s e) |

Instance details

Defined in Text.Megaparsec.State

type Rep (State s e) = D1 ('MetaData "State" "Text.Megaparsec.State" "megaparsec-9.7.0-BLrpTwU3VfiJJb0Dqvdds1" 'False) (C1 ('MetaCons "State" 'PrefixI 'True) ((S1 ('MetaSel ('Just "stateInput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 s) :*: S1 ('MetaSel ('Just "stateOffset") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "statePosState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PosState s)) :*: S1 ('MetaSel ('Just "stateParseErrors") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ParseError s e]))))

Methods

from :: State s e -> Rep (State s e) x Source #

to :: Rep (State s e) x -> State s e Source #

(Show (ParseError s e), Show s) => Show (State s e) Source # |
Instance details Defined in Text.Megaparsec.State Methods showsPrec :: Int -> State s e -> ShowS Source # show :: State s e -> String Source # showList :: [State s e] -> ShowS Source #
(Eq (ParseError s e), Eq s) => Eq (State s e) Source # |
Instance details Defined in Text.Megaparsec.State Methods (==) :: State s e -> State s e -> Bool Source # (/=) :: State s e -> State s e -> Bool Source #
type Rep (State s e) Source # |

Instance details

Defined in Text.Megaparsec.State

type Rep (State s e) = D1 ('MetaData "State" "Text.Megaparsec.State" "megaparsec-9.7.0-BLrpTwU3VfiJJb0Dqvdds1" 'False) (C1 ('MetaCons "State" 'PrefixI 'True) ((S1 ('MetaSel ('Just "stateInput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 s) :*: S1 ('MetaSel ('Just "stateOffset") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "statePosState") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PosState s)) :*: S1 ('MetaSel ('Just "stateParseErrors") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ParseError s e]))))

initialState Source #

Arguments

:: FilePath | Name of the file the input is coming from
-> s | Input
-> State s e |

Given the name of the source file and the input construct the initial state for a parser.

Since: 9.6.0

data PosState s Source #

A special kind of state that is used to calculate line/column positions on demand.

Since: 7.0.0

Constructors

PosState |

Fields

- pstateInput :: s

  The rest of input to process

- pstateOffset :: !Int

  Offset corresponding to beginning of `pstateInput`

- pstateSourcePos :: !SourcePos

  Source position corresponding to beginning of `pstateInput`

- pstateTabWidth :: Pos

  Tab width to use for column calculation

- pstateLinePrefix :: String

  Prefix to prepend to offending line

#### Instances

Instances details

NFData s => NFData (PosState s) Source # |
Instance details Defined in Text.Megaparsec.State Methods rnf :: PosState s -> () Source #
Data s => Data (PosState s) Source # |

Instance details

Defined in Text.Megaparsec.State

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PosState s -> c (PosState s) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (PosState s) Source #

toConstr :: PosState s -> Constr Source #

dataTypeOf :: PosState s -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (PosState s)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PosState s)) Source #

gmapT :: (forall b. Data b => b -> b) -> PosState s -> PosState s Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PosState s -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PosState s -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> PosState s -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PosState s -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> PosState s -> m (PosState s) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PosState s -> m (PosState s) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PosState s -> m (PosState s) Source #

Generic (PosState s) Source # |

Instance details

Defined in Text.Megaparsec.State

Associated Types

type Rep (PosState s) |

Instance details

Defined in Text.Megaparsec.State

type Rep (PosState s) = D1 ('MetaData "PosState" "Text.Megaparsec.State" "megaparsec-9.7.0-BLrpTwU3VfiJJb0Dqvdds1" 'False) (C1 ('MetaCons "PosState" 'PrefixI 'True) ((S1 ('MetaSel ('Just "pstateInput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 s) :*: S1 ('MetaSel ('Just "pstateOffset") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "pstateSourcePos") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SourcePos) :*: (S1 ('MetaSel ('Just "pstateTabWidth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pos) :*: S1 ('MetaSel ('Just "pstateLinePrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))))

Methods

from :: PosState s -> Rep (PosState s) x Source #

to :: Rep (PosState s) x -> PosState s Source #

Show s => Show (PosState s) Source # |
Instance details Defined in Text.Megaparsec.State Methods showsPrec :: Int -> PosState s -> ShowS Source # show :: PosState s -> String Source # showList :: [PosState s] -> ShowS Source #
Eq s => Eq (PosState s) Source # |
Instance details Defined in Text.Megaparsec.State Methods (==) :: PosState s -> PosState s -> Bool Source # (/=) :: PosState s -> PosState s -> Bool Source #
type Rep (PosState s) Source # |

Instance details

Defined in Text.Megaparsec.State

type Rep (PosState s) = D1 ('MetaData "PosState" "Text.Megaparsec.State" "megaparsec-9.7.0-BLrpTwU3VfiJJb0Dqvdds1" 'False) (C1 ('MetaCons "PosState" 'PrefixI 'True) ((S1 ('MetaSel ('Just "pstateInput") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 s) :*: S1 ('MetaSel ('Just "pstateOffset") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int)) :*: (S1 ('MetaSel ('Just "pstateSourcePos") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SourcePos) :*: (S1 ('MetaSel ('Just "pstateTabWidth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Pos) :*: S1 ('MetaSel ('Just "pstateLinePrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))))

initialPosState Source #

Arguments

:: FilePath | Name of the file the input is coming from
-> s | Input
-> PosState s |

Given the name of source file and the input construct the initial positional state.

Since: 9.6.0