Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm writing a parser which allows Perl callbacks, and I want to make some macros available to the programmer writing the callbacks. An example probably explains most easily. For a grammar rule to do addition
Sum ::= Addend + Addend
the user might want to supply a callback like
sub { <first Addend> + <second Addend> }
In this example, the things in angle brackets are the macros. The idea is that the parser replaces these before the callbacks are compiled.

My question is what's the best syntax to use for macros? I want macros that are easy to use, but on the other hand don't get in the way of Perl constructs, and on the third hand (?) aren't impossible to parse out. Obviously there are tradeoffs. The angle brackets of the above example are, to my mind, not the right choice. They too easily are mistaken for other Perl syntax, both by the programmer and the parser. Note that my primary question is not how to program the macro substitution, but what syntax to use for the macros?

I'm sure other modules have tackled this same issue. Pointers to modules which monks feel did macros right would be very helpful.

thanks, jeffrey kegler


In reply to Best Macro Syntax for Perl? by Jeffrey Kegler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (9)
As of 2024-04-16 09:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found