2007-11-06

How to Add Support for a New Language to Exuberant Ctags

Add Support for New Languages to Ctags

Exuberant Ctags has been designed to make it very easy to add your own custom language parser. As an exercise, let us assume that I want to add support for my new language, Swine, the successor to Perl (i.e. Perl before Swine ). This language consists of simple definitions of labels in the form "def my_label". Let us now examine the various ways to do this.

Operational background

As ctags considers each file name, it tries to determine the language of the file by applying the following three tests in order: if the file extension has been mapped to a language, if the file name matches a shell pattern mapped to a language, and finally if the file is executable and its first line specifies an interpreter using the Unix-style "#!" specification (if supported on the platform). If a language was identified, the file is opened and then the appropriate language parser is called to operate on the currently open file. The parser parses through the file and whenever it finds some interesting token, calls a function to define a tag entry.

No comments: