Package: exuberant-ctags
Version: 1:5.7-4
Severity: normal
Tags: patch

There is a known bug in the PHP parser. It also matches keywords such as
"function" and "class" in multiline comments such as docblocks. Since
those words are used quite often in comments, it makes exuberant-ctags
see a lot of things that aren't really there. It makes using ctags in
e.g. vim for PHP code pretty useless when there are plenty of comments
in the code.

The attached php-multiline-comment.patch tries to largely solve this
problem by looking at what is in front of the keyword. There should be
only whitespace or keywords such as "public", "static" or "abstract" in
front of a class or function statement.

The patch does not fix this 100%. It is technically possible to declare
classes and functions after another statement on the same line, but
nobody ever does that because it makes for very unreadable code. On the
other hand, a lot of people do comment their code so this patch should
give a large improvement in quality.

Since this patch also looks at PHP5 keywords such as "static" and
"abstract", it also adds the .php4 and .php5 extensions to the list of
PHP file extensions.

I am also submitting this patch upstream, but it would be very nice if
it could still be put into Lenny before it is released.

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages exuberant-ctags depends on:
ii  libc6                         2.7-15     GNU C Library: Shared libraries

exuberant-ctags recommends no packages.

Versions of packages exuberant-ctags suggests:
ii  vim-gnome [vim]              2:7.2.010-1 Vi IMproved - enhanced vi editor -

-- no debconf information
--- exuberant-ctags-5.7/php.c	2007-06-24 21:57:09.000000000 +0200
+++ exuberant-ctags-5.7-multiline/php.c	2008-11-13 12:34:10.000000000 +0100
@@ -11,6 +11,7 @@
 *   variables.
 *
 *   Parsing PHP defines by Pavel Hlousek <[EMAIL PROTECTED]>, Apr 2003.
+*   Multiline comment fixes by Sander Marechal <[EMAIL PROTECTED]>, Nov 2008.
 */
 
 /*
@@ -64,14 +65,14 @@
 
 static void installPHPRegex (const langType language)
 {
-	addTagRegex(language, "(^|[ \t])class[ \t]+([" ALPHA "_][" ALNUM "_]*)",
-		"\\2", "c,class,classes", NULL);
+	addTagRegex(language, "(^[ \t]*(abstract)?[ \t]+)class[ \t]+([" ALPHA "_][" ALNUM "_]*)",
+		"\\3", "c,class,classes", NULL);
 	addTagRegex(language, "(^|[ \t])interface[ \t]+([" ALPHA "_][" ALNUM "_]*)",
 		"\\2", "i,interface,interfaces", NULL);
 	addTagRegex(language, "(^|[ \t])define[ \t]*\\([ \t]*['\"]?([" ALPHA "_][" ALNUM "_]*)",
 		"\\2", "d,define,constant definitions", NULL);
-	addTagRegex(language, "(^|[ \t])function[ \t]+&?[ \t]*([" ALPHA "_][" ALNUM "_]*)",
-		"\\2", "f,function,functions", NULL);
+	addTagRegex(language, "(^[ \t]*(public|protected|private)?([ \t]*static)?[ \t]+)function[ \t]+&?[ \t]*([" ALPHA "_][" ALNUM "_]*)",
+		"\\4", "f,function,functions", NULL);
 	addTagRegex(language, "(^|[ \t])\\$([" ALPHA "_][" ALNUM "_]*)[ \t]*=",
 		"\\2", "v,variable,variables", NULL);
 
@@ -87,7 +88,7 @@
 /* Create parser definition structure */
 extern parserDefinition* PhpParser (void)
 {
-	static const char *const extensions [] = { "php", "php3", "phtml", NULL };
+	static const char *const extensions [] = { "php", "php3", "php4", "php5", "phtml", NULL };
 	parserDefinition* def = parserNew ("PHP");
 	def->extensions = extensions;
 	def->initialize = installPHPRegex;

Reply via email to