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 - Javascript regexp has wrong syntax error underlining
Summary: Javascript regexp has wrong syntax error underlining
Status: RESOLVED FIXED
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.0
Hardware: PC All
: P3 normal (vote)
Assignee: Petr Hejl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-22 14:15 UTC by emi
Modified: 2012-09-13 13:28 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Screenshot of the bad highlighting (8.18 KB, image/png)
2011-03-22 14:43 UTC, emi
Details

Note You need to log in before you can comment on or make changes to this bug.
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.