jashkenas / jashkenas/coffee-script-tmbundle
Syntax highlighting with double-backslashes in regexes
- Dominant language
- JavaScript
- Stars
- 826
- Forks
- 232
- PR merge metrics
- No merged PRs in 30d
Description
The line
```
str.replace(/\\/g, '')
```
is perfectly valid CoffeeScript, removing all backslashes from a string. However, the regex `/\\/` doesn't get highlighted. Worse, if there's a slash later on the line, _then_ regex highlighting goes all the way up to it, e.g.
```
str.replace(/\\/g, '\\\\').replace(/\\"/g, '"')
```
highlights
```
/\\/g, '\\\\').replace(/
```
In short, the syntax highlighter isn't currently distinguishing between a single backslash (which escapes the closing `/` of a regex) and a double backslash (which doesn't). More precisely, it needs to ignore any _even_ number of backslashes preceding the closing `\`, since the current behavior is correct for a regex like
```
/\\\/foo/
```
Contributor guide
No contributing guide indexed for this repository
Research direction
No file or test is named. Locate the CoffeeScript TextMate syntax grammar and inspect its regex-matching rules; use the examples in the issue to verify that even backslashes do not close a regex while an odd number does. Done means both highlighted examples stop at the correct closing slash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- coffeescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100