On Jan 17, 2016, at 3:12 AM, Phil Stokes < email@hidden> wrote:
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).
that an heuristic could help provide better error messages for certain cases;
That’s precisely my point. however, your assumption is not currently true, and an heuristic wouldn't apply generally. Application names can contain any valid filename, which includes line breaks (and fun things like the “delete” character).
It should have been clear by what I went on to say that edge cases can be accounted for by having more than one heuristic. Indeed...
And I thought we were discussing detecting mismatched quotes generally,
…in the code I wrote for my pre-compiler, I had a number of rules for detecting mismatched quotes, including a simple count-check (taking into account any preceded by a comment character or escape characters, like “ \” ") as well as a number of checks for certain grammatical constructions following keywords.
To give another example, if you have “tell” and a “set” and and odd number of (non-escaped, non-commented) quote marks between them and no other AS keyword intervening, then you know there’s an error there. That rule would also catch both the code samples I gave earlier. My rule about comment characters on the same line would catch the second code example I gave you (of course, you also have to scan for an opening ‘(*’ and delay judgement until or unless you find a closing ‘*)’). I'm not sure an heuristic that only handles ‘tell application "…’ is going to be useful enough.
Of course it wouldn’t. I’d have thought it clear from the context of the discussion that that heuristic was just an example solution to an example problem. I’m not even necessarily arguing that the particular rules I’ve given here are the best way to do it; I’m simply refuting your “AI” comment with rules that I’ve actually implemented myself.
Are there edge cases that you can come up with that I haven’t accounted for? Sure, we can play whack-a-mole for a few more posts if you like, but my point is that it doesn’t need “AI”; it doesn’t even need rocket science. Just a bit of additional parsing on the code before it gets compiled would do it.
It’d be a massive boon to the “casual users” that AS is supposedly aimed at to have more helpful help on syntactic errors. Seems like a very valid use of the AS team’s time from where I’m standing (well, sitting actually, somewhat uncomfortably).
Best
Phil |