Hello Januk,
Monday, July 30, 2001, 4:39:08 AM, you wrote:

M>> Uuuugh. That's why I suggested converting the "quoted" macros to
M>> (bracketed) ones. Turning %IF:"expr"=="val":"true":"false" would
M>> look better as %IF("expr"=="val":"true":"false"), as the brackets
M>> would clearly identify where the %IF starts and ends. That goes
M>> for all %REGEXP... macros, and probably all of them as well.

JA> I think you've got a good idea, but how would you solve this one:
JA> Suppose your string needs a closing bracket ")" but no opening
JA> bracket.  A silly example is:
JA> %IF("%DOW"="Friday":"It's almost the weekend ;-)":"")
JA> Don't you still have the same problem?  Or can you get rid of the
JA> quotation marks inside as well?

No problem here. The parser would just go from left to right and count
brackets and quotes, in a stack-like structure... And a bit of
recursion, too. It's untested YET, but after some testing and tweaking
it COULD be used "as is", if the RIT labs would kindly decide to
use it...
It supports all kinds of macros-in-macros. The quotes could be left
out to turn mildly-obsolete %MACRO("something")'s into simplier
%MACRO(something) in which the quotes would no longer be treated in a
special way, but right now it needs quotes for inline right brackets
%MACRO(":-)"). That would be easier with \backslashing, but...


function ParseString (line:string) : string;
var OutputString:string;
    macroname,macroparams:string;
    c:char;
    i:integer;
begin
  line:=line+' ';  // a safeguard for one-character lookaheads
  for i:=1 to length(line)-1 do begin
    c:=line[i];
    if ((c='%') and (TopOfStack<>'macro')) then PushToStack ('macro')
      else
    // if it's no longer a macro name, run it
    if (not (upcase(c) in ['A'..'Z','0'..'9','%','-','(']) and (TopOfStack='macro')) 
then begin
      PopFromStack;
      OutputString:=OutputString + ParseMacro(macroname,'') + c;
    end
      else
    // if it's a macro name, collect it
    if ((upcase(c) in ['A'..'Z','0'..'9','%','-']) and (TopOfStack='macro')) then 
macroname:=macroname+c
      else
    // remember the bracket only after the macro name, otherwise it's just a bracket
    if ((c='(') and (TopOfStack='macro')) then PushToStack ('bracket');
      else
    // inside the parameters remember quotes
    if ((c='"') and (TopOfStack='bracket')) then PushToStack('quote')
      else
    if ((c='"') and (line[i+1]<>'"') and (TopOfStack='quote') then PopFromStack
      else
    if ((c=')') and (TopOfStack='bracket')) then begin
      PopFromStack; // there goest the 'bracket'
      PopFromStack; // and the 'macro'
      OutputString:=OutputString + ParseMacro(macroname,ParseString(macroparams));
      macroname:='';
      macroparams:='';
    end
      else
    if (TopOfStack='bracket') then macroparams:=macroparams+c
      else
    OutputString:=OutputString+c;

    if ((macroname='-') or (macroname='%')) then begin
      PopFromStack;
      OutputString:=OutputString+ParseMacro(macroname,'');
    end;
  end;
end;



Alas, I'm damn sure the RIT guys won't use even one line of my code. I
already offered to write some small nifty pieces of code for them
(like, an advanced mail filtering script, or this macro handling I've
outlined above) and have been ignored so far. Too bad. It was to be
all for free, but... Oh well. Maybe it's their policy or something...

-- 
MaXxX

-- 
______________________________________________________
Archives   : <http://tbtech.thebat.dutaint.com>
Moderators : <mailto:[EMAIL PROTECTED]>
Unsubscribe: <mailto:[EMAIL PROTECTED]>


Reply via email to