gnum4

GNU M4: Define a rule that matches text, and operates on that matched text?


Suppose I have:

File:

[x]

And I would like to define m4 macro:

define(`\[.*\]`, ...)

Question: Is this possible and how does one do it?


Solution

  • It isn't possible as you can see in manual of m4:

    3.1 Macro names

    A name is any sequence of letters, digits, and the character ‘_’ (underscore), where the first character is not a digit. m4 will use the longest such sequence found in the input. If a name has a macro definition, it will be subject to macro expansion (see Macros). Names are case-sensitive.

    Examples of legal names are: ‘foo’, ‘_tmp’, and ‘name01’.

    The [ and ] characters aren't legal in macro definition.