Inherit all HTML+server_side_directives rules from HTML rules.

This commit is contained in:
DanyaPostfactum 2013-06-24 21:03:49 +10:00
commit a6ba61e11a
12 changed files with 373 additions and 549 deletions

View file

@ -32,92 +32,18 @@ define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var xml_util = require("./xml_util");
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var ColdfusionHighlightRules = function() {
HtmlHighlightRules.call(this);
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
this.embedTagRules(JavaScriptHighlightRules, "cfjs-", "cfscript");
this.$rules = {
start : [ {
token : "text",
regex : "<\\!\\[CDATA\\[",
next : "cdata"
}, {
token : "xml-pe",
regex : "<\\?.*?\\?>"
}, {
token : "comment",
regex : "<\\!--",
next : "comment"
}, {
token : "meta.tag",
regex : "<(?=script)",
next : "script"
}, {
token : "meta.tag",
regex : "<(?=cfscript)",
next : "cfscript"
}, {
token : "meta.tag",
regex : "<(?=style)",
next : "style"
}, {
token : "meta.tag", // opening tag
regex : "<\\/?",
next : "tag"
} ],
cdata : [ {
token : "text",
regex : "\\]\\]>",
next : "start"
} ],
comment : [ {
token : "comment",
regex : ".*?-->",
next : "start"
}, {
defaultToken : "comment"
} ]
};
xml_util.tag(this.$rules, "tag", "start");
xml_util.tag(this.$rules, "style", "css-start");
xml_util.tag(this.$rules, "script", "js-start");
xml_util.tag(this.$rules, "cfscript", "js-start");
this.embedRules(JavaScriptHighlightRules, "js-", [{
token: "comment",
regex: "\\/\\/.*(?=<\\/script>)",
next: "tag"
}, {
token: "meta.tag",
regex: "<\\/(?=script)",
next: "tag"
}, {
token: "comment",
regex: "\\/\\/.*(?=<\\/cfscript>)",
next: "tag"
}, {
token: "meta.tag",
regex: "<\\/(?=cfscript)",
next: "tag"
}]);
this.embedRules(CssHighlightRules, "css-", [{
token: "meta.tag",
regex: "<\\/(?=style)",
next: "tag"
}]);
this.normalizeRules();
};
oop.inherits(ColdfusionHighlightRules, TextHighlightRules);
oop.inherits(ColdfusionHighlightRules, HtmlHighlightRules);
exports.ColdfusionHighlightRules = ColdfusionHighlightRules;
});

View file

@ -42,34 +42,21 @@ var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var CurlyHighlightRules = function() {
var CurlyRules = {
"start" : [
{
token: "variable",
regex: "{{",
next: "curly_mode"
}
],
HtmlHighlightRules.call(this);
"curly_mode" : [
{
token: "variable",
regex: "}}",
next: "start"
}
]
};
this.$rules["start"].unshift({
token: "variable",
regex: "{{",
push: "curly-start"
});
var htmlRules = new HtmlHighlightRules().getRules();
this.$rules["curly-start"] = [{
token: "variable",
regex: "}}",
next: "pop"
}];
// Inject Curly start array into HTML rules
htmlRules.start = CurlyRules.start.concat(htmlRules.start);
// Inject Mustach mode array into HTML rules
htmlRules.curly_mode = CurlyRules.curly_mode;
// Return the augmented HTML rules
this.$rules = htmlRules;
this.normalizeRules();
};
oop.inherits(CurlyHighlightRules, HtmlHighlightRules);

View file

@ -131,14 +131,18 @@ var FtlLangHighlightRules = function () {
oop.inherits(FtlLangHighlightRules, TextHighlightRules);
var FtlHighlightRules = function() {
HtmlHighlightRules.call(this);
var directives = "assign|attempt|break|case|compress|default|elseif|else|escape|fallback|function|flush|"
+ "ftl|global|if|import|include|list|local|lt|macro|nested|noescape|noparse|nt|recover|recurse|return|rt|"
+ "setting|stop|switch|t|visit";
HtmlHighlightRules.call(this);
for (var i in this.$rules) {
this.$rules[i].unshift({
var startRules = [
{
token : "comment",
regex : "<#--",
next : "ftl-dcomment"
}, {
token : "string.interpolated",
regex : "\\${",
push : "ftl-start"
@ -150,34 +154,35 @@ var FtlHighlightRules = function() {
token : "keyword.other",
regex : "</?@[a-zA-Z\\.]+",
push : "ftl-start"
});
}
}
];
this.embedRules(FtlLangHighlightRules, "ftl-");
var endRules = [
{
token : "keyword",
regex : "/?>",
next : "pop"
}, {
token : "string.interpolated",
regex : "}",
next : "pop"
}
];
this.$rules["ftl-start"].unshift({
token : "keyword",
regex : "/?>",
next : "pop"
}, {
token : "string.interpolated",
regex : "}",
next : "pop"
});
for (var key in this.$rules)
this.$rules[key].unshift.apply(this.$rules[key], startRules);
this.$rules.start.unshift({
token : "comment",
regex : "<#--",
next : "comment"
});
this.embedRules(FtlLangHighlightRules, "ftl-", endRules, ["start"]);
this.$rules.comment.unshift({
token : "comment",
regex : ".*?-->",
next : "start"
}, {
token : "comment",
regex : ".+"
this.addRules({
"ftl-dcomment" : [{
token : "comment",
regex : ".*?-->",
next : "pop"
}, {
token : "comment",
regex : ".+"
}]
});
this.normalizeRules();

View file

@ -37,32 +37,37 @@ define(function(require, exports, module) {
var HtmlRubyHighlightRules = function() {
HtmlHighlightRules.call(this);
for (var i in this.$rules) {
this.$rules[i].unshift({
var startRules = [
{
regex: "<%%|%%>",
token: "constant.language.escape"
}, {
token : "comment.start.erb",
token : "comment.start.erb",
regex : "<%#",
push : [{regex: "%>", next: "pop"}]
}, {
token : "support.ruby_tag",
regex : "<%+(?!>)[-=]?",
push : "ruby-start"
});
}
this.embedRules(RubyHighlightRules, "ruby-");
this.$rules["ruby-start"].unshift({
token : "support.ruby_tag",
regex : "%>",
next : "pop"
}, {
token: "comment",
regex: /#(?:[^%]|%[^>])*/
});
}
];
var endRules = [
{
token : "support.ruby_tag",
regex : "%>",
next : "pop"
}, {
token: "comment",
regex: "#(?:[^%]|%[^>])*"
}
];
for (var key in this.$rules)
this.$rules[key].unshift.apply(this.$rules[key], startRules);
this.embedRules(RubyHighlightRules, "ruby-", endRules, ["start"]);
this.normalizeRules();
};

View file

@ -37,45 +37,52 @@ var JavaHighlightRules = require("./java_highlight_rules").JavaHighlightRules;
var JspHighlightRules = function() {
HtmlHighlightRules.call(this);
for (var i in this.$rules) {
this.$rules[i].unshift({
token : "meta.tag", // jsp open tag
regex : "<%@?|<%=?|<jsp:[^>]+>",
next : "jsp-start"
});
}
var builtinVariables = 'request|response|out|session|' +
'application|config|pageContext|page|Exception';
var keywords = 'page|include|taglib';
this.embedRules(JavaHighlightRules, "jsp-");
var startRules = [
{
token : "comment",
regex : "<%--",
push : "jsp-dcomment"
}, {
token : "meta.tag", // jsp open tag
regex : "<%@?|<%=?|<jsp:[^>]+>",
push : "jsp-start"
}
];
this.$rules["start"].unshift({
token : "comment",
regex : "<%--",
next : "comment"
var endRules = [
{
token : "meta.tag", // jsp close tag
regex : "%>|<\\/jsp:[^>]+>",
next : "pop"
}, {
token: "variable.language",
regex : builtinVariables
}, {
token: "keyword",
regex : keywords
}
];
for (var key in this.$rules)
this.$rules[key].unshift.apply(this.$rules[key], startRules);
this.embedRules(JavaHighlightRules, "jsp-", endRules, ["start"]);
this.addRules({
"jsp-dcomment" : [{
token : "comment",
regex : ".*?--%>",
next : "pop"
}]
});
this.$rules["jsp-start"].unshift({
token : "meta.tag", // jsp close tag
regex : "%>|<\\/jsp:[^>]+>",
next : "start"
},
{
token: "variable.language",
regex : builtinVariables
}, {
token: "keyword",
regex : keywords
});
this.$rules.comment.unshift({
token : "comment",
regex : ".*?--%>",
next : "start"
});
this.normalizeRules();
};
oop.inherits(JspHighlightRules, HtmlHighlightRules);

View file

@ -32,12 +32,11 @@ define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var xmlUtil = require("./xml_util");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var LiquidHighlightRules = function() {
HtmlHighlightRules.call(this);
// see: https://developer.mozilla.org/en/Liquid/Reference/Global_Objects
var functions = (
@ -69,65 +68,28 @@ var LiquidHighlightRules = function() {
"keyword.definition": definitions
}, "identifier");
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = {
start : [{
// add liquid start tags to the HTML start tags
for (var rule in this.$rules) {
this.$rules[rule].unshift({
token : "variable",
regex : "{%",
next : "liquid_start"
push : "liquid-start"
}, {
token : "variable",
regex : "{{",
next : "liquid_start"
}, {
token : "meta.tag",
regex : "<\\!\\[CDATA\\[",
next : "cdata"
}, {
token : "xml-pe",
regex : "<\\?.*?\\?>"
}, {
token : "comment",
regex : "<\\!--",
next : "comment"
}, {
token : "meta.tag",
regex : "<(?=\\s*script\\b)",
next : "script"
}, {
token : "meta.tag",
regex : "<(?=\\s*style\\b)",
next : "style"
}, {
token : "meta.tag", // opening tag
regex : "<\\/?",
next : "tag"
} ],
push : "liquid-start"
});
}
cdata : [ {
token : "text",
regex : "\\]\\]>",
next : "start"
} ],
comment : [ {
token : "comment",
regex : ".*?-->",
next : "start"
}, {
defaultToken : "comment"
} ] ,
liquid_start : [{
this.addRules({
"liquid-start" : [{
token: "variable",
regex: "}}",
next: "start"
next: "pop"
}, {
token: "variable",
regex: "%}",
next: "start"
next: "pop"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
@ -159,27 +121,9 @@ var LiquidHighlightRules = function() {
token : "text",
regex : "\\s+"
}]
};
});
xmlUtil.tag(this.$rules, "tag", "start");
xmlUtil.tag(this.$rules, "style", "css-start");
xmlUtil.tag(this.$rules, "script", "js-start");
this.embedRules(JavaScriptHighlightRules, "js-", [{
token: "comment",
regex: "\\/\\/.*(?=<\\/script>)",
next: "tag"
}, {
token: "meta.tag",
regex: "<\\/(?=script)",
next: "tag"
}]);
this.embedRules(CssHighlightRules, "css-", [{
token: "meta.tag",
regex: "<\\/(?=style)",
next: "tag"
}]);
this.normalizeRules();
};
oop.inherits(LiquidHighlightRules, TextHighlightRules);

View file

@ -8,31 +8,38 @@ var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var LuaHighlightRules = require("./lua_highlight_rules").LuaHighlightRules;
var LuaPageHighlightRules = function() {
this.$rules = new HtmlHighlightRules().getRules();
for (var i in this.$rules) {
this.$rules[i].unshift({
HtmlHighlightRules.call(this);
var startRules = [
{
token: "keyword",
regex: "<\\%\\=?",
next: "lua-start"
push: "lua-start"
}, {
token: "keyword",
regex: "<\\?lua\\=?",
next: "lua-start"
});
}
this.embedRules(LuaHighlightRules, "lua-", [
push: "lua-start"
}
];
var endRules = [
{
token: "keyword",
regex: "\\%>",
next: "start"
},
{
next: "pop"
}, {
token: "keyword",
regex: "\\?>",
next: "start"
next: "pop"
}
]);
];
this.embedRules(LuaHighlightRules, "lua-", endRules, ["start"]);
for (var key in this.$rules)
this.$rules[key].unshift.apply(this.$rules[key], startRules);
this.normalizeRules();
};
oop.inherits(LuaPageHighlightRules, HtmlHighlightRules);

View file

@ -42,16 +42,57 @@ function github_embed(tag, prefix) {
return { // Github style block
token : "support.function",
regex : "^```" + tag + "\\s*$",
next : prefix + "start"
push : prefix + "start"
};
}
var MarkdownHighlightRules = function() {
HtmlHighlightRules.call(this);
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
this.$rules = {
this.$rules["start"].unshift({
token : "empty_line",
regex : '^$',
next: "allowBlock"
}, { // h1
token: "markup.heading.1",
regex: "^=+(?=\\s*$)"
}, { // h2
token: "markup.heading.2",
regex: "^\\-+(?=\\s*$)"
}, {
token : function(value) {
return "markup.heading." + value.length;
},
regex : /^#{1,6}(?=\s*[^ #]|\s+#.)/,
next : "header"
},
github_embed("(?:javascript|js)", "jscode-"),
github_embed("xml", "xmlcode-"),
github_embed("html", "htmlcode-"),
github_embed("css", "csscode-"),
{ // Github style block
token : "support.function",
regex : "^```\\s*[a-zA-Z]*(?:{.*?\\})?\\s*$",
next : "githubblock"
}, { // block quote
token : "string",
regex : "^>[ ].+$",
next : "blockquote"
}, { // HR * - _
token : "constant",
regex : "^ {0,2}(?:(?: ?\\* ?){3,}|(?: ?\\- ?){3,}|(?: ?\\_ ?){3,})\\s*$",
next: "allowBlock"
}, { // list
token : "markup.list",
regex : "^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+",
next : "listblock-start"
}, {
include : "basic"
});
this.addRules({
"basic" : [{
token : "constant.language.escape",
regex : /\\[\\`*_{}\[\]()#+\-.!]/
@ -93,47 +134,6 @@ var MarkdownHighlightRules = function() {
{token : "empty", regex : "", next : "start"}
],
"start" : [{
token : "empty_line",
regex : '^$',
next: "allowBlock"
}, { // h1
token: "markup.heading.1",
regex: "^=+(?=\\s*$)"
}, { // h2
token: "markup.heading.2",
regex: "^\\-+(?=\\s*$)"
}, {
token : function(value) {
return "markup.heading." + value.length;
},
regex : /^#{1,6}(?=\s*[^ #]|\s+#.)/,
next : "header"
},
github_embed("(?:javascript|js)", "js-"),
github_embed("xml", "xml-"),
github_embed("html", "html-"),
github_embed("css", "css-"),
{ // Github style block
token : "support.function",
regex : "^```\\s*[a-zA-Z]*(?:{.*?\\})?\\s*$",
next : "githubblock"
}, { // block quote
token : "string",
regex : "^>[ ].+$",
next : "blockquote"
}, { // HR * - _
token : "constant",
regex : "^ {0,2}(?:(?: ?\\* ?){3,}|(?: ?\\- ?){3,}|(?: ?\\_ ?){3,})\\s*$",
next: "allowBlock"
}, { // list
token : "markup.list",
regex : "^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+",
next : "listblock-start"
}, {
include : "basic"
}],
"header" : [{
regex: "$",
next : "start"
@ -180,40 +180,32 @@ var MarkdownHighlightRules = function() {
token : "support.function",
regex : ".+"
} ]
};
});
this.embedRules(JavaScriptHighlightRules, "js-", [{
this.embedRules(JavaScriptHighlightRules, "jscode-", [{
token : "support.function",
regex : "^```",
next : "start"
next : "pop"
}]);
this.embedRules(HtmlHighlightRules, "html-", [{
this.embedRules(HtmlHighlightRules, "htmlcode-", [{
token : "support.function",
regex : "^```",
next : "start"
next : "pop"
}]);
this.embedRules(CssHighlightRules, "css-", [{
this.embedRules(CssHighlightRules, "csscode-", [{
token : "support.function",
regex : "^```",
next : "start"
next : "pop"
}]);
this.embedRules(XmlHighlightRules, "xml-", [{
this.embedRules(XmlHighlightRules, "xmlcode-", [{
token : "support.function",
regex : "^```",
next : "start"
next : "pop"
}]);
var html = new HtmlHighlightRules().getRules();
for (var i in html) {
if (this.$rules[i])
this.$rules[i] = this.$rules[i].concat(html[i]);
else
this.$rules[i] = html[i];
}
this.normalizeRules();
};
oop.inherits(MarkdownHighlightRules, TextHighlightRules);

View file

@ -1057,21 +1057,27 @@ oop.inherits(PhpLangHighlightRules, TextHighlightRules);
var PhpHighlightRules = function() {
HtmlHighlightRules.call(this);
for (var i in this.$rules) {
this.$rules[i].unshift({
var startRules = [
{
token : "support.php_tag", // php open tag
regex : "<\\?(?:php|=)?",
push : "php-start"
});
}
}
];
this.embedRules(PhpLangHighlightRules, "php-");
var endRules = [
{
token : "support.php_tag", // php close tag
regex : "\\?>",
next : "pop"
}
];
for (var key in this.$rules)
this.$rules[key].unshift.apply(this.$rules[key], startRules);
this.embedRules(PhpLangHighlightRules, "php-", endRules, ["start"]);
this.$rules["php-start"].unshift({
token : "support.php_tag", // php close tag
regex : "\\?>",
next : "pop"
});
this.normalizeRules();
};

View file

@ -24,24 +24,21 @@ var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var RHtmlHighlightRules = function() {
HtmlHighlightRules.call(this);
// regexp must not have capturing parentheses
// regexps are ordered -> the first match is used
this.$rules = new HtmlHighlightRules().getRules();
this.$rules["start"].unshift({
token: "support.function.codebegin",
regex: "^<" + "!--\\s*begin.rcode\\s*(?:.*)",
next: "r-start"
});
var rRules = new RHighlightRules().getRules();
this.addRules(rRules, "r-");
this.$rules["r-start"].unshift({
this.embedRules(RHighlightRules, "r-", [{
token: "support.function.codeend",
regex: "^\\s*end.rcode\\s*-->",
next: "start"
});
}], ["start"]);
this.normalizeRules();
};
oop.inherits(RHtmlHighlightRules, TextHighlightRules);

View file

@ -56,35 +56,37 @@ var TwigHighlightRules = function() {
}, "identifier");
// add twig start tags to the HTML start tags
this.$rules.start.unshift({
token : "variable.other.readwrite.local.twig",
regex : "\\{\\{-?",
next : "twig-start"
}, {
token : "meta.tag.twig",
regex : "\\{%-?",
next : "twig-start"
}, {
token : "comment.block.twig",
regex : "\\{#-?",
next : "comment"
});
for (var rule in this.$rules) {
this.$rules[rule].unshift({
token : "variable.other.readwrite.local.twig",
regex : "\\{\\{-?",
push : "twig-start"
}, {
token : "meta.tag.twig",
regex : "\\{%-?",
push : "twig-start"
}, {
token : "comment.block.twig",
regex : "\\{#-?",
push : "twig-comment"
});
}
// add twig closing comment to HTML comments
this.$rules.comment.unshift({
this.$rules["twig-comment"] = [{
token : "comment.block.twig",
regex : ".*-?#\\}",
next : "start"
});
next : "pop"
}];
this.$rules["twig-start"] = [{
token : "variable.other.readwrite.local.twig",
regex : "-?\\}\\}",
next : "start"
next : "pop"
}, {
token : "meta.tag.twig",
regex : "-?%\\}",
next : "start"
next : "pop"
}, {
token : "string",
regex : "'",
@ -131,8 +133,6 @@ var TwigHighlightRules = function() {
regex : "\\s+"
} ];
this.$rules["twig-qqstring"] = [{
token : "constant.language.escape",
regex : /\\[\\"$#ntr]|#{[^"}]*}/
@ -156,6 +156,8 @@ var TwigHighlightRules = function() {
defaultToken : "string"
}
];
this.normalizeRules();
};
oop.inherits(TwigHighlightRules, TextHighlightRules);

View file

@ -3,12 +3,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var lang = require("../lib/lang");
var xmlUtil = require("./xml_util");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var VelocityHighlightRules = function() {
HtmlHighlightRules.call(this);
var builtinConstants = lang.arrayToMap(
('true|false|null').split('|')
);
@ -31,198 +31,144 @@ var VelocityHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = {
"start" : [
{
token : "meta.tag",
regex : "<\\!\\[CDATA\\[",
next : "cdata"
}, {
token : "xml-pe",
regex : "<\\?.*?\\?>"
}, {
token : "comment",
regex : "<\\!--",
next : "comment"
}, {
token : "meta.tag",
regex : "<(?=\\s*script\\b)",
next : "script"
}, {
token : "meta.tag",
regex : "<(?=\\s*style\\b)",
next : "style"
}, {
token : "meta.tag", // opening tag
regex : "<\\/?(?=[a-z])",
next : "tag"
}, {
token : "comment",
regex : "##.*$"
},{
token : "comment.block", // multi line comment
regex : "#\\*",
next : "comment"
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
token : function(value) {
if (keywords.hasOwnProperty(value))
return "keyword";
else if (builtinConstants.hasOwnProperty(value))
return "constant.language";
else if (builtinVariables.hasOwnProperty(value))
return "variable.language";
else if (builtinFunctions.hasOwnProperty(value) || builtinFunctions.hasOwnProperty(value.substring(1)))
return "support.function";
else if (value == "debugger")
return "invalid.deprecated";
else
if(value.match(/^(\$[a-zA-Z_][a-zA-Z0-9_]*)$/))
return "variable";
return "identifier";
},
// TODO: Unicode escape sequences
// TODO: Unicode identifiers
regex : "[a-zA-Z$#][a-zA-Z0-9_]*\\b"
}, {
token : "keyword.operator",
regex : "!|&|\\*|\\-|\\+|=|!=|<=|>=|<|>|&&|\\|\\|"
}, {
token : "lparen",
regex : "[[({]"
}, {
token : "rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
],
"cdata" : [
{
token : "text",
regex : "\\]\\]>",
next : "start"
}, {
token : "text",
regex : "\\s+"
}, {
token : "text",
regex : ".+"
}
],
"comment" : [
{
token : "comment", // closing comment
regex : "\\*#|-->",
next : "start"
}, {
defaultToken: "comment"
}
],
"vm_start" : [
{
token: "variable",
regex: "}",
next: "start"
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
token : function(value) {
if (keywords.hasOwnProperty(value))
return "keyword";
else if (builtinConstants.hasOwnProperty(value))
return "constant.language";
else if (builtinVariables.hasOwnProperty(value))
return "variable.language";
else if (builtinFunctions.hasOwnProperty(value) || builtinFunctions.hasOwnProperty(value.substring(1)))
return "support.function";
else if (value == "debugger")
return "invalid.deprecated";
else
if(value.match(/^(\$[a-zA-Z_$][a-zA-Z0-9_]*)$/))
return "variable";
return "identifier";
},
// TODO: Unicode escape sequences
// TODO: Unicode identifiers
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "keyword.operator",
regex : "!|&|\\*|\\-|\\+|=|!=|<=|>=|<|>|&&|\\|\\|"
}, {
token : "lparen",
regex : "[[({]"
}, {
token : "rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
]
};
this.$rules.start.push(
{
token : "comment",
regex : "##.*$"
},{
token : "comment.block", // multi line comment
regex : "#\\*",
next : "vm_comment"
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
token : function(value) {
if (keywords.hasOwnProperty(value))
return "keyword";
else if (builtinConstants.hasOwnProperty(value))
return "constant.language";
else if (builtinVariables.hasOwnProperty(value))
return "variable.language";
else if (builtinFunctions.hasOwnProperty(value) || builtinFunctions.hasOwnProperty(value.substring(1)))
return "support.function";
else if (value == "debugger")
return "invalid.deprecated";
else
if(value.match(/^(\$[a-zA-Z_][a-zA-Z0-9_]*)$/))
return "variable";
return "identifier";
},
// TODO: Unicode escape sequences
// TODO: Unicode identifiers
regex : "[a-zA-Z$#][a-zA-Z0-9_]*\\b"
}, {
token : "keyword.operator",
regex : "!|&|\\*|\\-|\\+|=|!=|<=|>=|<|>|&&|\\|\\|"
}, {
token : "lparen",
regex : "[[({]"
}, {
token : "rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
);
xmlUtil.tag(this.$rules, "tag", "start");
xmlUtil.tag(this.$rules, "style", "css-start");
xmlUtil.tag(this.$rules, "script", "js-start");
this.$rules["vm_comment"] = [
{
token : "comment", // closing comment
regex : "\\*#|-->",
next : "start"
}, {
defaultToken: "comment"
}
];
this.embedRules(JavaScriptHighlightRules, "js-", [{
token: "comment",
regex: "\\/\\/.*(?=<\\/script>)",
next: "tag"
}, {
token: "meta.tag",
regex: "<\\/(?=script)",
next: "tag"
}]);
this.embedRules(CssHighlightRules, "css-", [{
token: "meta.tag",
regex: "<\\/(?=style)",
next: "tag"
}]);
this.$rules["vm_start"] = [
{
token: "variable",
regex: "}",
next: "pop"
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
token : function(value) {
if (keywords.hasOwnProperty(value))
return "keyword";
else if (builtinConstants.hasOwnProperty(value))
return "constant.language";
else if (builtinVariables.hasOwnProperty(value))
return "variable.language";
else if (builtinFunctions.hasOwnProperty(value) || builtinFunctions.hasOwnProperty(value.substring(1)))
return "support.function";
else if (value == "debugger")
return "invalid.deprecated";
else
if(value.match(/^(\$[a-zA-Z_$][a-zA-Z0-9_]*)$/))
return "variable";
return "identifier";
},
// TODO: Unicode escape sequences
// TODO: Unicode identifiers
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "keyword.operator",
regex : "!|&|\\*|\\-|\\+|=|!=|<=|>=|<|>|&&|\\|\\|"
}, {
token : "lparen",
regex : "[[({]"
}, {
token : "rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
];
for (var i in this.$rules) {
this.$rules[i].unshift({
token: "variable",
regex: "\\${",
next: "vm_start"
push: "vm_start"
});
}
this.normalizeRules();
};
oop.inherits(VelocityHighlightRules, TextHighlightRules);