youngnh/parsatron — pull request #7 by zane (2012-05-15 02:59:20+00:00)
Title: Stack Woes

Hey Nate,

I've been using Parsatron to great effect for a few days now, but I've recently been running into stack overflow errors. The issue is most easily demonstrated by:

```Clojure
(run (many (char \a)) (take 1000 (repeat \a)))
;; [Thrown class java.lang.StackOverflowError]
```

I investigated trying to rewrite `many` using `loop` and `recur`, but it's not obvious how to do so given that the recursive call happens within an inner function. I've implemented a simple trampolining strategy to slow stack consumption. With this pull request I can run up to `(run (many (char\a)) (take 10000 (repeat \a)))` without triggering an overflow error.

Working on a way to rewrite `many` to keep it's stack consumption linear.