Highlight HTML in PHP mode

This commit is contained in:
Adam Jimenez 2011-12-12 13:17:03 +00:00
commit dc32557f23

View file

@ -44,6 +44,7 @@ var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocComme
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var PhpHighlightRules = function() { var PhpHighlightRules = function() {
var docComment = new DocCommentHighlightRules();
// http://php.net/quickref.php // http://php.net/quickref.php
var builtinFunctions = lang.arrayToMap( var builtinFunctions = lang.arrayToMap(
('abs|acos|acosh|addcslashes|addslashes|aggregate|aggregate_info|aggregate_methods|aggregate_methods_by_list|aggregate_methods_by_regexp|' + ('abs|acos|acosh|addcslashes|addslashes|aggregate|aggregate_info|aggregate_methods|aggregate_methods_by_list|aggregate_methods_by_regexp|' +
@ -903,13 +904,32 @@ var PhpHighlightRules = function() {
this.$rules = { this.$rules = {
"start" : [ "start" : [
{ {
token : "support", // php open tag token : "support.php_tag", // php open tag
regex : "<\\?(?:php|\\=)" regex : "<\\?(?:php|\\=)"
}, },
{ {
token : "support", // php close tag token : "support.php_tag", // php close tag
regex : "\\?>" regex : "\\?>"
}, },
{
token : "comment",
regex : "<\\!--",
next : "htmlcomment"
},
{
token : "meta.tag",
regex : "<style",
next : "css"
},
{
token : "meta.tag", // opening tag
regex : "<\\/?[-_a-zA-Z0-9:]+",
next : "htmltag"
},
{
token : 'meta.tag',
regex : '<\!DOCTYPE.*?>'
},
{ {
token : "comment", token : "comment",
regex : "\\/\\/.*$" regex : "\\/\\/.*$"
@ -918,10 +938,9 @@ var PhpHighlightRules = function() {
token : "comment", token : "comment",
regex : "#.*$" regex : "#.*$"
}, },
new DocCommentHighlightRules().getStartRule("doc-start"), docComment.getStartRule("doc-start"),
{ {
token : "comment", // multi line comment token : "comment", // multi line comment
merge : true,
regex : "\\/\\*", regex : "\\/\\*",
next : "comment" next : "comment"
}, { }, {
@ -932,7 +951,6 @@ var PhpHighlightRules = function() {
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, { }, {
token : "string", // multi line string start token : "string", // multi line string start
merge : true,
regex : '["].*\\\\$', regex : '["].*\\\\$',
next : "qqstring" next : "qqstring"
}, { }, {
@ -940,7 +958,6 @@ var PhpHighlightRules = function() {
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, { }, {
token : "string", // multi line string start token : "string", // multi line string start
merge : true,
regex : "['].*\\\\$", regex : "['].*\\\\$",
next : "qstring" next : "qstring"
}, { }, {
@ -976,11 +993,7 @@ var PhpHighlightRules = function() {
"T(?:HOUS(?:ANDS_SEP|EP)|_FMT(?:_AMPM|))|YES(?:EXPR|STR)|STD(?:IN|OUT|ERR))\\b" "T(?:HOUS(?:ANDS_SEP|EP)|_FMT(?:_AMPM|))|YES(?:EXPR|STR)|STD(?:IN|OUT|ERR))\\b"
}, { }, {
token : function(value) { token : function(value) {
if (keywordsDeprecated.hasOwnProperty(value)) if (keywords.hasOwnProperty(value))
return "invalid.deprecated";
else if (keywords.hasOwnProperty(value))
return "keyword";
else if (languageConstructs.hasOwnProperty(value))
return "keyword"; return "keyword";
else if (builtinConstants.hasOwnProperty(value)) else if (builtinConstants.hasOwnProperty(value))
return "constant.language"; return "constant.language";
@ -988,12 +1001,12 @@ var PhpHighlightRules = function() {
return "variable.language"; return "variable.language";
else if (futureReserved.hasOwnProperty(value)) else if (futureReserved.hasOwnProperty(value))
return "invalid.illegal"; return "invalid.illegal";
else if (builtinFunctionsDeprecated.hasOwnProperty(value))
return "invalid.deprecated";
else if (builtinFunctions.hasOwnProperty(value)) else if (builtinFunctions.hasOwnProperty(value))
return "support.function"; return "support.function";
else if (value == "debugger")
return "invalid.deprecated";
else else
if(value.match(/^(\$[a-zA-Z_][a-zA-Z0-9_]*|self|parent)$/)) if(value.match(/^(\$[a-zA-Z][a-zA-Z0-9_]*|self|parent)$/))
return "variable"; return "variable";
return "identifier"; return "identifier";
}, },
@ -1004,10 +1017,10 @@ var PhpHighlightRules = function() {
token : "keyword.operator", token : "keyword.operator",
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
}, { }, {
token : "paren.lparen", token : "lparen",
regex : "[[({]" regex : "[[({]"
}, { }, {
token : "paren.rparen", token : "rparen",
regex : "[\\])}]" regex : "[\\])}]"
}, { }, {
token : "text", token : "text",
@ -1021,7 +1034,6 @@ var PhpHighlightRules = function() {
next : "start" next : "start"
}, { }, {
token : "comment", // comment spanning whole line token : "comment", // comment spanning whole line
merge : true,
regex : ".+" regex : ".+"
} }
], ],
@ -1032,7 +1044,6 @@ var PhpHighlightRules = function() {
next : "start" next : "start"
}, { }, {
token : "string", token : "string",
merge : true,
regex : '.+' regex : '.+'
} }
], ],
@ -1043,10 +1054,98 @@ var PhpHighlightRules = function() {
next : "start" next : "start"
}, { }, {
token : "string", token : "string",
merge : true,
regex : '.+' regex : '.+'
} }
] ],
"htmlcomment" : [
{
token : "comment",
regex : ".*?-->",
next : "start"
}, {
token : "comment",
regex : ".+"
}
],
"htmltag" : [
{
token : "meta.tag",
regex : ">",
next : "start"
}, {
token : "text",
regex : "[-_a-zA-Z0-9:]+"
}, {
token : "text",
regex : "\\s+"
}, {
token : "string",
regex : '".*?"'
}, {
token : "string",
regex : "'.*?'"
}
],
"css" : [
{
token : "meta.tag",
regex : "<\/style>",
next : "htmltag"
}, {
token : "meta.tag",
regex : ">",
}, {
token : 'text',
regex : "(?:media|type|href)"
}, {
token : 'string',
regex : '=".*?"'
}, {
token : "paren.lparen",
regex : "\{",
next : "cssdeclaration",
}, {
token : "keyword",
regex : "#[A-Za-z0-9\-\_\.]+"
}, {
token : "variable",
regex : "\\.[A-Za-z0-9\-\_\.]+"
}, {
token : "constant",
regex : "[A-Za-z0-9]+"
}
],
"cssdeclaration" : [
{
token : "support.type",
regex : "[\-a-zA-Z]+",
next : "cssvalue"
},
{
token : "paren.rparen",
regex : '\}',
next : "css"
}
],
"cssvalue" : [
{
token : "text",
regex : "\:"
},
{
token : "constant",
regex : "#[0-9a-zA-Z]+"
},
{
token : "text",
regex : "[\-\_0-9a-zA-Z\"' ,%]+"
},
{
token : "text",
regex : ";",
next : "cssdeclaration"
}
],
}; };
this.embedRules(DocCommentHighlightRules, "doc-", this.embedRules(DocCommentHighlightRules, "doc-",