noodle-0.0.19: the noodle programming language

Safe HaskellSafe-Infered

Language.Noodle.Parsing.Generic

Description

GParser is a generalized backtracking parser combinator with state, error propogation and easy to use associativity primitves.

Synopsis

Documentation

data Result st tok res Source

Result encompases error propogation, parameterized over st state type, tok token type, and res the monadic return value

Constructors

Success res st [tok]

'Success result state token_stream'

Failure String st

'Failure error_message state'

Instances

(Show st, Show tok, Show res) => Show (Result st tok res) 

newtype GParser st tok res Source

a GParser computes some result res, based on a stream of tokens tok having a state of type st

Constructors

P ((st, [tok]) -> Result st tok res) 

Instances

Monad (GParser s t) 

getTok :: GParser st tok tokSource

consume one token and return it

lookToks :: GParser st tok [tok]Source

lookahead at the rest of the tokens left in the input

getTokIf :: (tok -> Bool) -> GParser st tok tokSource

consume one token and return it if the result of applying the predicate to it is true, otherwise fail with 'unexpected token'

inputEnd :: GParser st tok ()Source

succeed if all of the input has been consumed, otherwise complain about expecting the end of the input

getSt :: GParser st tok stSource

return the current state

putSt :: st -> GParser st tok ()Source

change the value of the current state

modSt :: (st -> st) -> GParser st tok ()Source

apply some update function to the current state

many :: GParser st tok res -> GParser st tok [res]Source

apply the parser as many times as is possible, and return a list of the results

many1 :: GParser st tok res -> GParser st tok [res]Source

apply the parser one or more times, and return a list of the results. Fails the first application fails

sepBy1 :: GParser st tok res -> GParser st tok b -> GParser st tok [res]Source

parse many1 p's seperated by sep

sepBy :: GParser st tok res -> GParser st tok b -> GParser st tok [res]Source

parse many p's seperated by sep

(<|>) :: GParser st tok res -> GParser st tok res -> GParser st tok resSource

if the left operand | results in failure, apply the right operand. state and token stream changes are not carried over to right operand

choice :: [GParser st tok res] -> GParser st tok resSource

the first successful parser to succeed is parsed, if none, fail

pMaybe :: GParser st tok res -> GParser st tok (Maybe res)Source

try to apply parser p, return Just res on success, or Nothing on fail

pEither :: GParser st tok a -> GParser st tok b -> GParser st tok (Either a b)Source

try to parse either p1 or p2, returning Left a for p1, or Right b for p2

runp :: GParser st tok res -> st -> [tok] -> Result st tok resSource

apply a GParser computation to state and a token stream, returning a value of type Result