Module

Text.Parsing.StringParser

Package
purescript-string-parsers
Repository
paf31/purescript-string-parsers

This module defines the Parser type of string parsers, and its instances.

#Pos Source

type Pos = Int

A position in an input string.

#PosString Source

type PosString = { pos :: Pos, str :: String }

Strings are represented as a string with an index from the start of the string.

{ str: s, pos: n } is interpreted as the substring of s starting at index n.

This allows us to avoid repeatedly finding substrings every time we match a character.

#ParseError Source

data ParseError

The type of parsing errors.

Constructors

Instances

#Parser Source

newtype Parser a

A parser is represented as a function which takes a pair of continuations for failure and success.

Constructors

Instances

#unParser Source

unParser :: forall a. Parser a -> PosString -> Either { error :: ParseError, pos :: Pos } { result :: a, suffix :: PosString }

Run a parser by providing success and failure continuations.

#runParser Source

runParser :: forall a. Parser a -> String -> Either ParseError a

Run a parser for an input string, returning either an error or a result.

#fail Source

fail :: forall a. String -> Parser a

Fail with the specified message.

#try Source

try :: forall a. Parser a -> Parser a

In case of error, the default behavior is to backtrack if no input was consumed.

try p backtracks even if input was consumed.