# When to use PEP treetop vs regexp

**URL:** <https://www.ruby-forum.com/t/when-to-use-pep-treetop-vs-regexp/127359>\
**Category:** Ruby\
**Created:** [January 28, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/when-to-use-pep-treetop-vs-regexp/127359 "2008-01-28T16:27:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [January 28, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/when-to-use-pep-treetop-vs-regexp/127359/1 "2008-01-28T16:27:29Z")

</div>

on a practical basis when would want to use treetop parse over using  
regular expressions with .scan()? …  
in the wicki ‘treetop (PEP)’ subject/submission… it would seem  
that using regular expression would be a better tool!

---

<div class="post-metadata">

**Author:** ![davidjrice](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5e9695/32.png) [@davidjrice](https://www.ruby-forum.com/u/davidjrice)\
**Post date:** [January 28, 2008, 5:21pm UTC](https://www.ruby-forum.com/t/when-to-use-pep-treetop-vs-regexp/127359/2 "2008-01-28T17:21:05Z")

</div>

On Jan 28, 8:27 am, David R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> on a practical basis when would want to use treetop parse over using  
> regular expressions with .scan()? …  
> in the wicki ‘treetop (PEP)’ subject/submission… it would seem  
> that using regular expression would be a better tool!

I don’t have enough experience to be sure, but my guess is:

1. If you can’t do it in Regexp (e.g. recursive nested parens), use  
something like Treetop.
2. If the overall solution using Regexp alone becomes too large or  
unmaintainable (which may be the same thing), use something like  
Treetop. (Or you’re laying a foundation that you think may become  
large in the future.)
3. Otherwise, Regexp will be less overhead and, I suspect (but don’t  
know yet) faster.

I’m currently porting my OWLScribble[1] library from using (my own  
strscan/regex state-based) TagTreeScanner[2] parser to use Treetop  
instead. My goal is to learn Treetop, create a more readable and  
maintainable syntax description, and also to be able to benchmark and  
compare the performance of the two implementations.

[1] [http://rubyforge.org/projects/owlscribble/](http://rubyforge.org/projects/owlscribble/)  
[2] [http://rubyforge.org/projects/tagtreescanner/](http://rubyforge.org/projects/tagtreescanner/)
