Safe Haskell | Safe-Infered |
---|
GParser is a generalized backtracking parser combinator with state, error propogation and easy to use associativity primitves.
- data Result st tok res
- newtype GParser st tok res = P ((st, [tok]) -> Result st tok res)
- getTok :: GParser st tok tok
- lookToks :: GParser st tok [tok]
- getTokIf :: (tok -> Bool) -> GParser st tok tok
- inputEnd :: GParser st tok ()
- getSt :: GParser st tok st
- putSt :: st -> GParser st tok ()
- modSt :: (st -> st) -> GParser st tok ()
- many :: GParser st tok res -> GParser st tok [res]
- many1 :: GParser st tok res -> GParser st tok [res]
- sepBy1 :: GParser st tok res -> GParser st tok b -> GParser st tok [res]
- sepBy :: GParser st tok res -> GParser st tok b -> GParser st tok [res]
- (<|>) :: GParser st tok res -> GParser st tok res -> GParser st tok res
- choice :: [GParser st tok res] -> GParser st tok res
- pMaybe :: GParser st tok res -> GParser st tok (Maybe res)
- pEither :: GParser st tok a -> GParser st tok b -> GParser st tok (Either a b)
- runp :: GParser st tok res -> st -> [tok] -> Result st tok res
Documentation
Result
encompases error propogation, parameterized over st
state type, tok
token type, and res
the monadic return value
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
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
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