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


in reply to Specialty database API.

For the parsing of your language, Parse::RecDescent is usually my go-to for things like this. If your language is not that complex, you may be able to get by with regexes or somesuch, but if you think it's likely to get more complex in the future, the investment into a stronger parser might be worthwhile.

As for accessing someone else's lexical variables in the way you describe, I'm not sure you can, at least not with pure Perl runtime. Have a look at perlguts for a little more information on what's going on behind the scenes. This can be a very dangerous road to go down that can open up many unforeseen consequences, such as what happens with tied variables, especially given the desired asynchronous behavior you've described.

It won't exactly be trivial, but writing a Perl source filter will probably be the most straightforward way to accomplish what you want to do. If you've never worked with filters before, the link has some helpful examples, but the short version is that your custom filter would be given the text of the Perl source code you are running, upon which you can perform any text transformations you like, before Perl parses and compiles the source. So, you could conceivably detect and parse your "DBC" source from within the Perl source, and then convert it into those lower-level API calls you mentioned, before Perl sees it.

Handling the asynchronous dependencies (such as $value being fetched on line 123, and needed again on line 126), will probably require you to maintain some sort of dependency tree. I predict debugging will be fun!