On Fri, 09 May 2008, frank van nuffel wrote:

Hi Frank,

> the #define is on _EXPAND_() not on _EXPAND_, so #undef _EXPAND_
> won't be substituted, but at the same time it #undef's _EXPAND_()

Yes, you are right. I missed. Sorry I should more carefully check
your example.

> >It's for Harbour only. If you want to adopt it to Clipper then you have
> >to make the trick with #include I've written above: create file undef.ch
> >with one line:
> >  #undef  _EXPAND_
> >and in the above code change:
> >  #undef  _EXPAND_
> >to:
> >  #include "undef.ch"
> >Such tricks makes also class(y).ch
> i'm aware of such construct, but it isn't necessary here (see above)

Not exactly. There are situations when using indirect #include resolves
some problems which cannot be easu addressed using Clipper's PP.
I updated your example to work with Clipper and Harbour and to not use
overloaded #[x]trans rules.


/* --- system definitions ----- */

#xCOMM  MACRO SECTION BEGIN   => #undef _EXPAND_
#xCOMM  MACRO <f>( [ <a,...> ] ) <b> => #define <f>( <a> )  ;
               ANY_DEF( ppparam, ( _SUSPAND_() <f> | <b>, <a> ) _EXPAND_() )
#xCOMM  MACRO SECTION END     => #define _EXPAND_()

#xCOMM  MACRO SUSPEND         => #undef  _SUSPAND_
#xCOMM  MACRO RESUME          => #define _SUSPAND_()

#define _REPEAT_()
#define ANY_DEF( x, y )       ANY_TRANS( x, y )
#xTRAN  ANY_TRANS( <x>, ( [<s:_SUSPAND_()>] <y,...> ) ) => ;
                              <x>( _REPEAT_() <s> <y> )

#xTRAN           ppparam(               <f> | <b> [, <a,...>] ) => <b>
#xTRAN           ppparam(  _SUSPAND_()  <f> | <b> [, <a,...>] ) => <f>( <a>, )

# TRAN function  ppparam( [_SUSPAND_()] <f> | <b> [, <a,...>] ) => ;
       func <f> ; PARAM <a>
# TRAN procedure ppparam( [_SUSPAND_()] <f> | <b> [, <a,...>] ) => ;
       func <f> ; PARAM <a>

/* --- end of system definitions ----- */

Please look that if you want to use _SUSPAND_() define then it's
necessary to force switching translation to defines. ANY_DEF() does it.
Unlike the previous one current Harbour's PP uses the same algorithm
for rule parsing as Clipper so it's necessary also in Harbour.
In this test instead of '%%' you were usinf I used _REPEAT_() define.
It makes exactly the same job in changing substitution precedence as
%% in your examples though it also forces parsing DEFINEs. If you do
not want to parse define (in this example is not necessary) then you
can change #define _REPEAT_() to #xtrans _REPEAT_() =>
I hope it may help you to understand the exact substitution precedence
used by PP which is different then described in Clipper documentation.
In fact it looks like:

   1. substitute _ALL_ DEFINEs
   2. if anything was substituted in last pass goto 1
   3. substitute _ALL_ #[x]TRANs
   4. if anything was substituted in last pass goto 3
   5. if anyhthing was substituted in any of #[x]TRANs passes goto 1
   6. substitute _ALL_ #[x]COMMANDs
   7. if anything was substituted in last pass goto 6
   8. if anyhthing was substituted in any of #[x]COMMANDs passes goto 1

> >If you need general solution then we should introduce new PP token
> >which is significant for PP but neutral for compiler. F.e. <->
> >as result marker.
> >  #trans func( <a,...> ) => func( <-> 1, <a> )
> >The <-> in result pattern will block infinite translation and because
> >it will be invisible for compiler then it will not break compilation
> >process. I can add such marker in the future.
> And you did!  That would be welcome, i vote for!

Probably we should discuss it. I think it will be good to also have
named invisible markers which can be used in other rules. I hope that
after 1.0 we can return to this discussion.

best regards,
Przemek
_______________________________________________
Harbour mailing list
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to