Very cool, Dotan. Be sure to show us the complete parser if it's open
source! I learn lots from other people's code.

I was rewriting RedCloth in Treetop but hit a wall before Parslet came out.
I wanted to do recursion with exclusion neatly, but couldn't extend Treetop
well enough to do what I wanted to.  Also, speed was horrendous. I was
seeing all these parsers, like RedCloth, Gherkin, or Hpricot, that were
written in C/Java for speed but had problems on account of being native
extensions and had to solve the same problems—cross-compilation, character
encodings, etc.—over and over. What if they could share a common native
library but themselves be just a parser definition in pure Ruby? With
generated code, that's not an option.

I was considering forking Treetop and changing it to be in-memory when Citrus
came 
out<http://groups.google.com/group/treetop-dev/browse_thread/thread/af8d889f6c6100bd>.
I didn't make time to explore it before Parslet came out and really lit my
fire. The recursion with
exclusions<https://github.com/jgarber/redcloth-parslet/blob/master/lib/redcloth-parslet/parser/inline.rb>thing
I spoke of earlier was
a 
snap<https://github.com/jgarber/redcloth-parslet/blob/master/lib/redcloth-parslet/parser/exclusions.rb>since
I mostly based it on one of Kaspar's examples. We'll see how fast or
slow Parslet is in the end, but so far it's looking good.

Yes, you can use Treetop grammars with Parslet. See
lib/parslet/expression.rb<https://github.com/kschiess/parslet/blob/master/lib/parslet/expression.rb>.
It's experimental and I'm sure there are plenty of gotchas.

Interested to see your benchmarks when you're ready to share!

Cheers,
Jason

On Tue, Apr 26, 2011 at 5:05 AM, Dotan N. <[email protected]> wrote:
> Hi guys,
> Many thanks for a great tool. I was able to complete (a previously written
> treetop parser) in about 15 minutes!
> I wanted to ask a couple of questions that naturally stem from my move
from
> treetop to parslet
> Firstly, is there a benefit to treetop's generating code in a separate
file
> ? or even - is there a benefit for parslet keeping it 'in memory' ? (in
> terms of runtime use, not development)
> Secondly, is there _any_ way to use treetop grammars with parslet? what I
> turned to do was a mechanic search + replace of my treetop grammar plus
> minor hand tweaks. immediately I was wondering about that.
> When I finished, I realized I had two versions of the parser written with
> both treetop and parslet. As a typical engineer I ran a quick benchmark --
> and parslet (1.2.0) was faster by a considerable margin (perhaps i'll post
> the results further down the week).
>
> Thanks guys!
> --
> Dotan, @jondot
>

Reply via email to