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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.