Tuesday, September 15, 2009

Strange bedfellows: ctags and actionscript

I've been hacking a lot in ActionScript and Flex recently. I'm a vi user and went looking for how I could use ctags with ActionScript source.

Lo and behold, Google says there are about 858,800 results for a "actionscript ctags" search. (Bing says 45,800, which seems more reasonable but still really high.)

I associate ctags and vi with old school *nix hackers, and ActionScript with graphic designers that morph into Flash code monkeys. My picture of actionscript hackers ain't right, which gives me a good feeling about using ActionScript.

Anyway, it's pretty easy. Mixing some Makefile goo with some regular expressions, I get:


CTAGSLANGS=--langdef=as \
--langmap=as:.as \
--regex-as='/^(a-z0-9_]+)\([^\)]*\)[ \t]*/\1/f,function/i' \
--regex-as='/class[ \t]+([^ \t]+)[ \t]*$$/\1/c,class/i'

ctags::
        find . -name "*.as" | ctags -e - $(CTAGLANGS)
Notes:
  • the regular expressions are Posix extended (roughly egrep);
  • the "kind" (e.g., f,function) options can be seen by running
    ctags --list-kinds | less
    at the command line;
  • the i flag says case-insensitive;
  • the $$ (to match the end of a line) is required because we are inside a Makefile
  • these regex are specific to how I format my code.
More on that last point: I like using the vi's bracket-bracket key sequence to move from function to function within a source file, and to make this work, my ActionScript functions look like this:
public function
getfoo()
: void
{
}
The function regex may catch more than I want, but the alternative is to write some C code and recompile ctags (so I can use the previous line as context), so I'll run with this for a while.

References

  1. How to Add Support for a New Language to Exuberant Ctags
  2. ctags(1)
  3. Makefile goo, more complex regex's

No comments:

Post a Comment