Re: regexp in javascript.lang (3rd try!)

[email protected] Tue, 16 Dec 2008 19:32:59 -0600
Newsgroups gmane.comp.gnu.source-highlight.general
Message-ID <[email protected]>
Lorenzo Bettini wrote:
> [email protected] wrote:
>> Last time I suggested an ugly regexp definition for
>> javascript.lang to avoid matching /* */ comments:
>>
>> http://lists.gnu.org/archive/html/help-source-highlight/2008-09/msg00000.html 
>>
>>
>> On second thought (or third thought) I don't like this because it
>> matches cases where there are two division operators in a single
>> expression, such as:
>>
>> document.write('<table><tr><td>25% = '+(25/100)+'</td></tr></table>');
>>
> 
> mh... I'm not sure I understad: why does this happen?  The other / are 
> in strings delimited by '', aren't they?
> 

document.write('<table><tr><td>25% = '+(25/100)+'</td></tr></table>');
                                           ^
When at this point in the line, the "regexp" rule will match instead of 
the "string" rule.  I.e., the "regexp" rule will match with an empty 
prefix, while the "string" rule would have a nonempty prefix before the 
string starts:

document.write('<table><tr><td>25% = '+(25/100)+'</td></tr></table>');
                                           _________
                                            regexp

document.write('<table><tr><td>25% = '+(25/100)+'</td></tr></table>');
                                           ------____________________
                                           prefix      string