Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.4.2

Bug #17611 Regular expression tokens not recognised
Submitted: 2010-07-20 19:51 UTC
From: mcordoba Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.0a1)
PHP Version: 5.3.2 OS: Ubuntu
Roadmaps: (Not assigned)    
Subscription  


 [2010-07-20 19:51 UTC] mcordoba (Manuel Cordoba)
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

Comments

 [2010-07-20 20:12 UTC] mcordoba (Manuel Cordoba)
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-28 09:38 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
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-08-11 10:00 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: No Feedback
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-09-03 13:19 UTC] gurbani (Prem Gurbani)
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
 [2010-09-03 20:46 UTC] mcordoba (Manuel Cordoba)
In this example code it neither recognize the regular expression token: var test = {
 [2010-09-03 20:47 UTC] mcordoba (Manuel Cordoba)
In this example code it neither recognize the regular expression token: var test = { regularExpression: /[a-z]+/ };
 [2010-09-06 03:02 UTC] sleekism (Sleek Cab)
Hey gurbani, I would like to find out why you wouldn't just use: typeof obj === 'object' in your if statement. Isn't it the same thing, or am I missing something? Thanks, Sleek
 [2010-09-06 10:44 UTC] squiz (Greg Sherwood)
-Status: No Feedback +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.
 [2010-09-06 20:26 UTC] mcordoba (Manuel Cordoba)
Thanks, It is working now :-)