vim-mscgen available on GitHub

[tl;dr: Vim syntax highlighting for the mscgen, msgenny, Xù languages is now available on GitHub.]

At work I’ve been working on a large design document that involves some wire protocol work. It’s often helpful when explaining wire protocols to use packet/protocol sequence diagrams (sometimes called ladder diagrams, but that term is ambiguous if you’re a different type of electrical engineer).

Here’s an example:

While drawing one of these is pretty simple on a whiteboard or even a piece of paper, it’s more painful to do in PowerPoint, Inkscape, etc., especially if you need to keep modifying the diagram as the protocol or example evolves. So you can imagine how happy I was to discover the mscgen language and, better yet, the mscgen.js suite of tools.

You can think of the mscgen language as analogous to the DOT language and mscgen.js analogous to the Graphviz package for drawing directed and undirected graphs.

Here’s an example of the mscgen code that generates the above image:

# SIP protocol (source: wikipedia)
msc {
  UAS,  UAC;

  UAS -> UAC [label="INVITE"];
  UAS <- UAC [label="100 Trying"];
  UAS <- UAC [label="180 Ringing"];

  --- [label="the client plays ringing"];
  UAS <- UAC [label="200 Ok"];
  UAS -> UAC [label="ACK"];

  --- [label="the client hangs up"];
  UAS <- UAC [label="BYE"];
  UAS <- UAC [label="200 Ok"];

And here’s that same file in the msgenny language, a relaxed and simplified version of mscgen (sort of like Hjson is to JSON):

# SIP protocol (source: wikipedia)

UAS <- UAC : 100 Trying;
UAS <- UAC : 180 Ringing;
--- : the client plays ringing;
UAS <- UAC : 200 Ok;
--- : the client hangs up;
UAS <- UAC : 200 Ok;

You can even play around with these languages in your browser!

Editing those files in Vim is not a big deal, but I figured it could be made a little more pleasant with some syntax highlighting and other goodies. Hence, vim-mscgen was born in my spare time.

vim-mscgen includes:

  • syntax highlighting
  • file type detection (based on file extension being .mscgen/.msgenny/.mscin/.xu)
  • a rough errorformat setting for the mscgenjs-cli utility