Tag Archive for xclangspec

Xcode for Ruby

Xcode 3’s language support for Ruby is somewhat broken. Fortunately, fixing it only requires a few small modifications.

One major problem, Xcode doesn’t know what .erb and .rake files are.
There should be a file:
/Developer/Library/PrivateFrameworks/DevToolsCore.framework/Versions/Current/Resources/Standard file types.pbfilespec

Copy this to /Library/Application Support/Developer/Shared/Xcode/Specifications/, creating that directory if it doesn’t exist. Editing the original works, but your changes will be overwritten if you update Xcode, better to just override the standard files.
Edit the html-like files entry (line 335 in mine) to add erb:

    // html-like files
          Identifier = text.html.other;
          BasedOn = text.html;
          Extensions = (shtml, jsp, rhtml, erb);

I did the same to add a “rake” file type, around line 543, and also added the line “FilenamePatterns = (“[rR]akefile”);” to detect rakefiles without the .rake extension:

          Identifier = text.script.ruby;
          BasedOn = text.script;
          Extensions = (rb,rbw,rake);
          FilenamePatterns = ("[rR]akefile");
          MagicWord = ("#!/bin/ruby", "#! /bin/ruby", "#!/usr/bin/ruby", "#! /usr/bin/ruby", "#!/usr/local/bin/ruby", "#! /usr/local/bin/ruby");
          ComputerLanguage = shell.ruby;
          Language = "xcode.lang.ruby";
          IsExecutable = YES;

Next, the Ruby language syntax highlighting, selecting, etc need some tweaking. Copy the file
to /Library/Application Support/Developer/Shared/Xcode/Specifications/

By default, Xcode will select too much when doubleclicking. When trying to select an array identifier, it will select the opening [ bracket around the indices.
Go to the lines:

    Identifier = "xcode.lang.ruby.identifier";
    Syntax = {
        StartChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_[";
        Chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_?[]";

And remove the [ and [] characters, which will make selections break at the brackets around array indices.

Now restart Xcode…the changes will not take effect until you do.

Xcode language/syntax definition files for POV-Ray

Xcode 3 allows you to specify the syntax of a language with .xclangspec files, which contain information on the structure of the language that is used not only for syntax coloring, but also for populating the symbols menu, showing the currently selected block with the “Focus Follows Selection” feature, selecting the appropriate amount of text on a double-click, etc.

The POV-Ray syntax specification file is a little crude, work still to be done with it, but already a considerable improvement over the other options on the Mac for editing POV-Ray files.

Place POVRay.pbfilespec and POVRay.xclangspec in /Library/Application Support/Developer/Shared/Xcode/Specifications/ to use, create these directories if they don’t already exist.