http://www.perlmonks.org?node_id=661593

clinton has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a reporting module, which allows a (knowledgeable) user to specify the content and format of a report in HTML/Excel/XML/PDF etc, without having to touch the code.

For instance, this report would return a list of order_line objects - one for each row, then proceed to write out each column in the row, based on the current order_line object:

I would have a %vars hash which would contain (eg) the $lang variable and and would store the row variables $order_line, $order and $product, and a %function hash, which would contain the lookup() and currency() code refs.

title: This week's order lines object_type: order_line query: ... query params that return a list of Object IDs +... row_vars: order: $order_line.order # Stores $orde +r product: $order_line.product # and $product + in the %vars hash columns: - title: Order value: $order.id # $order->id - title: Order date value: $order.create_date.yMonthd($lang) # $order->crea +te_date->yMonthd($lang) - title: Order total value: $order.total | currency # currency ($o +rder->total) format: align: right - title: Invoice no value: $order.invoice_id || 'Not invoiced' - title: Pickup address value: $order_line.pickup_id ? $order_line.pickup_id | lookup ('pickup',$la +ng,$order_line.pickup_id) : $order_line.pickup_text

The question: how should I parse the value fields?

The value fields are short, discreet strings, in a TT style. The grammar is limited, but allows for quite a lot of flexibility.

My first inclination was to use a few regexes and to string together some coderefs, the return value from the previous coderef being passed as an argument to the next coderef. This would be fine, until I hit the logical operators (&& || ?:). Suddenly, this introduced the concept of branching into the code.

It feels like it should be a small job, and so I have been loathe to load up a full parser to do it. Having read Higher Order Perl, I have considered using Dominus' HOP::Parser, but I'm wondering if I should bite the bullet and use one of the standard modules like Parse::RecDescent or Parse::Yapp.

I have no experience with any of these modules. What would you recommend to handle what (in my ignorant opinion) should be a light-weight parsing task?

thanks

Clint

UPDATE : I have now posted my parser here: A parser for a limited grammar