[Haskell-cafe] Re: uu-parsinglib pKeyword
S. Doaitse Swierstra
doaitse at cs.uu.nl
Wed Oct 28 13:07:49 EDT 2009
pToken  = pSucceed 
pToken (x:xs) = (:) <$> pSym x <*> pToken xs
pKeyword_Float = pToken "Float"
PS: this function has been defined in the module
On 28 okt 2009, at 17:39, Ozgur wrote:
> Hi everybody,
> I am using the uu-parsinglib to parse a structured language and map
> the results to some proper data structures. Thanks to Prof Doaitse
> Swierstra (and other authors if any), it is fun to write a parser
> using this library.
> I've been sending private mails to Doaitse about my questions, who
> kindly gives nice replies everytime. But this time I thought I can ask
> my question to the community, and give everyone the chance to benefit
> from the answers.
> [After the intro, here comes my real question]
> I am trying to capture the following pattern.
> pKeyword_Int = ( \ _ _ _ -> "int" ) <$> pSym 'i' <*> pSym 'n' <*> pSym
> pKeyword_Float = ( \ _ _ _ _ _ -> "float" ) <$> pSym 'f' <*> pSym 'l'
> <*> pSym 'o' <*> pSym 'a' <*> pSym 't'
> As you can see there is an obvious pattern if you try to capture a
> "keyword". If there were a function called pKeyword taking a string as
> an argument and producing the necessary parser, things would be
> What I mean is,
> pKeyword_Int = pKeyword "int"
> pKeyword_Float = pKeyword "float"
> I tried to create this pKeyword function myself but I couldn't manage
> to do it.
> I can feel that, one can simply add a "<* pReturn " to the ends of
> every parser and write a recursion with this base condition.
> Any suggestions?
> PS: Actually I'm a little bit uncomfortable since there may be such a
> function in the library already :)
More information about the Haskell-Cafe