LDraw language grammar for TextMate

Data files for LDraw software, such as Bricksmith, are really just text files with a specific syntax, and it can be useful to treat these files as text by opening them in a text editor and manipulating the source directly. This is particularly true if you are using LPub to build instructions for the model, as editing the text directly is the only way to add certain commands to the file.

My text editor of choice, TextMate, supports large numbers of language grammars to provide syntax coloring. It also allows you to add your own. I threw together this one to get a bit of coloring into .ldr files:

{
   scopeName = 'source.ldr';
   firstLineMatch = '^0 FILE .+\.ldr$';
   fileTypes = ( 'ldr' );
   patterns = (
      {
	name = 'comment.line.ldraw';
        match = '^0 [^!].*$\n?';
      },
      {
	name = 'constant.other.ldraw';
        match = '^0 !.*$\n?';
      },
   );
}

To install this, pick Bundles→Bundle Editor→Edit Languages… from the menu bar. Click the + at the bottom of the window that comes up to create a new item. Then cut and paste the grammar. This should make your LDraw files go from what is shown on the left, to what is on the right:
Application of TextMate grammar

Leave a Reply

Your email address will not be published. Required fields are marked *