Add comment highlighting to JSONata and fix regex handling

Closes #2701
This commit is contained in:
Nick O'Leary 2020-09-21 11:52:33 +01:00
parent 19726cf428
commit 5a174ba014
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 38 additions and 11 deletions

View File

@ -12,7 +12,7 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m
jsonataFunctions.sort(function(A,B) { jsonataFunctions.sort(function(A,B) {
return B.length-A.length; return B.length-A.length;
}); });
jsonataFunctions = jsonataFunctions.join("|").replace(/\$/g,"\\$"); jsonataFunctions = "("+jsonataFunctions.join("|").replace(/\$/g,"\\$")+")(\\b)";
var JSONataHighlightRules = function() { var JSONataHighlightRules = function() {
@ -27,12 +27,17 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m
"function" "function"
}, "identifier"); }, "identifier");
this.$rules = { this.$rules = {
"start" : [ "no_regex" : [
{ {
token: "string.regexp", token : "comment.doc", // doc comment
regex: "\\/", regex : "\\/\\*",
next: "regex" next : "comments"
}, },
// {
// token: "string.regexp",
// regex: "\\/",
// next: "regex"
// },
{ {
token : "string", token : "string",
regex : "'(?=.)", regex : "'(?=.)",
@ -91,7 +96,7 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m
{ {
token : "string", token : "string",
regex : '"|$', regex : '"|$',
next : "start" next : "no_regex"
}, },
{ {
defaultToken: "string" defaultToken: "string"
@ -101,7 +106,7 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m
{ {
token : "string", token : "string",
regex : "'|$", regex : "'|$",
next : "start" next : "no_regex"
}, },
{ {
defaultToken: "string" defaultToken: "string"
@ -110,15 +115,37 @@ ace.define("ace/mode/jsonata",["require","exports","module","ace/lib/oop","ace/m
"regex" : [ "regex" : [
{ {
token: "string.regexp", token: "string.regexp",
regex: "\\\\/" regex: "/[sxngimy]*",
next: "start"
}, {
defaultToken: "string.regexp"
}
],
"start": [
{
token : "comment.doc", // doc comment
regex : "\\/\\*",
next : "comments"
}, },
{ {
token: "string.regexp", token: "string.regexp",
regex: "/[sxngimy]*", regex: "\\/",
next: "start" 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"
} }
] ]
}; };