2008-02-02

Codeless Language Module for OCaml

Since I couldn't find a ready-made syntax highlighting definition to edit OCaml code in BBEdit, I pieced together one from information and examples I found around. So, for the record, here is an OCaml Codeless Language Module that does the job:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>BBEditDocumentType</key>
  <string>CodelessLanguageModule</string>
  <key>BBLMColorsSyntax</key>
  <true/>
  <key>BBLMIsCaseSensitive</key>
  <true/>
  <key>BBLMKeywordList</key>
  <array>
    <string>and</string>
    <string>as</string>
    <string>assert</string>
    <string>asr</string>
    <string>begin</string>
    <string>class</string>
    <string>constraint</string>
    <string>do</string>
    <string>done</string>
    <string>downto</string>
    <string>else</string>
    <string>end</string>
    <string>exception</string>
    <string>external</string>
    <string>false</string>
    <string>for</string>
    <string>fun</string>
    <string>function</string>
    <string>functor</string>
    <string>if</string>
    <string>in</string>
    <string>include</string>
    <string>inherit</string>
    <string>initializer</string>
    <string>land</string>
    <string>lazy</string>
    <string>let</string>
    <string>lor</string>
    <string>lsl</string>
    <string>lsr</string>
    <string>lxor</string>
    <string>match</string>
    <string>method</string>
    <string>mod</string>
    <string>module</string>
    <string>mutable</string>
    <string>new</string>
    <string>object</string>
    <string>of</string>
    <string>open</string>
    <string>or</string>
    <string>parser</string>
    <string>private</string>
    <string>rec</string>
    <string>sig</string>
    <string>struct</string>
    <string>then</string>
    <string>to</string>
    <string>true</string>
    <string>try</string>
    <string>type</string>
    <string>val</string>
    <string>virtual</string>
    <string>when</string>
    <string>while</string>
    <string>with</string>
  </array>
  <key>BBLMLanguageCode</key>
  <string>Caml</string>
  <key>BBLMLanguageDisplayName</key>
  <string>Objective Caml</string>
  <key>BBLMScansFunctions</key>
  <true/>
  <key>BBLMSuffixMap</key>
  <array>
    <dict>
      <key>BBLMLanguageSuffix</key>
      <string>.ml</string>
    </dict>
    <dict>
      <key>BBLMLanguageSuffix</key>
      <string>.mli</string>
    </dict>
  </array>
  <key>Language Features</key>
  <dict>
    <key>Comment Pattern</key>
    <string><![CDATA[(?x:
(?> \(\* (?s: .*? ) (?> \*\) | \z ) )
    )]]></string>
    <key>Function Pattern</key>
    <string><![CDATA[(?x:
^[ \t]*
(?P<function>
  \b(?: let | and )\b [ \t]+
  (?: \brec\b [ \t]+ )?
  (?P<function_name>
    [A-Za-z]['0-9A-Za-z_]* | \([^)]+\)
  )
  (?:[ \t]+ [^ \t=]+)+ [ \t]*
  =
)
    )]]></string>
    <key>String Pattern</key>
    <string><![CDATA[(?x:
(?>
  (?<!') " (?: [^"\\] |
    (?P<escape>
      \\ (?: ['"ntbr\\] | \d{3} | x[0-9A-Fa-f]{2} )
    )
  )*
  (?> " | \z ) ) |
(?> ' (?: [^'\\] | (?P>escape) ) ' )
    )]]></string>
    <key>Identifier and Keyword Character Class</key>
    <string>\w</string>
    <key>Skip Pattern</key>
    <string><![CDATA[(?x:
(?> \(\* (?s: .*? ) (?> \*\) | \z ) )
|
(?> (?<!') " (?: [^"\\] | \\ (?: ['"ntbr\\] | \d{3} | x[0-9A-Fa-f]{2} ) )* " )
    )]]></string>
  </dict>
</dict>
</plist>

The function pattern could use some work, and the comments pattern doesn't recognize nested comments, but it's a start. I hope you will find it useful.

1 comment:

Phil said...

Matias,

Was trying to figure out how to do the Skip Pattern
section of a codeless language module: I've got a line of HTML l I'd like to skip, so any help would be appreciated on how to configure...

Respond at my ppearson@technn.com address...

Cordially,

Phil Pearson
Publisher, MacSurfer and TechNN
www.macsurfer.com
www.technn.com
ppearson@technn.com