Module

Text.Parsing.Simple

Package
purescript-simple-parser
Repository
Thimoteus/purescript-simple-parser

#ParseError Source

#parse Source

parse :: forall a s. Parser s a -> s -> Either ParseError a

Run a parser against an input, either getting an error or a value.

#unparser Source

unparser :: forall a s. Parser s a -> s -> { consumed :: Either ParseError a, remaining :: s }

Get the result of a parse, plus the unparsed input remainder.

#modify Source

modify :: forall a s. (s -> s) -> Parser s a -> Parser s a

Change the input to a parser.

#modifyM Source

modifyM :: forall a s. (s -> Maybe s) -> Parser s a -> Parser s a

Change the input to a parser, using Nothing to signal failure.

#modifyE Source

modifyE :: forall a err s. Show err => (s -> Either err s) -> Parser s a -> Parser s a

Change the input to a parser, using Left to signal failure.

#pureP Source

pureP :: forall a s. a -> Parser s a

A pure that doesn't require passing the typeclass dictionary for Applicative.

#mapP Source

mapP :: forall b a s. (a -> b) -> Parser s a -> Parser s b

A map that doesn't require passing the typeclass dictionary for Functor.

#(|->) Source

Operator alias for Text.Parsing.Simple.mapP (left-associative / precedence 4)

#applyP Source

applyP :: forall b a s. Parser s (a -> b) -> Parser s a -> Parser s b

An apply that doesn't require passing the typeclass dictionary for Apply.

#(~) Source

Operator alias for Text.Parsing.Simple.applyP (left-associative / precedence 4)

#bindP Source

bindP :: forall b a s. Parser s a -> (a -> Parser s b) -> Parser s b

A bind that doesn't require passing the typeclass dictionary for Bind.

#(>>-) Source

Operator alias for Text.Parsing.Simple.bindP (left-associative / precedence 1)

#flippedBindP Source

flippedBindP :: forall b a s. (a -> Parser s b) -> Parser s a -> Parser s b

#(-<<) Source

Operator alias for Text.Parsing.Simple.flippedBindP (right-associative / precedence 1)

#composeKleisliParser Source

composeKleisliParser :: forall c b a s. (b -> Parser s c) -> (a -> Parser s b) -> (a -> Parser s c)

#(<-<) Source

Operator alias for Text.Parsing.Simple.composeKleisliParser (right-associative / precedence 1)

#parserKleisliCompose Source

parserKleisliCompose :: forall c b a s. (a -> Parser s b) -> (b -> Parser s c) -> (a -> Parser s c)

#(>->) Source

Operator alias for Text.Parsing.Simple.parserKleisliCompose (right-associative / precedence 1)

#altL Source

altL :: forall a s. Parser s a -> Parser s a -> Parser s a

#(<|) Source

Operator alias for Text.Parsing.Simple.altL (left-associative / precedence 3)

#altR Source

altR :: forall a s. Parser s a -> Parser s a -> Parser s a

#(|>) Source

Operator alias for Text.Parsing.Simple.altR (right-associative / precedence 3)

#applyL Source

applyL :: forall b a s. Parser s a -> Parser s b -> Parser s a

Equivalent to (<*) but faster since it doesn't require passing typeclass dictionaries.

#(<<) Source

Operator alias for Text.Parsing.Simple.applyL (left-associative / precedence 4)

#applyR Source

applyR :: forall b a s. Parser s a -> Parser s b -> Parser s b

Equivalent to (*>) but faster since it doesn't require passing typeclass dictionaries.

#(>>) Source

Operator alias for Text.Parsing.Simple.applyR (left-associative / precedence 4)

#fromCharList Source

fromCharList :: forall f. Foldable f => f Char -> String

#none Source

none :: forall a s. Parser s a

Always fail.

#fail Source

fail :: forall a s. ParseError -> Parser s a

Fail with a message

#orFailWith Source

orFailWith :: forall a s. Parser s a -> ParseError -> Parser s a

#(<?>) Source

Operator alias for Text.Parsing.Simple.orFailWith (non-associative / precedence 0)

#try Source

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

If the given parser fails, backtrack to the point of failure.

#many Source

many :: forall a s. Parser s a -> Parser s (List a)

Attempt a parse as many times as possible, putting all successes into a list. WARNING: Applying this to a parser which never fails and never consumes input will result in a bottom, i.e. a nonterminating program.

#some Source

some :: forall a s. Parser s a -> Parser s (List a)

Attempt a parse one or more times.

#fix Source

fix :: forall a s. (Parser s a -> Parser s a) -> Parser s a

Find a function's least fixed point using the Z combinator.

#lookahead Source

lookahead :: forall a s. Parser s a -> Parser s a

Parse without consuming input.

#isn't Source

isn't :: forall a s. Parser s a -> Parser s Unit

isn't p succeeds iff p fails, though it will always consume the same amount of input that p does.

#notFollowedBy Source

notFollowedBy :: forall a s. Parser s a -> Parser s Unit

Differs from isn't in that this never consumes input.

#skip Source

skip :: forall a s. Parser s a -> Parser s Unit

Discard the result of a parse.

#suchThat Source

suchThat :: forall a s. Parser s a -> (a -> Boolean) -> Parser s a

Attempt a parse subject to a predicate. If the parse succeeds but the predicate does not hold, the resulting parse fails without backtracking. If the parse fails, it will backtrack.

#(|=) Source

Operator alias for Text.Parsing.Simple.suchThat (left-associative / precedence 5)

#sepBy Source

sepBy :: forall b a s. Parser s a -> Parser s b -> Parser s (List a)

#sepBy1 Source

sepBy1 :: forall b a s. Parser s a -> Parser s b -> Parser s (List a)

#tail Source

tail :: Parser String String

Matches the unparsed portion of the input.

#item Source

item :: Parser String Char

Parse a single Char.

#first Source

first :: forall a s. (s -> Maybe { head :: a, tail :: s }) -> Parser s a

A generalized item for arbitrary streams that can be unconsed.

#sat Source

sat :: (Char -> Boolean) -> Parser String Char

Backtracking combinators

Create a parser from a Characteristic function.

#isn'tAnyF Source

isn'tAnyF :: forall f. Foldable f => f Char -> Parser String Char

Match any character not in the foldable container.

#isn'tAny Source

isn'tAny :: String -> Parser String Char

Match any character not in the string. Equivalent to isn'tAnyF <<< toCharArray.

#anyOfF Source

anyOfF :: forall f. Foldable f => f Char -> Parser String Char

Match any character in the foldable container.

#anyOf Source

anyOf :: String -> Parser String Char

Match any character in the string. Equivalent to anyOfF <<< toCharArray.

#lower Source

lower :: Parser String Char

Parse a lowercase character.

#upper Source

upper :: Parser String Char

Parse an uppercase character.

#alphanum Source

alphanum :: Parser String Char

Parse a letter or a digit.

#cr Source

cr :: Parser String Char

Parse a carriage return.

#sat' Source

sat' :: (Char -> Boolean) -> Parser String Char

Non-backtracking combinators

#isn'tAnyF' Source

isn'tAnyF' :: forall f. Foldable f => f Char -> Parser String Char

#anyOfF' Source

anyOfF' :: forall f. Foldable f => f Char -> Parser String Char

#whitespaces Source

whitespaces :: Parser String (List Char)

Higher-order combinators

#manyChar Source

manyChar :: Parser String Char -> Parser String String

Parse a natural number amount of a given Char parser, resulting in a String.

#someChar Source

someChar :: Parser String Char -> Parser String String

Parse a positive integral amount of a given Char parser, resulting in a String.

#word Source

word :: Parser String String

Contiguous strings with no tabs, spaces, carriage returns or newlines.

#eof Source

eof :: Parser String Unit

Parse the end of a file, returning Unit to indicate success.

#integral Source

integral :: Parser String String

Parse an integer value as a String. Useful if needing to parse integers that are outside of Int's bounds. You could then combine this with, e.g. purescript-hugenum's Data.HugeInt.fromString.

#int Source

int :: Parser String Int

Parse an Int. Note that this parser will fail if the candidate would be outside the range of allowable Ints.

#number Source

number :: Parser String Number

Parse a Number. The string must have digits surrounding a decimal point.

#parens Source

parens :: forall a. Parser String a -> Parser String a

#braces Source

braces :: forall a. Parser String a -> Parser String a

#brackets Source

brackets :: forall a. Parser String a -> Parser String a