Skip to content

Comment on A quick intro to writing a parser with Treetop

Comments

This example uses Treetop. The same variety of parser, PEG (parsing expression grammar), but not code-generating, but dynamically defining ruby code is Citrus. It was really a pleasure to work with. The difference is that you don't need a preliminary compile step in a rake file e.g., which I like better for a language as dynamic as ruby.

http://github.com/mjijackson/citrus

The intermediate compilaton step is actually optional when using Treetop. You can see in the code in the article that Treetop is directly loading and interpreting the grammar at runtime. (Of course there is always going to be some compilation 'behind the scenes', but there's no need for it to be explicit.)

Citrus looks interesting! From what I can see the PEG syntax used by Citrus is very similar to Treetop. I'll definitely check it out more later, I'm particularly interested in performance difference between the two.

In fact, you're right, it doesn't necessarily write a source file. I missed that last time when I looked. But Treetop will still create ruby code, write it into a string and then eval that. I didn't find that approach really elegant.

I do agree to an extent. I'd be interested to see if Citrus is faster... I'll write up a test in a week or two and we shall see!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.