indents-0.2.0: indentation sensitive parser-combinators for parsec

Text.Parsec.Indent

Synopsis

Documentation

type IndentParserT s u m a = ParsecT s u (StateT SourcePos m) aSource

A module to construct indentation aware parsers. Many programming language have indentation based syntax rules e.g. python and Haskell. This module exports combinators to create such parsers.

The input source can be thought of as a list of tokens. Abstractly each token occurs at a line and a column and has a width. The column number of a token measures is indentation. If t1 and t2 are two tokens then we say that indentation of t1 is more than t2 if the column number of occurrence of t1 is greater than that of t2.

Currently this module supports two kind of indentation based syntactic structures which we now describe:

Block
A block of indentation c is a sequence of tokens with indentation at least c. Examples for a block is a where clause of Haskell with no explicit braces.
Line fold
A line fold starting at line l and indentation c is a sequence of tokens that start at line l and possibly continue to subsequent lines as long as the indentation is greater than c. Such a sequence of lines need to be folded to a single line. An example is MIME headers. Line folding based binding separation is used in Haskell as well.

withBlock :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> [b] -> c) -> IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m cSource

withBlock f a p parses a followed by an indented block of p and combines them with f

withLineFold :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> [b] -> c) -> IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m cSource

withLineFold f a p parses a followed by any number of p that can wrap onto subsequent indented lines, combined by f

withBlock' :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m [b]Source

Like withBlock, but throws away initial parse result

withLineFold' :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m [b]Source

Like withLineFold, but throws away initial parse result

block :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]Source

Parses a block of lines at the same indentation level

lineFold :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]Source

Parses one or more times, continuing in subsequent indented lines

manyLine :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]Source

Parses many occurances of p without using more than one line

manyIndent :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m [a]Source

Parses many occurances of p, indenting if over one line

foldLine :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> b -> c) -> IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m cSource

Parses two arguments for f possibly wrapping onto subsequent lines

foldLine3 :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> b -> c -> d) -> IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m c -> IndentParserT s u m dSource

Parses three arguments for f possibly wrapping onto subsequent lines

foldLine4 :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> b -> c -> d -> e) -> IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m c -> IndentParserT s u m d -> IndentParserT s u m eSource

Parses four arguments for f possibly wrapping onto subsequent lines

foldLine5 :: (Stream s (StateT SourcePos m) Char, Monad m) => (a -> b -> c -> d -> e -> f) -> IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m c -> IndentParserT s u m d -> IndentParserT s u m e -> IndentParserT s u m fSource

Parses four arguments for f possibly wrapping onto subsequent lines

(<+/>) :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m (a -> b) -> IndentParserT s u m a -> IndentParserT s u m bSource

<+/> is to foldLine as ap is to liftM2

(<-/>) :: (Stream s (StateT SourcePos m) Char, Monad m) => IndentParserT s u m a -> IndentParserT s u m b -> IndentParserT s u m aSource

<-/> is like <+/>, but doesn't apply the function to the parsed value

runIndent :: Monad m => SourceName -> StateT SourcePos m a -> m aSource

Run the result of an indentation sensitive parse