ddc-base-0.4.2.1: Disciplined Disciple Compiler common utilities.

Safe HaskellNone
LanguageHaskell98

DDC.Base.Parser

Description

Parser utilities.

Synopsis

Documentation

type Parser k a = Eq k => ParsecT [Token k] (ParserState k) Identity a Source

A generic parser, parameterised over token and return types.

data ParserState k Source

A parser state that keeps track of the name of the source file.

Constructors

ParseState 

data SourcePos Source

A position in a source file.

If there is no file path then we assume that the input has been read from an interactive session and display ''<interactive>'' when pretty printing.

runTokenParser Source

Arguments

:: Eq k 
=> (k -> String)

Show a token.

-> String

File name for error messages.

-> Parser k a

Parser to run.

-> [Token k]

Tokens to parse.

-> Either ParseError a 

Run a generic parser, making sure all input is consumed.

pTokMaybe :: (k -> Maybe a) -> Parser k a Source

Accept a token if the function returns Just.

pTokMaybeSP :: (k -> Maybe a) -> Parser k (a, SourcePos) Source

Accept a token if the function return Just, also returning the source position of that token.

pTokAs :: Eq k => k -> t -> Parser k t Source

Accept a token and return the given value.

pTokAsSP :: Eq k => k -> t -> Parser k (t, SourcePos) Source

Accept a token and return the given value, along with the source position of the token.

pTok :: Eq k => k -> Parser k () Source

Accept the given token.

pTokSP :: Eq k => k -> Parser k SourcePos Source

Accept the given token, returning its source position.