-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Jack Woehr on 8/30/2008 12:41 PM: > I'd like to submit the following for Gnu m4 documentation since it uses > regexp(), ifelse(), > and substr() recursively in an instructive fashion. This came up in the > PigIron Project <http://pigiron.sourceforge.net> > in autogenerating Java source code from strings cut-and-pasted from API > documentation.
Thanks for the suggestion; and it's nice to see M4 getting some good use. First off, it would be much easier to include something in the manual if you submitted it as a diff against doc/m4.texinfo, rather than merely a snippet of what the output looks like. And your contribution, once improved, will probably be long enough to need copyright assignment to FSF. Is this still something you are interested in pursuing? At any rate, here's some thoughts on the implementation. Your implementation is not robust to active symbols (and in general, substr never is). To be truly robust, you'll have to use tricks such as those found in http://www.gnu.org/software/m4/manual/m4.html#Improved-capitalize. I don't feel comfortable including something in the manual unless it is robust to active macro names. For an example of how your implementation collides with other macro names, look at what happens with javaize_lc(`a_dnl_rindex') (hint: it certainly doesn't give aDnlRindex). > # lowercase a character > define(`lowcase', `translit(`$*', `A-Z', `a-z')') How does this differ from the manual's downcase? > # upcase first char > define(`upcase_initial',`upcase(substr(`$1',0,1))`'substr(`$1',1)') This seems like it is trying to repeat the manual's capitalize macro, but by using substr, it is not robust to active macro names. In general, until qindir is implemented in m4 1.6, substr is basically worthless if you intend to be truly robust to text strings that happen to be macro names. > # Convert an xcc_xcc.. (etc.) to xccXcc... > define(`javaize_lc',`lowcase_initial(javaize(`$1'))') As the manual is about m4, and not Java, I think it would be nicer to use a bit more generic name for this macro; maybe camelcase? - -- Don't work too hard, make some time for fun as well! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAki5paIACgkQ84KuGfSFAYCnegCggqDVoyBcgy/fVZ9uKrATnH3U O1AAoLxxrJIvWy0VLUl5+pKk5uVP9U8B =52sO -----END PGP SIGNATURE----- _______________________________________________ m4-discuss mailing list [email protected] http://lists.gnu.org/mailman/listinfo/m4-discuss
