[Petal] [HELP] Anybody has experience with parsing?

Fergal Daly fergal at esatclear.ie
Wed Jun 11 01:15:55 BST 2003


On Tuesday 10 June 2003 5:26 pm, Jean-Michel Hiver wrote:
> Hi list,
> 
> I'm trying to build a better parser for Petal TALES expressions. The
> major bug / limitation I'd like to overcome is the fact that you can't
> write expressions such as:
> 
>   true: self/method ${self/other_method ${self/yet_other_method}}
> 
> I think that'd be a good feature. I had a look at Steve's modified
> parser but it's just a simple re-write of something that already works
> although cleaner (but slower :)).
> 
> I have played a bit with Parse::RecDescent with seems promissing but
> it's quite slow and a bit crazy: you mix the tokenization, parsing and
> tree-walking in one operation.
> 
> Anyone has already done some serious recursive parsing with Perl?  Have
> you got any examples, commented if possible, that I could play with?
> 
> Ideally I'd like to be able to build a parsed-tree of objects and walk
> the tree to resolve the expression, or even better turn the tree into
> Perl code in order to speed things up.
> 
> Any ideas or examples? I'm a bit stuck :)

I've got it working with Parse::RecDescent. I suppose now is as good a time as 
any to expose my unpleasant alternative to Petal. I was working on it before 
I found Petal, I'm not putting it forward as a competitor or anything. It's 
not very polished at all but it does seem to be considerably faster due to 
compiling variable accesses down to Perl rather than parsing them at run 
time. In fact that's about the only thing it has on Petal.

I want to try integrate the expression stuff into Petal.

You can get it here

http://www.fergaldaly.com/computer/Text/

install Text::Engine first and then Text::TAL. Text::TAL has the TALES 
compiler, have a look in the README for info and you can use the script 
examples/comp to see the expression stuff working. A simple example

examples/comp 'string:hello${person/name "first"} ${person/name "second"}'

which will output the following perl

"hello".$hash->{"person"}->name("first")."\ 
".$hash->{"person"}->name("second")

It's not ready to drop into Petal and Petal's not ready for something to drop 
in. Hopefully we can do something about that,

F



More information about the Petal mailing list