From 5a174ba014e59bb20d9e843d754dcbd787c37eea Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 21 Sep 2020 11:52:33 +0100 Subject: [PATCH] Add comment highlighting to JSONata and fix regex handling Closes #2701 --- .../src/vendor/jsonata/mode-jsonata.js | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/vendor/jsonata/mode-jsonata.js b/packages/node_modules/@node-red/editor-client/src/vendor/jsonata/mode-jsonata.js index 48358517e..a5cd9b860 100644 --- a/packages/node_modules/@node-red/editor-client/src/vendor/jsonata/mode-jsonata.js +++ b/packages/node_modules/@node-red/editor-client/src/vendor/jsonata/mode-jsonata.js @@ -12,7 +12,7 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m jsonataFunctions.sort(function(A,B) { return B.length-A.length; }); - jsonataFunctions = jsonataFunctions.join("|").replace(/\$/g,"\\$"); + jsonataFunctions = "("+jsonataFunctions.join("|").replace(/\$/g,"\\$")+")(\\b)"; var JSONataHighlightRules = function() { @@ -27,12 +27,17 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m "function" }, "identifier"); this.$rules = { - "start" : [ + "no_regex" : [ { - token: "string.regexp", - regex: "\\/", - next: "regex" + token : "comment.doc", // doc comment + regex : "\\/\\*", + next : "comments" }, + // { + // token: "string.regexp", + // regex: "\\/", + // next: "regex" + // }, { token : "string", regex : "'(?=.)", @@ -91,7 +96,7 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m { token : "string", regex : '"|$', - next : "start" + next : "no_regex" }, { defaultToken: "string" @@ -101,7 +106,7 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m { token : "string", regex : "'|$", - next : "start" + next : "no_regex" }, { defaultToken: "string" @@ -110,15 +115,37 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m "regex" : [ { token: "string.regexp", - regex: "\\\\/" + regex: "/[sxngimy]*", + next: "start" + }, { + defaultToken: "string.regexp" + } + ], + "start": [ + { + token : "comment.doc", // doc comment + regex : "\\/\\*", + next : "comments" }, { token: "string.regexp", - regex: "/[sxngimy]*", - next: "start" + regex: "\\/", + next: "regex", + },{ + // immediately return to the start mode without matching + // anything + token: "empty", + regex: "", + next: "no_regex" + }], + "comments": [ + { + token : "comment.doc", // doc comment + regex : "\\*\\/", + next : "start" }, { - defaultToken: "string.regexp" + defaultToken: "comment.doc" } ] };