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
|
||||
|
||||
this.$rules = {
|
||||
"start" : [
|
||||
"no_regex" : [
|
||||
{
|
||||
token : "comment",
|
||||
regex : /\/\/.*$/
|
||||
|
|
@ -165,7 +165,7 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token : "keyword",
|
||||
regex : "(?:" + kwBeforeRe + ")\\b",
|
||||
next : "regex_allowed"
|
||||
next : "start"
|
||||
}, {
|
||||
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(?=\()/
|
||||
|
|
@ -184,22 +184,22 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token : "keyword.operator",
|
||||
regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
|
||||
next : "regex_allowed"
|
||||
next : "start"
|
||||
}, {
|
||||
token : "punctuation.operator",
|
||||
regex : /\?|\:|\,|\;|\./,
|
||||
next : "regex_allowed"
|
||||
next : "start"
|
||||
}, {
|
||||
token : "paren.lparen",
|
||||
regex : /[\[({]/,
|
||||
next : "regex_allowed"
|
||||
next : "start"
|
||||
}, {
|
||||
token : "paren.rparen",
|
||||
regex : /[\])}]/
|
||||
}, {
|
||||
token : "keyword.operator",
|
||||
regex : /\/=?/,
|
||||
next : "regex_allowed"
|
||||
next : "start"
|
||||
}, {
|
||||
token: "comment",
|
||||
regex: /^#!.*$/
|
||||
|
|
@ -207,7 +207,7 @@ var JavaScriptHighlightRules = function() {
|
|||
],
|
||||
// regular expressions are only allowed after certain tokens. This
|
||||
// makes sure we don't mix up regexps with the divison operator
|
||||
"regex_allowed": [
|
||||
"start": [
|
||||
DocCommentHighlightRules.getStartRule("doc-start"),
|
||||
{
|
||||
token : "comment", // multi line comment
|
||||
|
|
@ -215,20 +215,22 @@ var JavaScriptHighlightRules = function() {
|
|||
next : "comment_regex_allowed"
|
||||
}, {
|
||||
token : "comment",
|
||||
regex : "\\/\\/.*$"
|
||||
regex : "\\/\\/.*$",
|
||||
next : "start"
|
||||
}, {
|
||||
token: "string.regexp",
|
||||
regex: "\\/",
|
||||
next: "regex",
|
||||
}, {
|
||||
token : "text",
|
||||
regex : "\\s+"
|
||||
regex : "\\s+|^$",
|
||||
next : "start"
|
||||
}, {
|
||||
// immediately return to the start mode without matching
|
||||
// anything
|
||||
token: "empty",
|
||||
regex: "",
|
||||
next: "start"
|
||||
next: "no_regex"
|
||||
}
|
||||
],
|
||||
"regex": [
|
||||
|
|
@ -240,7 +242,7 @@ var JavaScriptHighlightRules = function() {
|
|||
// flag
|
||||
token: "string.regexp",
|
||||
regex: "/\\w*",
|
||||
next: "start",
|
||||
next: "no_regex",
|
||||
}, {
|
||||
// invalid operators
|
||||
token : "invalid",
|
||||
|
|
@ -259,7 +261,7 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token: "empty",
|
||||
regex: "$",
|
||||
next: "start"
|
||||
next: "no_regex"
|
||||
}, {
|
||||
defaultToken: "string.regexp"
|
||||
}
|
||||
|
|
@ -278,7 +280,7 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token: "empty",
|
||||
regex: "$",
|
||||
next: "start"
|
||||
next: "no_regex"
|
||||
}, {
|
||||
defaultToken: "string.regexp.charachterclass"
|
||||
}
|
||||
|
|
@ -296,15 +298,15 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token: "empty",
|
||||
regex: "",
|
||||
next: "start"
|
||||
next: "no_regex"
|
||||
}
|
||||
],
|
||||
"comment_regex_allowed" : [
|
||||
{token : "comment", regex : "\\*\\/", next : "regex_allowed"},
|
||||
{token : "comment", regex : "\\*\\/", next : "start"},
|
||||
{defaultToken : "comment"}
|
||||
],
|
||||
"comment" : [
|
||||
{token : "comment", regex : "\\*\\/", next : "start"},
|
||||
{token : "comment", regex : "\\*\\/", next : "no_regex"},
|
||||
{defaultToken : "comment"}
|
||||
],
|
||||
"qqstring" : [
|
||||
|
|
@ -318,7 +320,7 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token : "string",
|
||||
regex : '"|$',
|
||||
next : "start",
|
||||
next : "no_regex",
|
||||
}, {
|
||||
defaultToken: "string"
|
||||
}
|
||||
|
|
@ -334,7 +336,7 @@ var JavaScriptHighlightRules = function() {
|
|||
}, {
|
||||
token : "string",
|
||||
regex : "'|$",
|
||||
next : "start",
|
||||
next : "no_regex",
|
||||
}, {
|
||||
defaultToken: "string"
|
||||
}
|
||||
|
|
@ -342,7 +344,7 @@ var JavaScriptHighlightRules = function() {
|
|||
};
|
||||
|
||||
this.embedRules(DocCommentHighlightRules, "doc-",
|
||||
[ DocCommentHighlightRules.getEndRule("start") ]);
|
||||
[ DocCommentHighlightRules.getEndRule("no_regex") ]);
|
||||
};
|
||||
|
||||
oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue