[Haskell-cafe] Better integration with Xcode

haskell cafe haskellcafe at gmail.com
Wed Nov 6 23:55:45 UTC 2013

On Tue, Nov 5, 2013 at 5:05 PM, haskell cafe <haskellcafe at gmail.com> wrote:

> You can directly edit Haskell in Xcode (with very basic syntax
> highlighting)

Here's how I got (basic) syntax highlighting for Haskell in Xcode:

I should start by saying that unlike my other post, this is totally
unsupported and that this involves modifying Xcode's bundle. While it
mainly just involves adding a plist file to the bundle and modifying an
existing plist, it is still potentially dangerous and you will likely have
to re-do it every time you update Xcode. You have been warned.

Also, this only adds syntax coloring for keywords, strings, characters, and
numbers. Unfortunately, it doesn't do coloring of variables, types, and
other identifiers. Xcode doesn't generally color operators, though you
could add the built-in ones to the list of keywords if you want it to also
color them.

Given all that, if you still want to proceed, here's what you need to do:

1) Copy Haskell.xclangspec (included at the bottom of this email) into
(Assuming you've installed Xcode into /Applications/.) This will require
admin privileges on the machine you're running Xcode on.

2) Save the following as "~/Desktop/Haskell.plist" (or wherever is
convenient for you) :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "
<plist version="1.0">

                <string>Haskell Language</string>

3) Make a copy of the file:


and put it somewhere safe in case you mess it up in the next step.

4) Using PlistBuddy, add the above into DVTFoundation.xcplugindata (in the
same directory as the stuff in step 1), by doing the following on the
command-line (this should all be one line) :

-c 'Merge ~/Desktop/Haskell.plist plug-in:extensions'

You may need to use "sudo" to run the above command. (In other words type
"sudo /usr/libexec/PlistBuddy …<rest of above command>…") Note that if you
saved the above file somewhere other than your desktop, you'll need to
change the path in the "Merge" command to match wherever you put it. If you
somehow messed it up and need to undo it, you can use the following command
to remove what you just added:

'Delete :plug-in:extensions:Xcode.SourceCodeLanguage.Haskell'

Again, you'll probably need to use 'sudo' to run that command, too.

5) Once you've done the above, you'll notice Xcode's "Editor" > "Syntax
Coloring" menu now includes "Haskell" as an option. Simply open your
Haskell source file and choose "Haskell" from the "Syntax Coloring" submenu!

Here is the Haskell.xclangspec. It's probably not perfect. I created it by
looking at the C and Fortran .xclangspec files and copying their format. I
used the information from the Haskell Language Spec <
http://www.haskell.org/haskellwiki/Language_and_library_specification>. If
you have suggestions for changes, let me know, or just post them:

// Haskell

// MARK: Haskell Keywords

        Identifier = "xcode.lang.haskell.keyword";
        Syntax = {
            StartChars = "abcdefghijklmnopqrstuvwxyz";
            Chars =
            Words = (
            Type = "xcode.syntax.keyword";
            AltType = "xcode.syntax.identifier";    // non-keywords are

// MARK: Haskell Coloring

        Identifier = "xcode.lang.haskell";
        Description = "Haskell Coloring";
        BasedOn = "xcode.lang.simpleColoring";
        IncludeInMenu = YES;
        Name = "Haskell";
        Syntax = {
            IncludeRules = (        // processed in order
            Type = "xcode.syntax.plain";

        Identifier = "xcode.lang.haskell.comment.singleline";
        Syntax = {
            Start = "--";
            End = "\n";
            IncludeRules = ( "xcode.lang.url", "xcode.lang.url.mail",
"xcode.lang.comment.mark" );
            Type = "xcode.syntax.comment";

        Identifier = "xcode.lang.haskell.comment";
        Syntax = {
            Start = "{-";
            End = "-}";
            IncludeRules = ( "xcode.lang.url", "xcode.lang.url.mail",
"xcode.lang.comment.mark" );
            Type = "xcode.syntax.comment";

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131106/cd6d2ceb/attachment.html>

More information about the Haskell-Cafe mailing list