[PATCH] Better regular expressions in the PHP Parser

Sebastian Gutweiler sebastian at gutweiler.net
Fri Jul 25 20:20:06 UTC 2003


Hi,

when using the PHP-Part I had the problem, that the Parser, when parsing
a class called "mp3", only added "mp" to the class store. When looking
at the source code, it tourned out, that the Parser also ignored files when
they contained a special char, like the German umlauts, but they are
allowed in PHP. 
This patch fixes this and makes the checking stricter. If, for
example, a variable begins with a figure, it is ignored and not added to
the class store, because this is not allowd in PHP. 

Sebastian
-------------- next part --------------
diff -u --recursive --new-file kdevelop_orig/parts/phpsupport/phpparser.cpp kdevelop_change/parts/phpsupport/phpparser.cpp
--- kdevelop_orig/parts/phpsupport/phpparser.cpp	Tue Apr 22 17:08:04 2003
+++ kdevelop_change/parts/phpsupport/phpparser.cpp	Fri Jul 25 20:08:39 2003
@@ -31,10 +31,10 @@
 }
 void PHPParser::parseLines(QStringList* lines,const QString& fileName){
   kdDebug(9018) << "enter parsedLines" << endl;
-  KRegExp classre("^[ \t]*class[ \t]+([A-Za-z_]+)[ \t]*(extends[ \t]*([A-Za-z_]+))?.*$");
-  KRegExp methodre("^[ \t]*function[ \t]*([0-9A-Za-z_]*)[ \t]*\\(([0-9A-Za-z_\\$\\, \t=&\\'\\\"]*)\\).*$");
-  KRegExp varre("^[ \t]*var[ \t]*([0-9A-Za-z_\\$]+)[ \t;=].*$");
-  KRegExp createMemberRe("\\$this->([0-9A-Za-z_]+)[ \t]*=[ \t]*new[ \t]+([0-9A-Za-z_]+)");
+  KRegExp classre("^[ \t]*class[ \t]+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[ \t]*(extends[ \t]*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))?.*$");
+  KRegExp methodre("^[ \t]*function[ \t]*([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[ \t]*\\(([a-zA-Z_\x7f-\xff]*[0-9A-Za-z_\x7f-\xff\\$\\, \t=&\\'\\\"]*)\\).*$");
+  KRegExp varre("^[ \t]*var[ \t]*\\$([a-zA-Z_\x7f-\xff][0-9A-Za-z_\x7f-\xff]*)[ \t;=].*$");
+  KRegExp createMemberRe("\\$this->([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[ \t]*=[\t]*new[ \t]+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)");
 
   ParsedClass *lastClass = 0;
   QString rawline;


More information about the KDevelop-devel mailing list