Module

StringParser

Package
purescript-string-parsers
Repository
purescript-contrib/purescript-string-parsers

Re-exports from StringParser.CodePoints

#whiteSpace Source

whiteSpace :: Parser String

Match many whitespace characters.

#upperCaseChar Source

upperCaseChar :: Parser Char

Match any upper case character.

#string Source

string :: String -> Parser String

Match the specified string.

#skipSpaces Source

skipSpaces :: Parser Unit

Skip many whitespace characters.

#satisfyCodePoint Source

satisfyCodePoint :: (CodePoint -> Boolean) -> Parser CodePoint

Match a code point satisfying the given predicate.

#satisfy Source

satisfy :: (Char -> Boolean) -> Parser Char

Match a character satisfying the given predicate.

#regex Source

regex :: String -> Parser String

match the regular expression

#oneOf Source

oneOf :: forall f. Foldable f => f Char -> Parser Char

Match one of the characters in the foldable structure.

#noneOf Source

noneOf :: forall f. Foldable f => f Char -> Parser Char

Match any character not in the foldable structure.

#lowerCaseChar Source

lowerCaseChar :: Parser Char

Match any lower case character.

#eof Source

eof :: Parser Unit

Match the end of the file.

#codePoint Source

codePoint :: CodePoint -> Parser CodePoint

Match the specified code point.

#char Source

char :: Char -> Parser Char

Match the specified character.

#anyLetter Source

anyLetter :: Parser Char

Match any letter.

#anyDigit Source

anyDigit :: Parser Char

Match any digit.

#anyCodePoint Source

anyCodePoint :: Parser CodePoint

Match any code point.

#anyChar Source

anyChar :: Parser Char

Match any character from the Basic Multilingual Plane.

#alphaNum Source

alphaNum :: Parser Char

Match a letter or a number.

Re-exports from StringParser.Combinators

#withError Source

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

Provide an error message in case of failure.

#tryAhead Source

tryAhead :: forall a. Parser a -> Parser a

Read ahead without consuming input. tryAhead p means: succeed if what comes next is of the form p; fail otherwise.

#try Source

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

try p means: run p but do not consume input in case of failure.

#sepEndBy1 Source

sepEndBy1 :: forall a sep. Parser a -> Parser sep -> Parser (NonEmptyList a)

Parse one or more separated values, optionally ending with a separator.

#sepEndBy Source

sepEndBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)

Parse zero or more separated values, optionally ending with a separator.

#sepBy1 Source

sepBy1 :: forall a sep. Parser a -> Parser sep -> Parser (NonEmptyList a)

Parse one or more separated values.

#sepBy Source

sepBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)

Parse zero or more separated values.

#optional Source

optional :: forall a. Parser a -> Parser Unit

Attempt to parse a value.

#optionMaybe Source

optionMaybe :: forall a. Parser a -> Parser (Maybe a)

Attempt to parse a value, pureing Nothing in case of failure.

#option Source

option :: forall a. a -> Parser a -> Parser a

Parse a value with a default value in case of failure.

#manyTill Source

manyTill :: forall a end. Parser a -> Parser end -> Parser (List a)

Match a parser until a terminator parser matches. Fails when the parser does not consume anymore.

#many1Till Source

many1Till :: forall a end. Parser a -> Parser end -> Parser (NonEmptyList a)

Match a parser until a terminator parser matches, requiring at least one match. Fails when the parser does not consume anymore.

#many1 Source

many1 :: forall a. Parser a -> Parser (NonEmptyList a)

Match a parser one or more times. Stops matching when the parser fails or does not consume anymore.

#many Source

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

Match a parser zero or more times. Stops matching when the parser fails or does not consume anymore.

#lookAhead Source

lookAhead :: forall a. Parser a -> Parser a

lookAhead p means: run p but do not consume input in case of success. In most cases you will probably want to use tryAhead instead.

#fix Source

fix :: forall l. Lazy l => (l -> l) -> l

fix defines a value as the fixed point of a function.

The Lazy instance allows us to generate the result lazily.

#endBy1 Source

endBy1 :: forall a sep. Parser a -> Parser sep -> Parser (NonEmptyList a)

Parse one or more separated values, ending with a separator.

#endBy Source

endBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)

Parse zero or more separated values, ending with a separator.

#choice Source

choice :: forall f a. Foldable f => f (Parser a) -> Parser a

Parse using any of a collection of parsers.

#chainr1 Source

chainr1 :: forall a. Parser a -> Parser (a -> a -> a) -> Parser a

Parse one or more values separated by a right-associative operator.

#chainr Source

chainr :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a

Parse zero or more values separated by a right-associative operator.

#chainl1 Source

chainl1 :: forall a. Parser a -> Parser (a -> a -> a) -> Parser a

Parse one or more values separated by a left-associative operator.

#chainl Source

chainl :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a

Parse zero or more values separated by a left-associative operator.

#between Source

between :: forall a open close. Parser open -> Parser close -> Parser a -> Parser a

Parse a string between opening and closing markers.

#assertConsume Source

assertConsume :: forall a. Parser a -> Parser a

Run given parser and fail if the parser did not consume any input.

#(<?>) Source

Operator alias for StringParser.Combinators.withError (left-associative / precedence 4)

Re-exports from StringParser.Parser

#PosString Source

type PosString = { position :: Pos, substring :: String }

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

{ substring: s, position: n } is interpreted as the substring s starting at index n of the original string.

The position is only kept for error messaging.

#Pos Source

type Pos = Int

A position in an input string.

#Parser Source

newtype Parser a

A parser is represented as a function that, when successful, returns a result and the position where the parse finished or, when it fails, a ParserError with more information on where and why it failed. See also printParserError.

Constructors

Instances

#ParseError Source

type ParseError = { error :: String, pos :: Pos }

The type of parsing errors.

#unParser Source

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

Run a parser, allowing the caller to define where to start within the input String and what to do with the unchanged output of the Parser. See runparser for more typical usages.

#runParser Source

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

Run a parser for an input string. See also printParserError and unParser for more flexible usages.

#printParserError Source

printParserError :: ParseError -> String

Prints a ParseError's the error message and the position of the error.

#fail Source

fail :: forall a. String -> Parser a

Fail with the specified message.