CotEditor icon indicating copy to clipboard operation
CotEditor copied to clipboard

Syntax Highlighting: JavaScript (Regular expression literal)

Open Lessica opened this issue 4 years ago • 7 comments

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:

  • Using a regular expression literal, which consists of a pattern enclosed between slashes, as follows:
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.

  • Or calling the constructor function of the RegExp object, as follows:
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 avatar Jun 04 '21 15:06 Lessica

Screenshots

截屏2021-06-05 上午12 24 46

Lessica avatar Jun 04 '21 16:06 Lessica

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.

1024jp avatar Jun 05 '21 03:06 1024jp

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

JJHackimoto avatar Jun 11 '21 09:06 JJHackimoto

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 avatar Jun 16 '21 09:06 1024jp

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.

1024jp avatar Jun 20 '21 14:06 1024jp