Bug #17611 [Com]: Regular expression tokens not recognised

From: Date: Fri, 03 Sep 2010 09:22:36 +0000
Subject: Bug #17611 [Com]: Regular expression tokens not recognised
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-4755@lists.php.net to get a copy of this message
Edit report at http://pear.php.net/bugs/bug.php?id=17611&edit=1 ID: 17611 Comment by: gurbani Reported By: prem at tuenti dot com Summary: Regular expression tokens not recognised Status: No Feedback Type: Bug Package: PHP_CodeSniffer Operating System: Ubuntu Package Version: 1.3.0a1 PHP Version: 5.3.2 Assigned To: squiz New Comment: Hi, Actually the usage of typeof before a regular expression can be a valid expression. Here's an example where we are creating a helper function to see if something is a regular expression. isRegexp: (function() { var regexpType = typeof /a/; return function(obj) { return ( (obj !== null) && (typeof obj === regexpType) && (obj.constructor === RegExp) ); }; } We were having a look at your tokenizer, and could it be just that we need to specify that before a regular expression we can accept a typeof (it might be an oversimplified view of the problem, you are the expert with your tokenizer after all :) Thanks Prem - Framework Lead @ Tuenti Previous Comments: ------------------------------------------------------------------------ [2010-08-11 06:00:29] squiz <div id="changeset"> <span class="removed">-Status: Feedback</span> <span class="added">+Status: No Feedback</span> </div>Please re-open if you are able to post some code where this is required as it will give me something solid to work with. ------------------------------------------------------------------------ [2010-07-28 05:38:21] squiz <div id="changeset"> <span class="removed">-Status: Open</span> <span class="added">+Status: Feedback</span> <span class="removed">-Assigned To:</span> <span class="added">+Assigned To: squiz</span> </div>Is there any reason you'd actually write "typeof /a/" in code? Or is this perhaps simplified from a larger piece of code where regexType will be variable? The reason I ask is that I'm trying to figure out if it is worth writing and testing this because it's quite hard to maintain that regular expression parsing. There is a lot you can do, but I'm only really interested in supporting the sort of things you will do due to the inability to figure out if a string is a regex statically. ------------------------------------------------------------------------ [2010-07-20 16:12:42] mcordoba I think the problem is the use of typeof before the regular expression. I think you have to include its token on the array beforeTokens that is in getRegexToken method. ------------------------------------------------------------------------ [2010-07-20 15:51:43] mcordoba Description: ------------ A regular expression is not recognised as T_REGULAR_EXPRESSION token. Test script: --------------- var regexType = typeof /a/; /a/ is recognised as T_DIVIDE, T_STRING and T_DIVIDE instead of T_REGULAR_EXPRESSION Expected result: ---------------- token T_REGULAR_EXPRESSION Actual result: -------------- / T_DIVIDE a T_STRING / T_DIVIDE ------------------------------------------------------------------------ -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=17611&edit=1

« previous php.pear.bugs (#4755) next »