uu-cco-0.1.0.4: Utilities for compiler construction: core functionality

Copyright(c) 2008 Utrecht University
LicenseAll rights reserved
Maintainerstefan@cs.uu.nl
Stabilityprovisional
Portabilitynon-portable (uses rank-2 types)
Safe HaskellSafe
LanguageHaskell98

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 where Source

The class of types that describe input symbols.

A minimal complete definition must supply the method describe.

Methods

describe :: s -> String -> String Source

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

Instances

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.

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

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 SourcePos Source

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

lexeme :: Parser s String Source

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 a infixl 2 Source

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 a Source

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 a infixl 3 Source

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 a Source

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 a Source

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 a Source

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