Add a few more JS styles for escaped chars & keywords, also tests
This commit is contained in:
parent
a0038069b8
commit
ee667179b3
4 changed files with 68 additions and 26 deletions
|
|
@ -1,5 +1,5 @@
|
|||
function foo(items) {
|
||||
for (var i=0; i<items.length; i++) {
|
||||
alert(items[i] + "juhu");
|
||||
alert(items[i] + "juhu\n");
|
||||
} // Real Tab.
|
||||
}
|
||||
|
|
@ -98,6 +98,14 @@ var JavaScriptHighlightRules = function() {
|
|||
+ unicode.packages.Mn + unicode.packages.Mc
|
||||
+ unicode.packages.Nd
|
||||
+ unicode.packages.Pc + "\\$_]*\\b";
|
||||
|
||||
var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
|
||||
"u[0-9a-fA-F]{4}|" + // unicode
|
||||
"[0-2][0-7]{0,2}|" + // oct
|
||||
"3[0-6][0-7]?|" + // oct
|
||||
"37[0-7]?|" + // oct
|
||||
"[4-7][0-7]?|" + //oct
|
||||
".)";
|
||||
|
||||
// regexp must not have capturing parentheses. Use (?:) instead.
|
||||
// regexps are ordered -> the first match is used
|
||||
|
|
@ -115,21 +123,13 @@ var JavaScriptHighlightRules = function() {
|
|||
regex : "\\/\\*",
|
||||
next : "comment"
|
||||
}, {
|
||||
token : "string", // single line
|
||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||
token : "string",
|
||||
regex : "'",
|
||||
next : "qstring"
|
||||
}, {
|
||||
token : "string", // multi line string start
|
||||
merge : true,
|
||||
regex : '["].*\\\\$',
|
||||
next : "qqstring"
|
||||
}, {
|
||||
token : "string", // single line
|
||||
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
|
||||
}, {
|
||||
token : "string", // multi line string start
|
||||
merge : true,
|
||||
regex : "['].*\\\\$",
|
||||
next : "qstring"
|
||||
token : "string",
|
||||
regex : '"',
|
||||
next : "qqstring"
|
||||
}, {
|
||||
token : "constant.numeric", // hex
|
||||
regex : "0[xX][0-9a-fA-F]+\\b"
|
||||
|
|
@ -146,6 +146,16 @@ var JavaScriptHighlightRules = function() {
|
|||
token : "keyword",
|
||||
regex : "(?:" + kwBeforeRe + ")\\b",
|
||||
next : "regex_allowed"
|
||||
}, {
|
||||
token : "support.function",
|
||||
regex : "\\b(?:s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|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(?=\\()"
|
||||
}, {
|
||||
token : "support.function.dom",
|
||||
regex : "\\b(?:s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\\b(?=\\()"
|
||||
}, {
|
||||
token : ["punctuation.operator", "support.function.firebug"],
|
||||
regex : "(\\.)(warn|info|log|error|time|timeEnd|assert)\\b"
|
||||
|
||||
}, {
|
||||
token : function(value) {
|
||||
if (globals.hasOwnProperty(value))
|
||||
|
|
@ -294,24 +304,28 @@ var JavaScriptHighlightRules = function() {
|
|||
],
|
||||
"qqstring" : [
|
||||
{
|
||||
token : "string",
|
||||
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
|
||||
next : "start"
|
||||
token : "constant.language.escape",
|
||||
regex : escapedRe
|
||||
}, {
|
||||
token : "string",
|
||||
merge : true,
|
||||
regex : '.+'
|
||||
regex : '[^"\\\\]+'
|
||||
}, {
|
||||
token : "string",
|
||||
regex : '"',
|
||||
next : "start"
|
||||
}
|
||||
],
|
||||
"qstring" : [
|
||||
{
|
||||
token : "string",
|
||||
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
|
||||
next : "start"
|
||||
token : "constant.language.escape",
|
||||
regex : escapedRe
|
||||
}, {
|
||||
token : "string",
|
||||
merge : true,
|
||||
regex : '.+'
|
||||
regex : "[^'\\\\]+"
|
||||
}, {
|
||||
token : "string",
|
||||
regex : "'",
|
||||
next : "start"
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -66,6 +66,17 @@ module.exports = {
|
|||
assert.equal("storage.type", tokens[4].type);
|
||||
},
|
||||
|
||||
"test: tokenize 'standard' functions" : function() {
|
||||
var line = "string.charCodeAt(23); document.getElementById('test'); console.log('Here it is');";
|
||||
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assert.equal(27, tokens.length);
|
||||
assert.equal("support.function", tokens[2].type); // charCodeAt
|
||||
assert.equal("support.function.dom", tokens[10].type); // getElementById
|
||||
assert.equal("support.function.firebug", tokens[20].type); // log
|
||||
},
|
||||
|
||||
"test: tokenize doc comment" : function() {
|
||||
var line = "abc /** de */ fg";
|
||||
|
||||
|
|
@ -164,6 +175,20 @@ module.exports = {
|
|||
assert.equal("paren.lparen", tokens[0].type);
|
||||
assert.equal("text", tokens[1].type);
|
||||
assert.equal("comment", tokens[2].type);
|
||||
},
|
||||
|
||||
"test skipping escaped chars": function() {
|
||||
var line = "console.log('Meh\\nNeh');"
|
||||
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assert.equal(11, tokens.length);
|
||||
assert.equal("constant.language.escape", tokens[6].type);
|
||||
|
||||
line = "console.log('\\u1232Feh');";
|
||||
tokens = this.tokenizer.getLineTokens(line, "start").tokens;
|
||||
|
||||
assert.equal(10, tokens.length);
|
||||
assert.equal("constant.language.escape", tokens[5].type);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -62,10 +62,13 @@ var supportedScopes = {
|
|||
"constant.language": "constant.language",
|
||||
"constant.library": "constant.library",
|
||||
"constant.numeric": "constant.numeric",
|
||||
"constant.character.escape" : "constant.character.escape",
|
||||
|
||||
"support": "support",
|
||||
"support.function": "support.function",
|
||||
|
||||
"support.function.dom": "support.function.dom",
|
||||
"support.function.firebug": "support.firebug",
|
||||
|
||||
"function": "function",
|
||||
"function.buildin": "function.buildin",
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue