Even though it was nice to see how it can be implemented, I'll be using the "PS" version :) I was really close in implementing it myself.
Anyway thanks for the quick reply. 2009/10/28 S. Doaitse Swierstra <doai...@cs.uu.nl> > pToken [] = pSucceed [] > pToken (x:xs) = (:) <$> pSym x <*> pToken xs > > pKeyword_Float = pToken "Float" > etc > > Doaitse > > PS: this function has been defined in the module > Text.ParserCombinators.UU.Derived > > > > > 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 >> 't' >> 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 >> easier. >> >> 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 :) >> > > -- Ozgur Akgun
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe