m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: submit the following for Gnu m4 documentation


From: Eric Blake
Subject: Re: submit the following for Gnu m4 documentation
Date: Sat, 30 Aug 2008 13:55:14 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080708 Thunderbird/2.0.0.16 Mnenhy/0.7.5.666

-----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             address@hidden
-----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-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]