| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
VtUtils.Parsec
Description
Additional combinators and utilities for Parsec library
Synopsis
- type Parser = Parsec Text ()
- parsecLineContains :: Text -> Parser Text
- parsecLinePrefix :: Text -> Parser Text
- parsecLineNoPrefix :: Text -> Parser Text
- parsecSkipLines :: Int -> Parser ()
- parsecSkipManyTill :: Text -> Parser ()
- parsecTry :: Parser a -> Parser a
- parsecWhitespace :: Parser ()
- data ParsecParseFileException
- parsecParseFile :: Parser a -> Text -> IO a
- data ParsecParseTextError
- parsecParseText :: Parser a -> Text -> Either ParsecParseTextError a
Documentation
parsecLineContains :: Text -> Parser Text Source #
Finds a line containing a specified substring
Uses LF as a line separator
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
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
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 intotry
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
data ParsecParseFileException Source #
Exception for parsecParseFile function
Instances
| Show ParsecParseFileException Source # | |
Defined in VtUtils.Parsec Methods showsPrec :: Int -> ParsecParseFileException -> ShowS # show :: ParsecParseFileException -> String # showList :: [ParsecParseFileException] -> ShowS # | |
| Exception ParsecParseFileException Source # | |
Defined in VtUtils.Parsec | |
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 exception on file IO error or parsing error
Arguments:
parser :: Parser a: Parser to use for the contents of the filepath :: ParseError: Path to a file to parse
Return value: Resulting value from the specified parser
data ParsecParseTextError Source #
Error for parsecParseText function
Instances
| Show ParsecParseTextError Source # | |
Defined in VtUtils.Parsec Methods showsPrec :: Int -> ParsecParseTextError -> ShowS # show :: ParsecParseTextError -> String # showList :: [ParsecParseTextError] -> ShowS # | |
parsecParseText :: Parser a -> Text -> Either ParsecParseTextError 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)
Returns an error on parsing error
Arguments:
parser :: Parser a: Parser to use for the contents of the filetext :: Text:Textstring to parse
Return value: Resulting value from the specified parser or parsing error