| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Parser.Parser
Description
- A combinator-based tokeniser with symmetric choice and location tracking.
- An unambiguous parser with symmetric choice and location tracking.
Synopsis
- data Parse_error error
- = Filter_error error
- | Parse_error' Location
- type Parser' token error = Parser token () error
- type Tokeniser' char_class token error = Parser char_class [With_location token] error
- data Usage_error
- (<+>) :: Parser token output error t -> Parser token output error t -> Parser token output error t
- add_location :: Monoid output => Parser token output error t -> Parser token output error (With_location t)
- add_token :: Tokeniser' char_class token error token -> Tokeniser' char_class token error ()
- filter_parser :: (Eq token, Monoid output) => (t -> Bool) -> (Location -> error) -> Parser token output error t -> Parser token output error t
- fmap_filter_parser :: (Eq token, Monoid output) => (t -> Either (Location -> error) u) -> Parser token output error t -> Parser token output error u
- parse' :: (Char -> char_class) -> (char_class -> Location -> Location) -> Tokeniser' char_class token error () -> Parser' token error t -> (Location -> error) -> String -> Either Usage_error (Either error t)
- parse_brackets :: (Eq token, Monoid output) => token -> token -> Parser token output error t -> Parser token output error t
- parse_default :: Monoid output => Parser token output error t -> t -> Parser token output error t
- parse_file_path' :: Eq token => Parser' token error [Back] -> Parser' token error String -> token -> token -> (String -> token) -> String -> Parser' token error File_path
- parse_list :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error [t]
- parse_location :: Monoid output => Parser token output error Location
- parse_many :: Monoid output => Parser token output error t -> Parser token output error [t]
- parse_non_empty_list :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error [t]
- parse_not :: Monoid output => Parser token output error t -> Parser token output error ()
- parse_some :: Monoid output => Parser token output error t -> Parser token output error [t]
- parse_token :: (Eq token, Monoid output) => token -> Parser token output error ()
- parse_token' :: Monoid output => (token -> Maybe t) -> Parser token output error t
- parse_with_location :: Monoid output => Parser token output error t -> Parser token output error (With_location t)
Documentation
data Parse_error error Source #
Parse errors.
Constructors
| Filter_error error | |
| Parse_error' Location |
Instances
| Show error => Show (Parse_error error) Source # | |
Defined in Parser.Parser Methods showsPrec :: Int -> Parse_error error -> ShowS # show :: Parse_error error -> String # showList :: [Parse_error error] -> ShowS # | |
type Tokeniser' char_class token error = Parser char_class [With_location token] error Source #
A tokeniser that works on any kind of custom characters and tokens. The custom character type is useful if you need to classify characters before tokenisation to simplify patternmatching.
data Usage_error Source #
Errors that indicate that the parsing library has been used incorrectly.
Instances
| Show Usage_error Source # | |
Defined in Parser.Parser Methods showsPrec :: Int -> Usage_error -> ShowS # show :: Usage_error -> String # showList :: [Usage_error] -> ShowS # | |
(<+>) :: Parser token output error t -> Parser token output error t -> Parser token output error t infixr 3 Source #
Symmetric choice between two parsers that selects the longest match. Note that if both parsers successfully reach the same location it will result in an ambiguity error. Also note that you should not attempt to recover a filter error. This operator is normally associative unless you make a mistake and write an ambiguous parser.
add_location :: Monoid output => Parser token output error t -> Parser token output error (With_location t) Source #
Parse with location.
add_token :: Tokeniser' char_class token error token -> Tokeniser' char_class token error () Source #
Add the token to the output.
filter_parser :: (Eq token, Monoid output) => (t -> Bool) -> (Location -> error) -> Parser token output error t -> Parser token output error t Source #
Filter the parse results - for example, restrict an integer parser to positive numbers. You also have to provide an error. Note that filter errors, unlike token matching errors, are non-recoverable.
fmap_filter_parser :: (Eq token, Monoid output) => (t -> Either (Location -> error) u) -> Parser token output error t -> Parser token output error u Source #
Filter and transform the parse results in one operation. You also have to provide an error. Note that filter errors, unlike matching errors, are non-recoverable.
parse' :: (Char -> char_class) -> (char_class -> Location -> Location) -> Tokeniser' char_class token error () -> Parser' token error t -> (Location -> error) -> String -> Either Usage_error (Either error t) Source #
Parse the text. You have to provide a function that classifies characters, a function that updates the location after each character, a tokeniser, a parser and a function that converts parse errors to your preferred type.
parse_brackets :: (Eq token, Monoid output) => token -> token -> Parser token output error t -> Parser token output error t Source #
Parse a term in brackets.
parse_default :: Monoid output => Parser token output error t -> t -> Parser token output error t Source #
Parse something optional or return the default value.
parse_file_path' :: Eq token => Parser' token error [Back] -> Parser' token error String -> token -> token -> (String -> token) -> String -> Parser' token error File_path Source #
Parse a file path. You have to provide a parent directory counter parser, a name parser, the slash token, the dot token, a function that converts strings to name tokens and the file extension.
parse_list :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error [t] Source #
Parse a (possibly empty) list with separators.
parse_location :: Monoid output => Parser token output error Location Source #
Get the current location.
parse_many :: Monoid output => Parser token output error t -> Parser token output error [t] Source #
Parse a (possibly empty) list without separators.
parse_non_empty_list :: (Eq token, Monoid output) => token -> Parser token output error t -> Parser token output error [t] Source #
Parse a non-empty list with separators.
parse_not :: Monoid output => Parser token output error t -> Parser token output error () Source #
Succeed if the parser fails.
parse_some :: Monoid output => Parser token output error t -> Parser token output error [t] Source #
Parse a non-empty list without separators.
parse_token :: (Eq token, Monoid output) => token -> Parser token output error () Source #
Parse a certain token (for example, a delimiter or a keyword) without returning a result.
parse_token' :: Monoid output => (token -> Maybe t) -> Parser token output error t Source #
Parse tokens that fit a certain pattern and transform them into something more useful - for example, an int or a string.
parse_with_location :: Monoid output => Parser token output error t -> Parser token output error (With_location t) Source #
Parse data with location.