Open jonhue opened 5 years ago
I have a grammar that uses this regex to match comments (it's in the extras array):
extras
comment: $ => /((\/\/[^\r\n]*)|(\/\*(.|\s)*?\*\/))/
This fails on the following test:
===================================== Comments ===================================== 1 // C$mment 1// C$mment 1/* C$mment C$mment C$mment*/ 1 --- (file (integer) (comment) (integer) (comment) (integer) (comment) (integer))
However, when I make the regex greedy (/((\/\/[^\r\n]*)|(\/\*(.|\s)*\*\/))/), the test is successful. The regex has to be non greedy for cases like this:
/((\/\/[^\r\n]*)|(\/\*(.|\s)*\*\/))/
1 // C$mment 1// C$mment 1/* C$mment C$mment C$mment*/ + 1 /* C$mment */ 1
Yeah, non-greedy regexes are not supported.
It looks like you're trying to match C-style comments. If so, have you tried this regex?
I have a grammar that uses this regex to match comments (it's in the
extras
array):This fails on the following test:
However, when I make the regex greedy (
/((\/\/[^\r\n]*)|(\/\*(.|\s)*\*\/))/
), the test is successful. The regex has to be non greedy for cases like this: