320 |
* Active Characters:: Characters that change the behavior of m4 |
* Active Characters:: Characters that change the behavior of m4 |
321 |
* One Macro Call:: Quotation and one macro call |
* One Macro Call:: Quotation and one macro call |
322 |
* Quotation and Nested Macros:: Macros calling macros |
* Quotation and Nested Macros:: Macros calling macros |
323 |
|
* Changequote is Evil:: Worse than INTERCAL: M4 + changequote |
324 |
* Quadrigraphs:: Another way to escape special characters |
* Quadrigraphs:: Another way to escape special characters |
325 |
* Quotation Rule Of Thumb:: One parenthesis, one quote |
* Quotation Rule Of Thumb:: One parenthesis, one quote |
326 |
|
|
6386 |
* Active Characters:: Characters that change the behavior of m4 |
* Active Characters:: Characters that change the behavior of m4 |
6387 |
* One Macro Call:: Quotation and one macro call |
* One Macro Call:: Quotation and one macro call |
6388 |
* Quotation and Nested Macros:: Macros calling macros |
* Quotation and Nested Macros:: Macros calling macros |
6389 |
|
* Changequote is Evil:: Worse than INTERCAL: M4 + changequote |
6390 |
* Quadrigraphs:: Another way to escape special characters |
* Quadrigraphs:: Another way to escape special characters |
6391 |
* Quotation Rule Of Thumb:: One parenthesis, one quote |
* Quotation Rule Of Thumb:: One parenthesis, one quote |
6392 |
@end menu |
@end menu |
6647 |
Also, because @code{qar} behaves differently from the other macros, |
Also, because @code{qar} behaves differently from the other macros, |
6648 |
it's an exception that should be avoided in Autoconf. |
it's an exception that should be avoided in Autoconf. |
6649 |
|
|
6650 |
|
@node Changequote is Evil |
6651 |
|
@subsection @code{changequote} is Evil |
6652 |
|
|
6653 |
|
The temptation is often high to bypass proper quotation, in particular |
6654 |
|
when it's late at night. Then, many experienced Autoconf hackers |
6655 |
|
finally surrender to the dark side of the force and use the ultimate |
6656 |
|
weapon: @code{changequote}. |
6657 |
|
|
6658 |
|
The M4 builtin @code{changequote} belongs to a set of primitives that |
6659 |
|
allow one to adjust the syntax of the language to adjust it to her |
6660 |
|
needs. For instance, by default M4 uses @samp{`} and @samp{'} as |
6661 |
|
quotes, but in the context of shell programming (and actually of most |
6662 |
|
programming languages), it's about the worst choice one can make: |
6663 |
|
because of strings and back quoted expression in shell (such as |
6664 |
|
@samp{'this'} and @samp{`that`}), because of literal characters in usual |
6665 |
|
programming language (as in @samp{'0'}), there are many unbalanced |
6666 |
|
@samp{`} and @samp{'}. Proper M4 quotation then becomes a nightmare, if |
6667 |
|
not impossible. In order to make M4 useful in such a context, its |
6668 |
|
designers have equipped it with @code{changequote}, which makes it |
6669 |
|
possible to chose another pair of quotes. M4sugar, M4sh, Autoconf, and |
6670 |
|
Autotest all have chosen to use @samp{[} and @samp{]}. Not especially |
6671 |
|
because they are unlikely characters, but @emph{because they are |
6672 |
|
characters unlikely to be unbalanced}. |
6673 |
|
|
6674 |
|
There are other magic primitives, such as @code{changecom} to specify |
6675 |
|
what syntactic forms are comments (it is common to see |
6676 |
|
@samp{changecom(<!--, -->)} when M4 is used to produce HTML pages), |
6677 |
|
@code{changeword} and @code{changesyntax} to change other syntactic |
6678 |
|
details (such as the character to denote the n-th argument, @samp{$} by |
6679 |
|
default, the parenthesis around arguments etc.). |
6680 |
|
|
6681 |
|
These primitives are really meant to make M4 more useful for specific |
6682 |
|
domains: they should be considered like command line options: |
6683 |
|
@option{--quotes}, @option{--comments}, @option{--words}, and |
6684 |
|
@code{--syntax}. Nevertheless, they are implemented as M4 builtins, as |
6685 |
|
it makes M4 libraries self contained (no need for additional options). |
6686 |
|
|
6687 |
|
There lies the problem... |
6688 |
|
|
6689 |
|
@sp 1 |
6690 |
|
|
6691 |
|
The problem is that it is then tempting to use them in the middle of an |
6692 |
|
M4 script, as opposed to its initialization. This, if not carefully |
6693 |
|
thought, can lead to disastrous effects: @emph{you are changing the |
6694 |
|
language in the middle of the execution}. Changing and restoring the |
6695 |
|
syntax is often not enough: if you happened to invoke macros in between, |
6696 |
|
these macros will be lost, as the current syntax will probably not be |
6697 |
|
the one they were implemented with. |
6698 |
|
|
6699 |
|
@c FIXME: I've been looking for a short, real case example, but I |
6700 |
|
@c lost them all :( |
6701 |
|
|
6702 |
|
|
6703 |
@node Quadrigraphs |
@node Quadrigraphs |
6704 |
@subsection Quadrigraphs |
@subsection Quadrigraphs |