
Hi, I want to have a parser like: p = do eof return something <|> do patternA update_parser_state p <|> do patternB update_parser_state_in_another_way p <|> do anyToken p i.e., go through the content, if pattern A occurs, update my internal state, if pattern B occurs, update the state in another way. Also, the exact forms of pattern A and pattern B might be dependent on the internal state at that time (e.g., whenever I encount pattern A, I increase a counter in my internal state, and that counter is included in pattern B). Finally, when I reach the end, I will then return something based on the final internal state. I did it in the above recursive fashion, but when I ran it, it caused a stack overflow error. So what is the best way to do this kind of parsing? Thanks! Di, Yu 7.11 __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com

Hi Yu Di,
Hi, I want to have a parser like:
p = do eof return something <|> do patternA update_parser_state p <|> do patternB update_parser_state_in_another_way p <|> do anyToken p
[snip]
I did it in the above recursive fashion, but when I ran it, it caused a stack overflow error. So what is the best way to do this kind of parsing?
It seems to me that this program should *not* cause a stack overflow unless something more is happening in patternX or update_parser_state_X than I can see. Maybe you can send the entire source (or at least the relevant parts)? Normally, a stack overlow only occurs when you write a non-accumulating function, in your case something like: p = do ... x <- p return (.. x... ) The (<|>) combinators are carefully structured to prevent holding on to input and will not cause the stack overflow (unless you are using "try" in devious ways :-) Hope this helps, All the best, Daan.
Thanks!
Di, Yu 7.11
__________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
participants (2)
-
Daan Leijen
-
Yu Di