Friday, June 15, 2018

Parsing AppleScript

Chris Nebel:

AppleScript’s parser works mostly like any other parser: there’s a tokenizer that breaks the input into meaningful pieces, in particular, identifiers. The key difference is that there’s an extra phase to handle multi-word identifiers.

[…]

When reading an app’s dictionary, AppleScript takes all the terminology identifiers, which consist of one or more words, and runs the tokenizer on them to break them into word sequences.

When parsing source and it comes to a word, it starts looking for more immediately following words, greedily matching the longest valid sequence.

[…]

Precedence is fixed. Mostly. There used to be a “tightBindingFunction” flag you could attach to commands, I suspect so you could define a “cos” function that would work in expressions without needing parentheses. I never saw anyone use it, though.

Comments RSS · Twitter

Leave a Comment