[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
/Applications/Xcode/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/.
(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" "
http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Xcode.SourceCodeLanguage.Haskell</key>
        <dict>
                <key>languageSpecification</key>
                <string>xcode.lang.haskell</string>
                <key>fileDataType</key>
                <array>
                        <dict>
                                <key>identifier</key>
                                <string>public.haskell-source</string>
                        </dict>
                </array>
                <key>id</key>
                <string>Xcode.SourceCodeLanguage.Haskell</string>
                <key>point</key>
                <string>Xcode.SourceCodeLanguage</string>
                <key>languageName</key>
                <string>Haskell</string>
                <key>version</key>
                <string>1.0</string>
                <key>conformsTo</key>
                <array>
                        <dict>
                                <key>identifier</key>

<string>Xcode.SourceCodeLanguage.Generic</string>
                        </dict>
                </array>
                <key>name</key>
                <string>Haskell Language</string>
                <key>documentationAbbreviation</key>
<string>hs</string>
        </dict>
</dict>
</plist>

3) Make a copy of the file:

/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/DVTFoundation.xcplugindata

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) :

/usr/libexec/PlistBuddy
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/DVTFoundation.xcplugindata
-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:

/usr/libexec/PlistBuddy
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/DVTFoundation.xcplugindata
-c
'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 =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'";
            Words = (
                "case",
                "class",
                "data",
                "default",
                "deriving",
                "do",
                "else",
                "foreign",
                "import",
                "if",
                "in",
                "infix",
                "infixl",
                "infixr",
                "instance",
                "let",
                "module",
                "newtype",
                "of",
                "then",
                "type",
                "where",
                "_",
            );
            Type = "xcode.syntax.keyword";
            AltType = "xcode.syntax.identifier";    // non-keywords are
identifiers
        };
    },

/****************************************************************************/
// MARK: Haskell Coloring
/****************************************************************************/

    {
        Identifier = "xcode.lang.haskell";
        Description = "Haskell Coloring";
        BasedOn = "xcode.lang.simpleColoring";
        IncludeInMenu = YES;
        Name = "Haskell";
        Syntax = {
            IncludeRules = (        // processed in order
                "xcode.lang.haskell.comment.singleline",
"xcode.lang.haskell.comment",
                "xcode.lang.string",
                "xcode.lang.character",
                "xcode.lang.number",
                "xcode.lang.haskell.keyword",
            );
            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