fix highlighting of regular expressions at the beginning of document
This commit is contained in:
parent
9ddf039cf6
commit
94a6dac5a7
1 changed files with 21 additions and 19 deletions
|
|
@ -83,7 +83,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
// regexps are ordered -> the first match is used
|
// regexps are ordered -> the first match is used
|
||||||
|
|
||||||
this.$rules = {
|
this.$rules = {
|
||||||
"start" : [
|
"no_regex" : [
|
||||||
{
|
{
|
||||||
token : "comment",
|
token : "comment",
|
||||||
regex : /\/\/.*$/
|
regex : /\/\/.*$/
|
||||||
|
|
@ -165,7 +165,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token : "keyword",
|
token : "keyword",
|
||||||
regex : "(?:" + kwBeforeRe + ")\\b",
|
regex : "(?:" + kwBeforeRe + ")\\b",
|
||||||
next : "regex_allowed"
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
token : ["punctuation.operator", "support.function"],
|
token : ["punctuation.operator", "support.function"],
|
||||||
regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:opzzzz|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
|
regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:opzzzz|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
|
||||||
|
|
@ -184,22 +184,22 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token : "keyword.operator",
|
token : "keyword.operator",
|
||||||
regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
|
regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
|
||||||
next : "regex_allowed"
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
token : "punctuation.operator",
|
token : "punctuation.operator",
|
||||||
regex : /\?|\:|\,|\;|\./,
|
regex : /\?|\:|\,|\;|\./,
|
||||||
next : "regex_allowed"
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
token : "paren.lparen",
|
token : "paren.lparen",
|
||||||
regex : /[\[({]/,
|
regex : /[\[({]/,
|
||||||
next : "regex_allowed"
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
token : "paren.rparen",
|
token : "paren.rparen",
|
||||||
regex : /[\])}]/
|
regex : /[\])}]/
|
||||||
}, {
|
}, {
|
||||||
token : "keyword.operator",
|
token : "keyword.operator",
|
||||||
regex : /\/=?/,
|
regex : /\/=?/,
|
||||||
next : "regex_allowed"
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
token: "comment",
|
token: "comment",
|
||||||
regex: /^#!.*$/
|
regex: /^#!.*$/
|
||||||
|
|
@ -207,7 +207,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
],
|
],
|
||||||
// regular expressions are only allowed after certain tokens. This
|
// regular expressions are only allowed after certain tokens. This
|
||||||
// makes sure we don't mix up regexps with the divison operator
|
// makes sure we don't mix up regexps with the divison operator
|
||||||
"regex_allowed": [
|
"start": [
|
||||||
DocCommentHighlightRules.getStartRule("doc-start"),
|
DocCommentHighlightRules.getStartRule("doc-start"),
|
||||||
{
|
{
|
||||||
token : "comment", // multi line comment
|
token : "comment", // multi line comment
|
||||||
|
|
@ -215,20 +215,22 @@ var JavaScriptHighlightRules = function() {
|
||||||
next : "comment_regex_allowed"
|
next : "comment_regex_allowed"
|
||||||
}, {
|
}, {
|
||||||
token : "comment",
|
token : "comment",
|
||||||
regex : "\\/\\/.*$"
|
regex : "\\/\\/.*$",
|
||||||
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
token: "string.regexp",
|
token: "string.regexp",
|
||||||
regex: "\\/",
|
regex: "\\/",
|
||||||
next: "regex",
|
next: "regex",
|
||||||
}, {
|
}, {
|
||||||
token : "text",
|
token : "text",
|
||||||
regex : "\\s+"
|
regex : "\\s+|^$",
|
||||||
|
next : "start"
|
||||||
}, {
|
}, {
|
||||||
// immediately return to the start mode without matching
|
// immediately return to the start mode without matching
|
||||||
// anything
|
// anything
|
||||||
token: "empty",
|
token: "empty",
|
||||||
regex: "",
|
regex: "",
|
||||||
next: "start"
|
next: "no_regex"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"regex": [
|
"regex": [
|
||||||
|
|
@ -240,7 +242,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
// flag
|
// flag
|
||||||
token: "string.regexp",
|
token: "string.regexp",
|
||||||
regex: "/\\w*",
|
regex: "/\\w*",
|
||||||
next: "start",
|
next: "no_regex",
|
||||||
}, {
|
}, {
|
||||||
// invalid operators
|
// invalid operators
|
||||||
token : "invalid",
|
token : "invalid",
|
||||||
|
|
@ -259,7 +261,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token: "empty",
|
token: "empty",
|
||||||
regex: "$",
|
regex: "$",
|
||||||
next: "start"
|
next: "no_regex"
|
||||||
}, {
|
}, {
|
||||||
defaultToken: "string.regexp"
|
defaultToken: "string.regexp"
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +280,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token: "empty",
|
token: "empty",
|
||||||
regex: "$",
|
regex: "$",
|
||||||
next: "start"
|
next: "no_regex"
|
||||||
}, {
|
}, {
|
||||||
defaultToken: "string.regexp.charachterclass"
|
defaultToken: "string.regexp.charachterclass"
|
||||||
}
|
}
|
||||||
|
|
@ -296,15 +298,15 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token: "empty",
|
token: "empty",
|
||||||
regex: "",
|
regex: "",
|
||||||
next: "start"
|
next: "no_regex"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"comment_regex_allowed" : [
|
"comment_regex_allowed" : [
|
||||||
{token : "comment", regex : "\\*\\/", next : "regex_allowed"},
|
{token : "comment", regex : "\\*\\/", next : "start"},
|
||||||
{defaultToken : "comment"}
|
{defaultToken : "comment"}
|
||||||
],
|
],
|
||||||
"comment" : [
|
"comment" : [
|
||||||
{token : "comment", regex : "\\*\\/", next : "start"},
|
{token : "comment", regex : "\\*\\/", next : "no_regex"},
|
||||||
{defaultToken : "comment"}
|
{defaultToken : "comment"}
|
||||||
],
|
],
|
||||||
"qqstring" : [
|
"qqstring" : [
|
||||||
|
|
@ -318,7 +320,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : '"|$',
|
regex : '"|$',
|
||||||
next : "start",
|
next : "no_regex",
|
||||||
}, {
|
}, {
|
||||||
defaultToken: "string"
|
defaultToken: "string"
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +336,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
}, {
|
}, {
|
||||||
token : "string",
|
token : "string",
|
||||||
regex : "'|$",
|
regex : "'|$",
|
||||||
next : "start",
|
next : "no_regex",
|
||||||
}, {
|
}, {
|
||||||
defaultToken: "string"
|
defaultToken: "string"
|
||||||
}
|
}
|
||||||
|
|
@ -342,7 +344,7 @@ var JavaScriptHighlightRules = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.embedRules(DocCommentHighlightRules, "doc-",
|
this.embedRules(DocCommentHighlightRules, "doc-",
|
||||||
[ DocCommentHighlightRules.getEndRule("start") ]);
|
[ DocCommentHighlightRules.getEndRule("no_regex") ]);
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
|
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue