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"; "use strict";
var oop = require("../lib/oop"); var oop = require("../lib/oop");
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules; var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var xml_util = require("./xml_util");
var ColdfusionHighlightRules = function() { var ColdfusionHighlightRules = function() {
HtmlHighlightRules.call(this);
// regexp must not have capturing parentheses this.embedTagRules(JavaScriptHighlightRules, "cfjs-", "cfscript");
// regexps are ordered -> the first match is used
this.$rules = { this.normalizeRules();
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"
}]);
}; };
oop.inherits(ColdfusionHighlightRules, TextHighlightRules); oop.inherits(ColdfusionHighlightRules, HtmlHighlightRules);
exports.ColdfusionHighlightRules = ColdfusionHighlightRules; exports.ColdfusionHighlightRules = ColdfusionHighlightRules;
}); });

View file

@ -42,34 +42,21 @@ var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var CurlyHighlightRules = function() { var CurlyHighlightRules = function() {
var CurlyRules = { HtmlHighlightRules.call(this);
"start" : [
{ this.$rules["start"].unshift({
token: "variable", token: "variable",
regex: "{{", regex: "{{",
next: "curly_mode" push: "curly-start"
} });
],
"curly_mode" : [ this.$rules["curly-start"] = [{
{
token: "variable", token: "variable",
regex: "}}", regex: "}}",
next: "start" next: "pop"
} }];
]
};
var htmlRules = new HtmlHighlightRules().getRules(); this.normalizeRules();
// 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;
}; };
oop.inherits(CurlyHighlightRules, HtmlHighlightRules); oop.inherits(CurlyHighlightRules, HtmlHighlightRules);

View file

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

View file

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

View file

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

View file

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

View file

@ -42,16 +42,57 @@ function github_embed(tag, prefix) {
return { // Github style block return { // Github style block
token : "support.function", token : "support.function",
regex : "^```" + tag + "\\s*$", regex : "^```" + tag + "\\s*$",
next : prefix + "start" push : prefix + "start"
}; };
} }
var MarkdownHighlightRules = function() { var MarkdownHighlightRules = function() {
HtmlHighlightRules.call(this);
// regexp must not have capturing parentheses // regexp must not have capturing parentheses
// regexps are ordered -> the first match is used // 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" : [{ "basic" : [{
token : "constant.language.escape", token : "constant.language.escape",
regex : /\\[\\`*_{}\[\]()#+\-.!]/ regex : /\\[\\`*_{}\[\]()#+\-.!]/
@ -93,47 +134,6 @@ var MarkdownHighlightRules = function() {
{token : "empty", regex : "", next : "start"} {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" : [{ "header" : [{
regex: "$", regex: "$",
next : "start" next : "start"
@ -180,40 +180,32 @@ var MarkdownHighlightRules = function() {
token : "support.function", token : "support.function",
regex : ".+" regex : ".+"
} ] } ]
}; });
this.embedRules(JavaScriptHighlightRules, "js-", [{ this.embedRules(JavaScriptHighlightRules, "jscode-", [{
token : "support.function", token : "support.function",
regex : "^```", regex : "^```",
next : "start" next : "pop"
}]); }]);
this.embedRules(HtmlHighlightRules, "html-", [{ this.embedRules(HtmlHighlightRules, "htmlcode-", [{
token : "support.function", token : "support.function",
regex : "^```", regex : "^```",
next : "start" next : "pop"
}]); }]);
this.embedRules(CssHighlightRules, "css-", [{ this.embedRules(CssHighlightRules, "csscode-", [{
token : "support.function", token : "support.function",
regex : "^```", regex : "^```",
next : "start" next : "pop"
}]); }]);
this.embedRules(XmlHighlightRules, "xml-", [{ this.embedRules(XmlHighlightRules, "xmlcode-", [{
token : "support.function", token : "support.function",
regex : "^```", 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(); this.normalizeRules();
}; };
oop.inherits(MarkdownHighlightRules, TextHighlightRules); oop.inherits(MarkdownHighlightRules, TextHighlightRules);

View file

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

View file

@ -24,24 +24,21 @@ var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var RHtmlHighlightRules = function() { 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({ this.$rules["start"].unshift({
token: "support.function.codebegin", token: "support.function.codebegin",
regex: "^<" + "!--\\s*begin.rcode\\s*(?:.*)", regex: "^<" + "!--\\s*begin.rcode\\s*(?:.*)",
next: "r-start" next: "r-start"
}); });
var rRules = new RHighlightRules().getRules(); this.embedRules(RHighlightRules, "r-", [{
this.addRules(rRules, "r-");
this.$rules["r-start"].unshift({
token: "support.function.codeend", token: "support.function.codeend",
regex: "^\\s*end.rcode\\s*-->", regex: "^\\s*end.rcode\\s*-->",
next: "start" next: "start"
}); }], ["start"]);
this.normalizeRules();
}; };
oop.inherits(RHtmlHighlightRules, TextHighlightRules); oop.inherits(RHtmlHighlightRules, TextHighlightRules);

View file

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

View file

@ -3,12 +3,12 @@ define(function(require, exports, module) {
var oop = require("../lib/oop"); var oop = require("../lib/oop");
var lang = require("../lib/lang"); var lang = require("../lib/lang");
var xmlUtil = require("./xml_util");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules; var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules;
var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
var VelocityHighlightRules = function() { var VelocityHighlightRules = function() {
HtmlHighlightRules.call(this);
var builtinConstants = lang.arrayToMap( var builtinConstants = lang.arrayToMap(
('true|false|null').split('|') ('true|false|null').split('|')
); );
@ -31,38 +31,14 @@ var VelocityHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead. // regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used // regexps are ordered -> the first match is used
this.$rules = { this.$rules.start.push(
"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", token : "comment",
regex : "##.*$" regex : "##.*$"
},{ },{
token : "comment.block", // multi line comment token : "comment.block", // multi line comment
regex : "#\\*", regex : "#\\*",
next : "comment" next : "vm_comment"
}, { }, {
token : "string.regexp", token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
@ -114,21 +90,9 @@ var VelocityHighlightRules = function() {
token : "text", token : "text",
regex : "\\s+" regex : "\\s+"
} }
], );
"cdata" : [
{ this.$rules["vm_comment"] = [
token : "text",
regex : "\\]\\]>",
next : "start"
}, {
token : "text",
regex : "\\s+"
}, {
token : "text",
regex : ".+"
}
],
"comment" : [
{ {
token : "comment", // closing comment token : "comment", // closing comment
regex : "\\*#|-->", regex : "\\*#|-->",
@ -136,12 +100,13 @@ var VelocityHighlightRules = function() {
}, { }, {
defaultToken: "comment" defaultToken: "comment"
} }
], ];
"vm_start" : [
this.$rules["vm_start"] = [
{ {
token: "variable", token: "variable",
regex: "}", regex: "}",
next: "start" next: "pop"
}, { }, {
token : "string.regexp", token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
@ -193,36 +158,17 @@ var VelocityHighlightRules = function() {
token : "text", token : "text",
regex : "\\s+" 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"
}]);
for (var i in this.$rules) { for (var i in this.$rules) {
this.$rules[i].unshift({ this.$rules[i].unshift({
token: "variable", token: "variable",
regex: "\\${", regex: "\\${",
next: "vm_start" push: "vm_start"
}); });
} }
this.normalizeRules();
}; };
oop.inherits(VelocityHighlightRules, TextHighlightRules); oop.inherits(VelocityHighlightRules, TextHighlightRules);