uu-cco-0.1.0.0: Utilities for compiler construction

Portabilitynon-portable (uses rank-2 types)
Stabilityprovisional
Maintainerstefan@cs.uu.nl
Safe HaskellSafe-Inferred

CCO.Parsing

Contents

Description

A library of parser combinators that expose their functionality through an Applicative interface.

Based on work by Doaitse Swierstra.

Synopsis

Symbols

class Symbol s whereSource

The class of types that describe input symbols.

A minimal complete definition must supply the method describe.

Methods

describe :: s -> String -> StringSource

Retrieves a textual description from a value that describes a symbol and the lexeme that constitutes the symbol.

Instances

Symbol Char 

Parsers

data Parser s a Source

The type of parsers that consume symbols described by tokens of type s and produces values of type a.

Instances

Functor (Parser s) 
Applicative (Parser s) 
Symbol s => Alternative (Parser s) 

satisfy :: Symbol s => (s -> Bool) -> Parser s sSource

Produces a Parser that recognises a single symbol satisfying a given predicate.

eof :: Symbol s => Parser s ()Source

A Parser that recognises the end of input.

sourcePos :: Parser s SourcePosSource

A Parser that produces the SourcePos of the next lexeme in the input (without consuming the associated symbol).

lexeme :: Parser s StringSource

A Parser that produces the next lexeme in the input (without consuming the associated symbol). Fails if the end of input has been reached.

(<!>) :: Parser s a -> String -> Parser s aSource

Labels a Parser with a description of the grammar production it is associated with. Used to produce more informative error messages.

Derived combinators

choice :: Symbol s => [Parser s a] -> Parser s aSource

Produces a Parser that may use any Parser from a given list to parse its input.

opt :: Symbol s => Parser s a -> a -> Parser s aSource

Produces a Parser that tries to parse its input with a given argument

chainl :: Symbol s => Parser s (a -> a -> a) -> Parser s a -> Parser s aSource

Produces a Parser that parses one or more elements chained by a left-associative operator.

chainr :: Symbol s => Parser s (a -> a -> a) -> Parser s a -> Parser s aSource

Produces a Parser that parses one or more elements chained by a right-associative operator.

manySepBy :: Symbol s => Parser s b -> Parser s a -> Parser s [a]Source

Produces a Parser that parses zero or more elements separated by specified separator.

someSepBy :: Symbol s => Parser s b -> Parser s a -> Parser s [a]Source

Produces a Parser that parses one or more elements separated by specified separator.

Parsing

parse :: Parser s a -> Symbols s -> Feedback (a, Symbols s)Source

Uses a specified Parser to try and parse Symbols. Produces,if successful, a result and any remaining Symbols.

parse_ :: Lexer s -> Parser s a -> Source -> String -> Feedback aSource

Uses a specified Lexer and Parser to perform syntactic analysis on an input stream.