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

Safe HaskellNone

DDC.Base.Parser

Description

Parser utilities.

Synopsis

Documentation

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

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 

Fields

stateTokenShow :: k -> String
 
stateFileName :: String
 

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.

Instances

runTokenParserSource

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.

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

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 tSource

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 SourcePosSource

Accept the given token, returning its source position.