Get a handler from a script

Dick Kriesel dick.kriesel at mail.com
Tue Mar 21 03:34:55 EST 2006


On 3/20/06 9:30 PM, "Mark Wieder" <mwieder at ahsoftware.net> wrote:

>>> The best solution I've come up with for removing block comments is
>>> 
>>> put the script of SomeObject into tScript
>>> put token 1 to -1 of tScript into tScript
>>> 
> 
>> This sounded really cool, but I can't get it to work. :(
> 
> Really? What isn't it doing? For me it removes all comments that are
> outside handlers (which is where my block comments are)...

That technique appears to me to work for block comments and line comments
that appear in the script either before the first compilable code or after
the last compilable code.  But it overlooks block and line comments that are
interspersed within the compilable code, and undelimited comments outside
handlers.

In contrast, a repeat loop through the tokens of the script does not see any
line comments anywhere in the script, and does not see the first lines of
any block comments.  In comparison, neither technique removes undelimited
comments outside handlers.

But tokenizing seems unrelated to the challenge of getting a handler from a
script, because it can lose the control structure of a handler.  For
example, consider the following handlers, whose bodies yield the same list
of tokens:

on a
  if the seconds mod 2 = 0 then ask the date;ask the time
end a

on b
  if the seconds mod 2 = 0 then ask the date
  ask the time
end b

Now that I'm considering the variety of valid circumstances for comments,
doomsayers Geoff, Alex, and David are sounding right about this challenge.
But there _ought_ to be a way...

I'd really like to be able to search selected scripts while optionally
ignoring all comments.

-- Dick





More information about the Use-livecode mailing list