RossNet

FunnelWeb

Reference

Developer

Tutorial
1 Introduction
2 Macros
3 Typesetting
4 Example
5 Hints
6 Examples
7 Webmaking

SEARCH
FunnelWeb Tutorial Manual

5.4 Fiddling With End of Lines

One of the fiddly aspects of programming with FunnelWeb is coping with end of lines. If you want your product file to be well indented without multiple blank lines or code run-ons, you have to spend a little time working out how the end of line markers get moved around.

The rule to remember is that, disregarding the effects of special sequences within a macro body, the body of a macro consists of exactly the text between the opening @{ and the closing @} . This text includes end of line markers.

If for example you call a macro in a sequence of code...

while the_walrus_is_sleepy do
   begin
   writeln('zzzzzzz');
   @<Wake up the walrus@>
   writeln('Umpharumpha...');
   end;

where <wake up the walrus> is defined as follows

@$@<Wake up the walrus@>==@{
wake_up_the_walrus(the_walrus);
@}

then when <Wake up the walrus> is expanded you will get

while the_walrus_is_sleepy do
   begin
   writeln("zzzzzzz");

   wake_up_the_walrus(the_walrus);

   writeln("Umpharumpha...");
   end;

The blank lines were introduced by the end on line markers included in the definition of <Wake up the walrus>. A good solution to this problem is to suppress the end of line markers by defining the macro as follows

@$@<Wake up the walrus@>==@{@-
wake_up_the_walrus(the_walrus);@}

This is the usual form of macro definitions in FunnelWeb files.

In additive macros, this format does not work properly because the end of line that is suppressed by the trailing @} does not get replaced by the end of line at the end of the macro invocation. For example the definition

@$@<Wake up the walrus@>+=@{@-
wake_up_the_walrus_once(the_walrus);@}

later followed by

@$@<Wake up the walrus@>+=@{@-
wake_up_the_walrus_again(the_walrus);@}

is equivalent to the single definition

@$@<Wake up the walrus@>==@{@-
wake_up_the_walrus_once(the_walrus);@-
wake_up_the_walrus_again(the_walrus);@}

Putting the trailing @} on a new line at the end of the macro (except for the last definition part) solves the problem.

@$@<Wake up the walrus@>+=@{@-
wake_up_the_walrus_once(the_walrus);
@}

later followed by

@$@<Wake up the walrus@>+=@{@-
wake_up_the_walrus_again(the_walrus);@}

is equivalent to the single definition

@$@<Wake up the walrus@>==@{@-
wake_up_the_walrus_once(the_walrus);
wake_up_the_walrus_again(the_walrus);@}

Managing end of line markers is tricky, but once you establish a convention for coping with them, the problem disappears into the background.

Prev Up Next


Webmaster    Copyright © Ross N. Williams 1992,1999. All rights reserved.