Text.Parsec.IndentParsec.Prim
Description
In general, an indentation structure is a predicate on the position
which tells us whether the token is acceptable or not. Besides the
predicate to check if a token at a given position is acceptable, we
also need to specify how indentations can be nested. This is captured
by the type class Indentation.
- class  Indentation i  where- never :: i
- always :: i
- acceptable :: i -> SourcePos -> Bool
- nestableIn :: i -> i -> Bool
 
- type GenIndentParsecT i s u m a = ParsecT s u (IndentT i m) a
- tokeniser :: (Indentation i, Monad m) => GenIndentParsecT i s u m a -> GenIndentParsecT i s u m a
- nest :: (Indentation i, Show i, Monad m, Stream s (IndentT i m) t, Show t) => (SourcePos -> i) -> GenIndentParsecT i s u m body -> GenIndentParsecT i s u m body
- neglectIndent :: (Monad m, Show t, Show i, Indentation i, Stream s (IndentT i m) t) => GenIndentParsecT i s u m a -> GenIndentParsecT i s u m a
- data HaskellLike
- runGIPT' :: (Monad m, Stream s (IndentT i m) t) => i -> GenIndentParsecT i s u m a -> u -> SourceName -> s -> m (Either ParseError a)
- runGIPT :: (Monad m, Indentation i, Stream s (IndentT i m) t) => GenIndentParsecT i s u m a -> u -> SourceName -> s -> m (Either ParseError a)
- type IndentT i m = StateT i m
- type GenIndentParsec i s u a = GenIndentParsecT i s u Identity a
- type IndentParsecT s u m a = GenIndentParsecT HaskellLike s u m a
- type IndentParsec s u a = IndentParsecT s u Identity a
Documentation
class Indentation i whereSource
Type class that captures generic indentation rule. It should follow
the condition that acceptable never = const False
Methods
Arguments
| :: i | an indentation state where no tokens are accepted. | 
Arguments
| :: i | an indentation that will always accept tokens. | 
Arguments
| :: i | Inner indentation. | 
| -> i | Outer indentation. | 
| -> Bool | True if the inner indentation can nest inside the outer indentations. | 
Instances
type GenIndentParsecT i s u m a = ParsecT s u (IndentT i m) aSource
The indentation parser.
tokeniser :: (Indentation i, Monad m) => GenIndentParsecT i s u m a -> GenIndentParsecT i s u m aSource
Build indentation awareness into the parser
Arguments
| :: (Indentation i, Show i, Monad m, Stream s (IndentT i m) t, Show t) | |
| => (SourcePos -> i) | indentor function. | 
| -> GenIndentParsecT i s u m body | The nested parser to run | 
| -> GenIndentParsecT i s u m body | 
Any nested indentation starts at a position. Given an indentor function, i.e. a function to compute the indentation state from the current position, and a parser to parse the body of the indentation, runs the parser inside the nested indentation context given by the indentor.
neglectIndent :: (Monad m, Show t, Show i, Indentation i, Stream s (IndentT i m) t) => GenIndentParsecT i s u m a -> GenIndentParsecT i s u m aSource
run a given parser neglecting indentation.
data HaskellLike Source
Type to capture Haskell like indentation. Besides always and never
the important indentations are blocks and line folds. A block starting
at position p consists of all tokens that have indentation at least
as much as p. A folded like starting at position p is
Instances
Running parsers
Arguments
| :: (Monad m, Stream s (IndentT i m) t) | |
| => i | The starting indentation, | 
| -> GenIndentParsecT i s u m a | The parser to run, | 
| -> u | The user state, | 
| -> SourceName | Name of the input source, | 
| -> s | The actual stream, | 
| -> m (Either ParseError a) | The result | 
Run a given indentation aware parser with a starting indentation.
Arguments
| :: (Monad m, Indentation i, Stream s (IndentT i m) t) | |
| => GenIndentParsecT i s u m a | The parser to run, | 
| -> u | The user state, | 
| -> SourceName | Name of the input source, | 
| -> s | The actual stream, | 
| -> m (Either ParseError a) | The result. | 
Same as runGIPT' always
Some convenient type aliases.
type GenIndentParsec i s u a = GenIndentParsecT i s u Identity aSource
type IndentParsecT s u m a = GenIndentParsecT HaskellLike s u m aSource
type IndentParsec s u a = IndentParsecT s u Identity aSource