Short of AI, how do you propose detecting this case?
It doesn’t need AI, Chris, or even a lot of ‘I’ ; I did it myself in my now defunct proto-app “DisplayDroid” for which I wrote a “pre-compiler” to apply various rules before invoking OSAScript’s compileAndReturnError. I’m an amateur, and not a very good one at that, so I find it hard to believe this strikes an Apple programmer as in the realms of “AI”.
The particular case mentioned is easily solved as the compiler (or pre-compiler in my app’s case) can be taught to recognise that after a “tell application" there must be a closed, quoted string before a new line (application names don’t have new line characters in them).
In the code I wrote for my editor, I combined scanner searches looking for AS keywords on each line, and then a bunch of conditionals using the grammar rules of the AS keywords to figure out and highlight various errors. It wasn’t perfect, and nowhere near complete, but with a bit more development none of the difficulties I could see were theoretically insurmountable. It just needed more rules adding, and I would have added them if the app itself (of which the AS editor was only a part) had garnered any interest. Alas, that was not the case.
Scripts containing “run script” I think were my biggest stumbling block. I think because I was parsing the user’s script line by line. I know there’s another way of doing (the way it’s done in Script Debugger), but I never figured out how to do that (Shane or has or someone pointed me to a paper by William Cook* which briefly mentions two different approaches to writing an AS debugger, which I also had a crack at. I basically took the first approach for both my pre-compiler and my debugger, of breaking the user’s script down line by line, checking it and compiling it before putting it all back together again). If I ever get the luxury of time on my hands, I still intend to write my own full AS Editor at some point, but I’d rather you guys just improved the one we’ve got, cos that’s the only reason I want to do it.
Do you know of any compilers for any other languages that could do so? I’m not sure about compilers**, but there’s text editors galore that do basic things like quotation balancing. Xcode’s CodeSense (or whatever it’s called these days) does a great job of the sort of thing I’m talking about as do many other IDE’s. I’m not necessarily asking for anything that sophisticated, but some sort of static analyser** doesn’t seem to be an out-of-this-world-in-the-realms-of-science-fiction request for a language as venerable as AppleScript. Does it?
Best
Phil
**As an untrained, fairly inexperienced and generally sloppy programmer, I tend to throw around technical terms incorrectly, so whether or not it’s the compiler/static analyser or some other part of the program that does the work I’m talking about is not really the issue (though it may confuse the way I state the issue). I basically want an AS Editor which does a better job at helping users determine and fix errors before runtime (and during if possible, but I know that asking for a debugger probably is asking for too much).
|