vt-utils-1.0.0.0: Vector and Text utilities

Safe HaskellSafe
LanguageHaskell2010

VtUtils.Parsec

Description

Additional combinators and utilities for Parsec library

Synopsis

Documentation

type Parser = Parsec Text () #

parsecLineContains :: Text -> Parser Text Source #

Finds a line containing a specified substring

Uses LF as a line separator

Consumes whitespace after the line found

Resulting line doesn't contain a line separator

Arguments:

  • needle :: Text: Substring to find

Return value: Line that contains a specified substring

parsecLinePrefix :: Text -> Parser Text Source #

Finds a line with a specified prefix

Uses LF as a line separator

Whitespace is stripped from the start of each line before checking for prefix

Consumes whitespace after the line found

Resulting line doesn't contain a line separator

Arguments:

  • prefix :: Text: Prefix to find

Return value: Line with the specified prefix

parsecLineNoPrefix :: Text -> Parser Text Source #

Finds a line that does not have a specified prefix

Uses LF as a line separator

Whitespace is stripped from the start of each line before checking for prefix

Consumes whitespace after the line found

Resulting line doesn't contain a line separator

Arguments:

  • prefix :: Text: Prefix that should be skipped

Return value: First line that does not have a specified prefix

parsecSkipLines :: Int -> Parser () Source #

Skips a specified number of lines

Uses LF as a line separator

Does not consume additional whitespace after the last line skipped (or between the lines)

Arguments:

  • count :: Int: Number of lines to skip

parsecSkipManyTill :: Text -> Parser () Source #

Skips all input until the specified substring is found

Warning: all look-ahead data is kept in memory

Arguments:

  • needle :: Text: Substring to find

Return value: First line that does not have a specified prefix

parsecTry :: Parser a -> Parser a Source #

The parser parsecTry p behaves like parser p, except that it pretends that it hasn't consumed any input when an error occurs

This is a re-export of Text.Parsec.try under a different name to not conflict with Control.Exception.try

Arguments:

  • parser :: Parser a: Parser to wrap into try

Return value: Resulting value from the specified parser

parsecWhitespace :: Parser () Source #

Skips one or more whitespace characters

Note: Lexemes from Text.Parsec.Token.TokenParser can be used instead

parsecErrorToText :: ParseError -> Text Source #

Formats ParseError into Text string

Arguments:

  • err :: ParseError: ParseError thrown by Parsec

Return value: Text representation of a specified error

parsecParseFile :: Parser a -> Text -> IO a Source #

Lazily reads contents from a specified file and parses it using the specified parser

File contents are decoded as UTF-8

Throws an error on file IO error or parsing error

Arguments:

  • parser :: Parser a: Parser to use for the contents of the file
  • path :: ParseError: Path to a file to parse

Return value: Resulting value from the specified parser

parsecParseText :: Parser a -> Text -> a Source #

Parser a specified strict Text string using a specified parser

Note: parser is typed on a lazy Text input (so it can also be used with parsecParseFile)

Throws an error on parsing error

Arguments:

  • parser :: Parser a: Parser to use for the contents of the file
  • text :: Text: Text string to parse

Return value: Resulting value from the specified parser