rejetto forum

Alias and Macros

Mars · 6 · 4119

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
With Silentpliz, we set up craftiness in the French version which allows to force the use of the internal macro of hfs (not the alias), even in case a macro is overloaded by one alias.

The adaptation is simple:

It is enough to make precede the name of the macro with the character _ as in this example


[special:alias]
comment={.add to log|this is an alias : $1.}


[]
{.comment|comment one.}
{._comment|comment two.}

Quote
    // here we try to handle some shortcuts.
    // it's a special starting character that identifies the macro, and the rest of the name is a parameter.
    p:=copy(name,2,MAXINT);

    if name[1] = '$' then
      try section(0); exit; except end;

    if name[1] = '!' then
      // we look for p (they key) in {.^special:strings.} then in [special:strings]. If no luck, we try to output an eventual parameter, or the key itself.
      try result:=first([fromTable('special:strings',p), md.tpl.getStrByID(p), par(0), p]); exit; except end;

    if name[1] = '^' then
      try call(getVar(p), 0); exit; except end;

    if name[1] = '?' then  // shortcut for 'urlvar'
      try result:=urlvar(p); exit; except end;


    // handle aliases //moved
    if assigned(md.aliases) and not (name[1] = '_') then

      begin
      s:=md.aliases.values[name];
      if s > '' then
        begin
        if not AnsiStartsStr(MARKER_OPEN, s) then
          s:=MARKER_OPEN+s+MARKER_CLOSE;
        call(s, 0);
        exit;
        end;
      end;

    if name[1] = '_' then name:=copy(name,2,MAXINT);

    p:=par(0); // a handy shortcut for the first parameter


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
as i explained you once, i consider this overloading a feature.
thanks for sharing, anyway.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
as i explained you once, i consider this overloading a feature.

Certainly, I remember it, but if you looked well and analyzed the code which I proposed, the overloading is not questioned:

The only thing where I do not agree with you is the order of analysis; according to me the macro which begin by ( ^, $ , ! , ? ) are not to be overloaded in, and on this last point I believe that the majority will be of my opinion.

In your overload of macro, I add simply the possibility of choosing between the macro overloaded by one alias and the macro primary, which I call by preceding its name by one '_', the primary macro '_macro' being priority on quite alias of the same name.

My proposition is not a review but a step furthermore forward while respecting your desires: unless you wish to use the character _ in quite other thing.

if assigned(md.aliases) and not (name[1] = '_') then
      //overload macro
       ....
      // ELSE
if name[1] = '_' then name:=copy(name,2,MAXINT);


Especially since with your code, one alias of the following chap do not can be overloaded by using the same primary macro,
macroRejetto=macroRejetto|$1|$3|texte1|$2

While with my extension, it is possible to change the order or the quantity of parameters of an existing macro, with no problem at all

In macroMars =_macroMars|$1|$3|texte1|$2

Scripters will have the choice to use or not this possibility without constraint.

[color=red]I am going eventually rerelease my boxing gloves  [/color] :-\, set silentpliz as referee and bacter to count points;D

Very friendly, Mars.  ;)
  
« Last Edit: June 12, 2010, 10:06:12 AM by Mars »


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
Code: [Select]
ah, alright

1. did you face a situation where this was useful?

2. do you consider this a frequent need? because shortcuts like the _ should be kept for frequent things, since they are also very cryptic (you cannot guess what "_" is meaning).
It may be replaced by this form {.original|comment|....}

A way to get this could be to replace this
[code]
    name:=trim(pars[0]);
    pars.delete(0);
    if name = '' then exit;

with this

Code: [Select]
  repeat
  name:=trim(pars[0]);
  pars.delete(0);   
  if name = '' then exit;
  if name <> 'original' then break;
  original:=TRUE;   
  until false;

and then
Code: [Select]
if assigned(md.aliases) thenby this
Code: [Select]
if not original and assigned(md.aliases) then
It's all untested, written directly on the forum.

Quote
according to me the macro which begin by ( ^, $ , ! , ? ) are not to be overloaded in, and on this last point I believe that the majority will be of my opinion.
if name[1] = '_' then name:=copy(name,2,MAXINT);

what are we going to gain by this?[/code]


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
do a test with this part of template

[rejetto]
simple text

[special:alias]
$rejetto={.add to log|es-tu convaincu par la nécessité de ne pas remplacer les ( ^, $ , ! , ? ) par des alias?.}
-----------
put the 'macro'  {.$rejetto.} inside a diff template and see what append in the browser and in the log


Alias can supplant everything besides the macro: sections ($) , variables (^), urlvars (?).... and the stringvars (!)

I that does well to me to laugh.

It's as if we removed panels ' attention danger ' at the edge of an abyss. How then try to debug a template with the risks of confusions engendered by alias if we preserve your formulation.

***************************************************************************************
Quote
It may be replaced by this form {.original|comment|....}

I see that you adopt the same tactics as me but by changing the call to the macro. And in more it is longer in a template. but you create a boolean var and you have to manage it. Me, i just delete the char '_' in the front of macro.

if (name[1] <> '_') and assigned(md.aliases)  then
      //overload macro by alias
       ....
      // ELSE
if name[1] = '_' then name:=copy(name,2,MAXINT);
     //continue to manage macro
   

If it is necessary to be self-assured that it is necessary to add 'original|' in quite the macro including those with (^,$,!,?) then I prefer and recommend to use the character '_' which meets in the other languages on the same principle of call of procedure

I know what you are going to say to me: " we do not find that in the scripts generally."


what do you thing about

[special:alias]
$original=original|original                 --->>  infinite loop    ;D

-----------------------------
[special:alias]
$original=_comment|_comment       }--->>> macro error     ;)  this is good
_comment=_comment|_comment    }



Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
Quote
do you consider this a frequent need? because shortcuts like the _ should be kept for frequent things, since they are also very cryptic (you cannot guess what "_" is meaning).
It may be replaced by this form {.original|comment|....}

are you decided to change all macro

$name    by   section|name
?var       by   urlvars|var
^name   by   var|name
!text      by   string|name



After careful consideration we can associate your point of view and my good idea

{.original comment|blablabla.}

{.original if|is true|then|else.}  

I use no pipe between original and name

Quote
if not ansiStartsStr('original ',name) and assigned(md.aliases)  then    ;D
      //overload macro by alias
       ....
      // ELSE

if ansiStartsStr('original ',name) then name:=copy(name,9,MAXINT);  ;)
     ------------
    

only two lines to do what it's necessary  :)
and working

« Last Edit: June 15, 2010, 02:10:34 PM by Mars »