This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 196965

Summary: Javascript regexp has wrong syntax error underlining
Product: javascript Reporter: emi <emi>
Component: EditorAssignee: Petr Hejl <phejl>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 7.0   
Hardware: PC   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Screenshot of the bad highlighting

Description emi 2011-03-22 14:15:49 UTC
The following javascript code is highlighted wrong (red underline):

var a = function(theFunction){
    return /function (.*)\(/.exec("" + theFunction)[1];
}

although internally the syntax tree seems to be ok.

The problem seems to be at lexer level. More precisely, the divIsRegexp flag from org.mozilla.nb.javascript.TokenStream is wrong so the regexp isn't detected properly.

Thus, SyntaxHighlighting gets a Token.ERROR in the TokenSequence and ends up highlighting those ranges.

I wanted to fix this bug myself but then I found these lines in TokenStream:

                // THIS IS NOT COMPLETE; there are other possible constructions with operators but covers 90+% of cases
                divIsRegexp = (token == Token.LP || token == Token.COMMA || token == Token.NOT || token == Token.ASSIGN || token == Token.SEMI ||
                        token == Token.COLON);

which made me believe the whole regexp support at lexer level is more or less volatile.

I'm posting this bug as a testcase for you and as a reminder for myself. Given the heuristics used to detect regular expressions, I don't see a clear solution to fix this.
Comment 1 emi 2011-03-22 14:43:17 UTC
Created attachment 107182 [details]
Screenshot of the bad highlighting
Comment 2 Petr Hejl 2012-09-13 13:28:43 UTC
Fixed for 7.3.