We used CLIPS, a forward chaining production system in some artificial intelligence and cognitive engineering classes as well as Pyps, a sort of Python “CLIPS Light” that the professor Dr. Chris Darken worked up. Since I love TextMate so much, I wanted a more TextMate-like experience, so I worked up a bundle for CLIPS (and Pyps).

clips-picture-1

Download

Download the TextMate CLIPS bundle here.

clips-icon

Installation

After downloading the zip file above, expand it, and you’ll have a file/bundle called CLIPS (or possible CLIPS.tmbundle if the extension is showing). Move this bundle to your TextMate bundles folder:

clips-picture-3

You’ll need to create this folder (or folders) if they are not already there.

Quit and restart TextMate.

Usage

You’ll now have CLIPS-specific formatting and a few commands available to you. If your filename ends with .clp or .pyp, TextMate should automatically make the CLIPS bundle the active one. If it does not, you can select CLIPS manually at the bottom of the editor window:

clips-picture-4

The bundle makes three commands available as well as the nice formatting:

  • Batch (Cmd-B): Loads the file into the current CLIPS session like CLIPS’ (batch ..) command
  • Run (Cmd-R): Loads the file (as with Batch) and executes (run) in CLIPS.
  • Clear & Run (Cmd-Shift-R): Clears CLIPS working memory, loads the file, and runs it.

Formatting

The following words have special formatting as special language keywords:

  • defrule
  • not
  • or
  • and
  • assert
  • retract
  • gensym

Rule names (follows defrule) are also formatted specially.

clips-picture-6

Making it Better

You can extend the CLIPS support yourself with TextMate’s Bundle Editor (that’s how I made this initially). Go to TextMate’s Bundles menu, select Bundle Editor and then Show Bundle Editor.

clips-picture-7

Learning the TextMate tricks and syntax can be a bit daunting, but just look at other languages for examples. Here’s the editor showing the CLIPS bundle’s language details:

clips-picture-8

I’ve only used a simple subset of CLIPS, so perhaps you want to add some more keywords to be highlighted. Look for where the string defrule|not|or|and|assert|retract|gensym is above, and you can add run, clear, batch, etc as you like.

The most sophisticated formatting instruction is for the rule names. Here is the instruction I finally figured out:

{ name = 'meta.function.clips';
  match = '(^.*(defrule)[ t]+)([a-zA-Z0-9_-]+)';
  captures = {
    2 = { name = 'keyword.control.clips'; };
    3 = { name = 'entity.name.function.clips'; };
  };
},

You may want to use it as a template if you need to do further complex formatting instructions.

If you make good changes, I don’t mind putting them up here for others to use. Email me.