Actions

Creating tags from Gambit library C files

From Gambit wiki

Revision as of 02:02, 10 April 2008 by Dpeschel (talk | contribs) (Put a section at the beginning so the contents go there.)

Overview

Work in progress. See also User:dpeschel.

The hand-written C files in the Gambit lib/ directory contain many small functions, so it would be useful to have a list. The GNU etags program can create lists in a format that Emacs can use and in a different format that vi and Vim can use. These lists support interactive browsing within Emacs, vi, and Vim. With your cursor on a symbol, you jump to its definition. Unfortunately the lsits are not very useful to read by themselves (to get a quick overview of functions and the order they are defined in, or to get sublists of symbols sorted by type).

Another program, Exuberant Ctags, has some features etags doesn't, but I haven't gotten Exuberant working yet.

I don't think the original UNIX ctags is flexible enough to parse the Gambit library. I haven't tried yet.

There is no point in parsing C files that were compiled from Scheme, if I can parse the original Scheme.

The extensive use of preprocessor macros in the library code means etags's default parser can do very little with the files. Luckily you can extend the lines recognized by etags through its --regex option. The regular expressions used must:

  • Match the entire text of a line or group of lines (this is not documented in the etags manual page).
  • Contain a subexpression that matches the name of the function being defined.
  • Handle enough C syntax to match all and only the correct uses of the macros.
    • etags doesn't tag forward declarations, so these expressions are designed to fail on forward declarations.
    • It is not possible to associate expressions with different parts of a C function definition, like return type and linkage type, or the signature after a name. The expression must match all those parts in order. However, etags does not need to know where those parts are within the matched text, except the function name as described above.

use /m modifier, recent version of etags

Parsing ___PVOID

Parsing ___P

Finding the maximum depth of parentheses used

Generating a regexp

Using the regexp