m4: Changecom
1
1 8.3 Changing the comment delimiters
1 ===================================
1
1 The default comment delimiters can be changed with the builtin macro
1 'changecom':
1
1 -- Builtin: changecom ([START], [END = '<NL>'])
1 This sets START as the new begin-comment delimiter and END as the
1 new end-comment delimiter. If both arguments are missing, or START
1 is void, then comments are disabled. Otherwise, if END is missing
1 or void, the default end-comment delimiter of newline is used. The
1 comment delimiters can be of any length.
1
1 The expansion of 'changecom' is void.
1
1 define(`comment', `COMMENT')
1 =>
1 # A normal comment
1 =># A normal comment
1 changecom(`/*', `*/')
1 =>
1 # Not a comment anymore
1 =># Not a COMMENT anymore
1 But: /* this is a comment now */ while this is not a comment
1 =>But: /* this is a comment now */ while this is not a COMMENT
1
1 Note how comments are copied to the output, much as if they were
1 quoted strings. If you want the text inside a comment expanded, quote
1 the begin-comment delimiter.
1
1 Calling 'changecom' without any arguments, or with START as the empty
1 string, will effectively disable the commenting mechanism. To restore
1 the original comment start of '#', you must explicitly ask for it. If
1 START is not empty, then an empty END will use the default end-comment
1 delimiter of newline, as otherwise, it would be impossible to end a
1 comment. However, this is not portable, as some other 'm4'
1 implementations preserve the previous non-empty delimiters instead.
1
1 define(`comment', `COMMENT')
1 =>
1 changecom
1 =>
1 # Not a comment anymore
1 =># Not a COMMENT anymore
1 changecom(`#', `')
1 =>
1 # comment again
1 =># comment again
1
1 The comment strings can safely contain eight-bit characters. If no
1 single character is appropriate, START and END can be of any length.
1 Other implementations cap the delimiter length to five characters, but
1 GNU has no inherent limit.
1
1 Comments are recognized in preference to macros. However, this is
1 not compatible with other implementations, where macros and even quoting
1 takes precedence over comments, so it may change in a future release.
1 For portability, this means that START should not begin with a letter,
1 digit, or '_' (underscore), and that neither the start-quote nor the
1 start-comment string should be a prefix of the other.
1
1 define(`hi', `HI')
1 =>
1 define(`hi1hi2', `hello')
1 =>
1 changecom(`q', `Q')
1 =>
1 q hi Q hi
1 =>q hi Q HI
1 changecom(`1', `2')
1 =>
1 hi1hi2
1 =>hello
1 hi 1hi2
1 =>HI 1hi2
1
1 Comments are recognized in preference to argument collection. In
1 particular, if START is a single '(', then argument collection is
1 effectively disabled. For portability with other implementations, it is
1 a good idea to avoid '(', ',', and ')' as the first character in START.
1
1 define(`echo', `$#:$*:$@:')
1 =>
1 define(`hi', `HI')
1 =>
1 changecom(`(',`)')
1 =>
1 echo(hi)
1 =>0:::(hi)
1 changecom
1 =>
1 changecom(`((', `))')
1 =>
1 echo(hi)
1 =>1:HI:HI:
1 echo((hi))
1 =>0:::((hi))
1 changecom(`,', `)')
1 =>
1 echo(hi,hi)bye)
1 =>1:HI,hi)bye:HI,hi)bye:
1 changecom
1 =>
1 echo(hi,`,`'hi',hi)
1 =>3:HI,,HI,HI:HI,,`'hi,HI:
1 echo(hi,`,`'hi',hi`'changecom(`,,', `hi'))
1 =>3:HI,,`'hi,HI:HI,,`'hi,HI:
1
1 It is an error if the end of file occurs within a comment.
1
1 changecom(`/*', `*/')
1 =>
1 /*dangling comment
1 ^D
1 error->m4:stdin:2: ERROR: end of file in comment
1