MACSCRPT Archives

January 2008

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
peter boardman <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Tue, 22 Jan 2008 17:29:10 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (34 lines)
On 21 Jan 2008, at 05:04, T&B wrote:

> Short question:
>
> I want to parse an arbitrary string using a known structure, but  
> respecting (not parsing within) quotes and comments. What's a good  
> way to do this?
> ...
> I've already achieved this using AppleScript code, and it works near  
> perfectly. But that section of my AppleScript code is too slow. It  
> grew over time as a prototype and I always intended to replace it.

First, congratulations on getting Applescript to do anything this!  
It's perhaps not the most suitable language ...

My first reaction is that your workflow has some major problem, if  
you've got to write a language parser using AppleScript -  there  
should be some other solution... But I'm sure you've tried everything  
else...!

I think you should be able to write a simple tokenizer.  A tokenizer  
I've written for scanning source code can process 100 copies of a  
string like your example in 20 milliseconds. The idea is just to read  
the string character by character, switching from one 'mode' to  
another when certain characters are encountered. That way, you don't  
pay any attention to 'special' characters such as parentheses when  
they're inside strings... There's probably much better ways to do it,  
but that's for computer scientists...

If you've already done something similar in AppleScript. In which case  
I'd recommend trying another scripting language for comparison.

cheers!

ATOM RSS1 RSS2