indentparser-0.1: A parser for indentation based structures

Text.Parsec.IndentParsec.Prim

Contents

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.

Synopsis

Documentation

class Indentation i whereSource

Type class that captures generic indentation rule. It should follow the condition that acceptable never = const False.

Methods

neverSource

Arguments

:: i

an indentation state where no tokens are accepted.

alwaysSource

Arguments

:: i

an indentation that will always accept tokens.

acceptableSource

Arguments

:: i 
-> SourcePos 
-> Bool

Check if the current position is acceptable.

nestableInSource

Arguments

:: i

Inner indentation.

-> i

Outer indentation.

-> Bool

True if the inner indentation can nest inside the outer indentations.

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

nestSource

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

Running parsers

runGIPT'Source

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.

runGIPTSource

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 IndentT i m = StateT i mSource

The inner monad for indent parsers.