almost_geek, girl

vimmish - vim translator

dira, May 07

Vimmish is a translator from VIM cryptic commands to human-readable explanations. I built it using a parsing expression grammar and the wonderful Treetop library.

The example:

So you can feed vimmish with a sequence of commands that you got from a cryptic guru, and it will tell you what it means. Here’s an example:

Input:
Output:

Cool! Now all that gibberish makes sense!

small-print disclaimer: while vimmish doesn’t cover (yet) all the possible commands, it is fairly powerful as it understands a lot of them (and combinations).

And what about these grammars..

If you’re new to grammars, you can think of them as regular expressions taken to the next level. That is, with power to express more things.

For example, with a regular expression you could search for all lines in a file that end with “;”:

.*;$

But you cannot build a regular expression that will tell you if a sequence of text is formed from parenthesis that are closed correctly (no one missing, no one extra, no one closed if there was not a corresponding opening one.. you get the idea). But you could do that with a grammar:

grammar OnlyParenthesis
  rule parenthesis_sequence
    ''
    /
    '(' parenthesis_sequence ')'
  end
end

The ‘/’ operator means “or”. So a parenthesis_sequence is either an empty string or a pair of parenthesis that contains another parenthesis_sequence.  This recursion is, of course, one of the key powers of grammars.

So according to this grammar, ” is correct, so is ‘()’, and so is ‘(())’ – it has a pair of parenthesis () that contain a string that matches the rule. But ‘())’ is not correct as the outer parenthesis do not contain a correct sequence.

Having a grammar that defines acceptable texts – that is, a language – you can build a parser that verifies whether a given string belongs to that language or not. This is exactly what the Treetop library offers.

And.. what are grammars _really_ useful for? Defining & parsing complex languages – think DSLs. Or, parsing vim commands :D – see the grammar.

Archive

  • Fixed bugs for fun. Rails BugMash
  • Back from Euruko 2009
  • vimmish - vim translator
  • Deploying a non-trivial app on Heroku
  • GMaps stub released
  • New friends, new enemies
  • Friendly URLs - reverberations