coteditor / CotEditor

Lightweight Plain-Text Editor for macOS
https://coteditor.com
Other
6.45k stars 431 forks source link

Syntax Highlighting: JavaScript (Regular expression literal) #1185

Open Lessica opened 3 years ago

Lessica commented 3 years ago

Regular expression literal are not properly rendered. If quotes " are included in a regex literal, all syntax highlights after that will fail.

Creating a regular expression

You construct a regular expression in one of two ways:

let re = /ab+c/;

Regular expression literals provide compilation of the regular expression when the script is loaded. If the regular expression remains constant, using this can improve performance.

let re = new RegExp('ab+c');

Using the constructor function provides runtime compilation of the regular expression. Use the constructor function when you know the regular expression pattern will be changing, or you don't know the pattern and are getting it from another source, such as user input.

Referenced from: Regular expressions - JavaScript | MDN

Lessica commented 3 years ago

Screenshots

截屏2021-06-05 上午12 24 46
1024jp commented 3 years ago

Thank you for the feedback. I update the JavaScript syntax style definition to solve this issue. The change will be shipped with the next version.

JJHackimoto commented 3 years ago

I believe this fix caused new issues when using forward slash as dividing operator or when using two forward slashes to comment. See included screenshots.

Skärmavbild 2021-06-11 kl  11 41 51 Skärmavbild 2021-06-11 kl  11 39 28
1024jp commented 3 years ago

Thank you for the report and sorry for the enbug. I close this issue just because it is the same as issue #1187. I'll fix it anyway in the next version.

1024jp commented 3 years ago

Regrettably, I need to say I reopen this issue because the JavaScript syntax highlight definition will be restored in the next version to solve the further issue, which was reported by @JJHackimoto and in #1187.

I understand the current issue on the regex literal in CotEditor's JavaScript definition. However, by studying the source code, I realize this is the limit of the current syntax highlight mechanism in CotEditor, which is simple but originally designed aiming that users can modify it easily in GUI.

To solve this issue, I need to redesign CotEditor's syntax highlight system and definition format drastically. In other words, it takes time.

Sorry for that. I actually know for years I need to update this highlighting system and put in my to-do list, but not decided yet when I'll set about this task.