A hard challenge anyone?
Kay C Lan
lan.kc.macmail at gmail.com
Thu Feb 15 10:14:42 EST 2007
On 2/15/07, David Bovill <david at openpartnership.net> wrote:
>
> Thanks Ken! I will test your approach out against the quick hack that I
> have
> in place and send you the pictures!
I've just realised a problem with my approach. It doesn't work for any line
that contains an unmatched number of ( and ) or where they may appear in
quoted text. For instance a line of code such as:
offset("(","some text containing a ( and a )")
will not yield the correct result.
How often is this likely to occur? Looking at my own script yields 2 such
lines - the first two CASE structures. Running my script on my own script
results in two nonsensical functions being reported:-(
On the other hand, running the suggested 'tokens script' on my script
produces a nightmare of words and characters that would need to be sifted
through.
Personally I think the number of cases where the brackets are uneven is so
low that you could include another CASE structure that checked for it and
just popped up an 'ask' dialog with the line in question as the default so
that you could sensibly edit the line.
The situation where the brackets match, but some are in quoted strings, as
in
offset("z","some text that happens to have sin(a + b)/tan(y * z)")
should be solvable. Without too much thought (always a problem) - "
should??? always be matched so
CASE (char tMyChar of tMyData = quote)
Should be able to keep track of when one occurs, then at the next instance
of " replace the text from the first character to the current char with some
random char - you can't just delete them as it will mess up the repeat loop
which is based on the original number of chars in the line.
HTH
More information about the use-livecode
mailing list