• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Syntax highlighting, compilation etc.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syntax highlighting, compilation etc.


  • Subject: Re: Syntax highlighting, compilation etc.
  • From: Shane Stanley <email@hidden>
  • Date: Mon, 24 Apr 2017 22:39:31 +1000

On 24 Apr 2017, at 10:11 pm, Jean-Christophe Helary <email@hidden> wrote:

I'm wondering where the syntax highlighting information is "stored".

When the script is compiled, it becomes a binary file that, well, is binary. When it is opened in SE or any AS supporting editor (currently only 3 it seems), the script gets decompiled and is highlighted.

But, where does that syntax information comes from ?

It comes from the AppleScript compiler, which reads the various styles from AppleScript's persistent defaults. 

In code terms, Script Editor creates an instance of AppleScript in the host, passing the code as text. It then tells the script to compile, and assuming it does, it then asks for its styled source, which is returned as an attributed string. The compiled script is essentially what's saved to disk. In code:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

-- create a new AppleScript instance
set anOSALanguageInstance to current application's OSALanguageInstance's languageInstanceWithLanguage:(current application's OSALanguage's defaultLanguage())
-- make script and run it from the new instance
set theSource to "display dialog \"Hello world\""
set theScript to current application's OSAScript's alloc()'s initWithSource:theSource fromURL:(missing value) languageInstance:anOSALanguageInstance usingStorageOptions:(current application's OSANull)
set {theResult, theError} to theScript's compileAndReturnError:(reference)
if theResult as boolean is false then
-- handle error
else
set sourceText to theScript's source()
set styledSourceText to theScript's richTextSource()
end if

Run that in Script Debugger and you will see what styledSourceText looks like.

Other editors may use the original Carbon APIs; OSAScript is just an Objective-C wrapper around them.

The important point, from your perspective, is that compilation and styling a completely opaque process.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Syntax highlighting, compilation etc.
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >Syntax highlighting, compilation etc. (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Syntax highlighting, compilation etc.
  • Next by Date: Re: Syntax highlighting, compilation etc.
  • Previous by thread: Syntax highlighting, compilation etc.
  • Next by thread: Re: Syntax highlighting, compilation etc.
  • Index(es):
    • Date
    • Thread