Re: MACRO calling

David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Sun, 2 Feb 2003 15:30:24 -0500
Newsgroups gmane.comp.lang.moto.devel
Message-ID <[email protected]>
On Sunday, February 2, 2003, at 01:57  PM, Stefano Corsi wrote:

>  I see that with the actual setup, macro calls are a bit difficult to 
> read,
> for example:
>
> $TABLE_CELL($INPUT_TEXT(Short description \,short_description
> \,$(rset.getString("short_description"))))
>
> and it could be worst with more complex macro with more arguments.
> The fact is that, as far as I could notice, at present macros can be 
> called
> only on a whole line.
>
I agree with you ... this is definitely a bug. Just one I keep 
forgetting to fix :) .

> So I did this little change to motopp.l (a patch (-p1 !!) is attached) 
> so that
> I was able to wrap macro call on multiple lines.
>
> Now I can do something like:
>
> $TABLE_CELL(
> 	$INPUT_TEXT(
> 		Short description \,
> 		short_description \,
> 		$(rset.getString("short_description"))
> 	)
> )
>

Excellent! I've tried the patch. The unput doesn't work quite right 
though. It chops off the first non-whitespace character of the macro 
argument that follows a return. I have modified the patch however to 
not make use of a new TM state and to leave the extra white space in 
for the time being. I don't think the white space is that big of an 
issue. The preferred way to call macros nowadays is to do something like

$TABLE("left","right")

where TABLE is defined

TABLE(left,right) 
<table><tr><td>$($left)</td><td>$($right)</td></tr></table>

using the arguments within moto constructs.

thus calling

$TABLE(
	"left",
	"right"
)

does not change the output since whitespace within constructs is 
ignored.

> The change I have done should leave old macros untouched.
> The lexer handles the new wrapped macros so that it finds a carriage 
> return in
> macro argument state it starts trimming away spaces from the beggining 
> of the
> line to the next non space character.
>
> An example:
>
> MACROC
>  $MACROA(
>     $MACROB(
>         bar\,
>         bar
>     )
>  )
>
> MACROA(arg)
>  A: $arg
>
> MACROB(arg1, arg2)
>  B: $arg1, $arg2
>
> A call to MACROC should give:
>
> "A: B: foo, bar"
>
> and not
>
> "A: 		B: foo, 		bar"
>
> but if we define macros as:
>
> MACROC
>  $MACROA(		$MACROB(		bar\,		bar	))
>
> MACROA(arg)
>  A: $arg
>
> MACROB(arg1, arg2)
>  B: $arg1, $arg2
>
> the lexer take spaces and tabs into account and cluster them in the 
> macro
> argument.
>
> I really don't know if this change has implications or not... only you 
> can
> tell it, probably. (Anyway, all test still pass...)
> But the feature is important to me, to use nested macro effectively.
>

I will be committing our combined change momentarily as soon as I test 
it in some more complex scenarios. For now I have added a small test of 
it to the pp_defs test. Let me know if this fix works for you.

> Stefano
>
>
>
>
> <wrapped_macro_call.patch>