The parser
tokenPrim showTok nextPos testTok accepts a token
t with result
x when the function
testTok t
returns
Just x. The token can be shown using
showTok t. The position of the
next token should be
returned when
nextPos is called with the current source
position
pos, the current token
t and the rest of
the tokens
toks,
nextPos pos t toks.
This is the most primitive combinator for accepting tokens. For
example, the
char parser could be implemented as:
char c
= tokenPrim showChar nextPos testChar
where
showChar x = "'" ++ x ++ "'"
testChar x = if x == c then Just x else Nothing
nextPos pos x xs = updatePosChar pos x