kangaroo-0.2.0: Binary parsing with random access.

Portabilityto be determined.
Stabilityhighly unstable
MaintainerStephen Tetley <stephen.tetley@gmail.com>

Data.ParserCombinators.KangarooReader

Contents

Description

Kangaroo parse monad with env.

Synopsis

Documentation

manyTill :: GenKangaroo ust a -> GenKangaroo ust b -> GenKangaroo ust [a]Source

genericManyTill :: (a -> c -> c) -> c -> GenKangaroo ust a -> GenKangaroo ust b -> GenKangaroo ust cSource

manyTillPC :: GenKangaroo ust a -> (a -> Bool) -> GenKangaroo ust ([a], a)Source

genericManyTillPC :: (a -> b -> b) -> b -> GenKangaroo ust a -> (a -> Bool) -> GenKangaroo ust (b, a)Source

count :: Int -> GenKangaroo ust a -> GenKangaroo ust [a]Source

countPrefixed :: Integral i => GenKangaroo ust i -> GenKangaroo ust a -> GenKangaroo ust (i, [a])Source

genericCount :: (a -> b -> b) -> b -> Int -> GenKangaroo ust a -> GenKangaroo ust bSource

runOn :: GenKangaroo ust a -> GenKangaroo ust [a]Source

genericRunOn :: (a -> b -> b) -> b -> GenKangaroo ust a -> GenKangaroo ust bSource

postCheck :: GenKangaroo ust a -> (a -> Bool) -> String -> GenKangaroo ust aSource

Apply parse then apply the check, if the check fails report the error message.

buildWhile :: (a -> Bool) -> (a -> b -> b) -> (a -> b -> b) -> b -> GenKangaroo ust a -> GenKangaroo ust bSource

Build a value by while the test holds. When the test fails the position is not backtracked, instead we use the "failing" element with lastOp potentially still building the value with it.

buildPrimitive :: Int -> (Word8 -> Bool) -> (Word8 -> b -> b) -> b -> GenKangaroo ust bSource

data RegionCoda Source

RegionCoda - represents three useful final positions:

  1. dalpunto - 'from the point' - Run the parser within a region and return to where you came from.
  2. alfermata - 'to the stop' - Run the parser within a region, the cursor remains wherever the parse finished.
  3. alfine - 'to the end' - Run the parser within a region and jump to the right-end of the region after the parse.

Constructors

Dalpunto 
Alfermata 
Alfine 

modifyUserSt :: (ust -> ust) -> GenKangaroo ust ()Source

Primitive parsers

Query the cursor position

position :: GenKangaroo ust IntSource

position : -> cursor-position

Return the current cursor position

region :: GenKangaroo ust (Int, Int, Int)Source

region : -> (region-start, cursor-position, region-end)

Return the current parse region and the current position of the cursor within it.

atEnd :: GenKangaroo ust BoolSource

atEnd - is the cursor at the end of the current region?

lengthRemaining :: GenKangaroo ust IntSource

lengthRemaining : -> distance-to-region-end

Distance from the current cursor position to the end of the current region

regionSize :: GenKangaroo ust IntSource

regionSize : -> region-length

Size of the current region.

Parse within a region

intraparse :: RegionName -> RegionCoda -> RegionStart -> Int -> GenKangaroo ust a -> GenKangaroo ust aSource

intraparse : name * coda * abs_region_start * region_length * parser -> parser

Create a new region within the current one and run the supplied parser. The cursor position is moved to the start of the new region. The value of coda determines where the cursor is positioned after a successful parse.

intraparse throws a parse error if the supplied absolute-region-start is not located within the current region, or if the right-boundary of the new region (abs_region_start + region_length) extends beyond the right-boundary of the current region.

advance :: RegionName -> RegionCoda -> Int -> GenKangaroo ust a -> GenKangaroo ust aSource

advance : name * coda * abs_region_start * parser -> parser

A variation of intraparse - the new region starts at the supplied abs_region_start and continues to the end of the current region.

advance throws a parse error if the new start position is not within the current region.

advanceRelative :: RegionName -> RegionCoda -> Int -> GenKangaroo ust a -> GenKangaroo ust aSource

advanceRelative : name * coda * distance * parser -> parser

A variation of advance - the start of the new region is calculated from the current-cursor-position + the supplied distance.

advanceRelative throws a parse error if the new start position is not within the current region.

restrict :: RegionName -> RegionCoda -> Int -> GenKangaroo ust a -> GenKangaroo ust aSource

restrict : name * coda * distance * parser -> parser

A variation of intraparse - create a new region as a restriction of the current one and run the supplied parser. The new region starts at the current coursor position, the right-boundary is restricted to the current-cursor-position + the supplied distance.

restrict throws a parse error if the right-boundary of the new region extends beyond the current region.

restrictToPos :: RegionName -> RegionCoda -> Int -> GenKangaroo ust a -> GenKangaroo ust aSource

restrictToPos : region-name * coda * abs-end-pos * parser -> parser

A variantion of restrict - the new region takes the current cursor position for the left-boundary and the supplied absolute-end-position (abs-end-pos) as the right-boundary.

restrictToPos throws a parse error if the abs-end-pos extends beyond the right-boundary of the current region.

Debug

cstring :: GenKangaroo ust StringSource

Read a null-terminated string