{"id":21833,"date":"2018-06-15T16:20:37","date_gmt":"2018-06-15T20:20:37","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=21833"},"modified":"2018-06-15T16:20:37","modified_gmt":"2018-06-15T20:20:37","slug":"parsing-applescript","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/06\/15\/parsing-applescript\/","title":{"rendered":"Parsing AppleScript"},"content":{"rendered":"<p><a href=\"https:\/\/twitter.com\/nebelch\/status\/1007684674896912384\">Chris Nebel<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/nebelch\/status\/1007684674896912384\">\n<p>AppleScript&rsquo;s parser works mostly like any other parser: there&rsquo;s a tokenizer that breaks the input into meaningful pieces, in particular, identifiers.  The key difference is that there&rsquo;s an extra phase to handle multi-word identifiers.<\/p>\n<p>[&#8230;]<\/p>\n<p>When reading an app&rsquo;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.<\/p>\n<p>When parsing source and it comes to a word, it starts looking for more immediately following words, greedily matching the longest valid sequence.<\/p>\n<p>[&#8230;]<\/p>\n<p>Precedence is fixed.  Mostly.  There used to be a &ldquo;tightBindingFunction&rdquo; flag you could attach to commands, I suspect so you could define a &ldquo;cos&rdquo; function that would work in expressions without needing parentheses.  I never saw anyone use it, though.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Chris Nebel: AppleScript&rsquo;s parser works mostly like any other parser: there&rsquo;s a tokenizer that breaks the input into meaningful pieces, in particular, identifiers. The key difference is that there&rsquo;s an extra phase to handle multi-word identifiers. [&#8230;] When reading an app&rsquo;s dictionary, AppleScript takes all the terminology identifiers, which consist of one or more words, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2018-06-15T20:20:38Z","apple_news_api_id":"44cb1a2b-c732-4ee5-9526-38aa56dd3d36","apple_news_api_modified_at":"2018-06-15T20:20:39Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/ARMsaK8cyTuWVJjiqVt09Ng","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[159,46,30,1529,270,71],"class_list":["post-21833","post","type-post","status-publish","format-standard","hentry","category-technology","tag-applescript","tag-languagedesign","tag-mac","tag-macos-10-13","tag-parser","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=21833"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21833\/revisions"}],"predecessor-version":[{"id":21834,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/21833\/revisions\/21834"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=21833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=21833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=21833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}