Use push/pop in css highlight rules
This commit is contained in:
parent
a6ba61e11a
commit
25853c11a1
1 changed files with 75 additions and 110 deletions
|
|
@ -60,11 +60,80 @@ var CssHighlightRules = 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
|
||||||
|
|
||||||
var base_ruleset = [
|
this.$rules = {
|
||||||
{
|
"start" : [{
|
||||||
token : "comment", // multi line comment
|
token : "comment", // multi line comment
|
||||||
regex : "\\/\\*",
|
regex : "\\/\\*",
|
||||||
next : "ruleset_comment"
|
push : "comment"
|
||||||
|
}, {
|
||||||
|
token: "paren.lparen",
|
||||||
|
regex: "\\{",
|
||||||
|
push: "ruleset"
|
||||||
|
}, {
|
||||||
|
token: "string",
|
||||||
|
regex: "@.*?{",
|
||||||
|
push: "media"
|
||||||
|
}, {
|
||||||
|
token: "keyword",
|
||||||
|
regex: "#[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
token: "variable",
|
||||||
|
regex: "\\.[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
token: "string",
|
||||||
|
regex: ":[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
token: "constant",
|
||||||
|
regex: "[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
caseInsensitive: true
|
||||||
|
}],
|
||||||
|
|
||||||
|
"media" : [{
|
||||||
|
token : "comment", // multi line comment
|
||||||
|
regex : "\\/\\*",
|
||||||
|
push : "comment"
|
||||||
|
}, {
|
||||||
|
token: "paren.lparen",
|
||||||
|
regex: "\\{",
|
||||||
|
push: "ruleset"
|
||||||
|
}, {
|
||||||
|
token: "string",
|
||||||
|
regex: "\\}",
|
||||||
|
next: "pop"
|
||||||
|
}, {
|
||||||
|
token: "keyword",
|
||||||
|
regex: "#[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
token: "variable",
|
||||||
|
regex: "\\.[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
token: "string",
|
||||||
|
regex: ":[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
token: "constant",
|
||||||
|
regex: "[a-z0-9-_]+"
|
||||||
|
}, {
|
||||||
|
caseInsensitive: true
|
||||||
|
}],
|
||||||
|
|
||||||
|
"comment" : [{
|
||||||
|
token : "comment",
|
||||||
|
regex : "\\*\\/",
|
||||||
|
next : "pop"
|
||||||
|
}, {
|
||||||
|
defaultToken : "comment"
|
||||||
|
}],
|
||||||
|
|
||||||
|
"ruleset" : [
|
||||||
|
{
|
||||||
|
token : "paren.rparen",
|
||||||
|
regex : "\\}",
|
||||||
|
next: "pop"
|
||||||
|
}, {
|
||||||
|
token : "comment", // multi line comment
|
||||||
|
regex : "\\/\\*",
|
||||||
|
push : "comment"
|
||||||
}, {
|
}, {
|
||||||
token : "string", // single line
|
token : "string", // single line
|
||||||
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
|
||||||
|
|
@ -97,114 +166,10 @@ var CssHighlightRules = function() {
|
||||||
regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
|
regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
|
||||||
}, {
|
}, {
|
||||||
caseInsensitive: true
|
caseInsensitive: true
|
||||||
}
|
}]
|
||||||
];
|
|
||||||
|
|
||||||
var ruleset = lang.copyArray(base_ruleset);
|
|
||||||
ruleset.unshift({
|
|
||||||
token : "paren.rparen",
|
|
||||||
regex : "\\}",
|
|
||||||
next: "start"
|
|
||||||
});
|
|
||||||
|
|
||||||
var media_ruleset = lang.copyArray( base_ruleset );
|
|
||||||
media_ruleset.unshift({
|
|
||||||
token : "paren.rparen",
|
|
||||||
regex : "\\}",
|
|
||||||
next: "media"
|
|
||||||
});
|
|
||||||
|
|
||||||
var base_comment = [{
|
|
||||||
token : "comment", // comment spanning whole line
|
|
||||||
regex : ".+"
|
|
||||||
}];
|
|
||||||
|
|
||||||
var comment = lang.copyArray(base_comment);
|
|
||||||
comment.unshift({
|
|
||||||
token : "comment", // closing comment
|
|
||||||
regex : ".*?\\*\\/",
|
|
||||||
next : "start"
|
|
||||||
});
|
|
||||||
|
|
||||||
var media_comment = lang.copyArray(base_comment);
|
|
||||||
media_comment.unshift({
|
|
||||||
token : "comment", // closing comment
|
|
||||||
regex : ".*?\\*\\/",
|
|
||||||
next : "media"
|
|
||||||
});
|
|
||||||
|
|
||||||
var ruleset_comment = lang.copyArray(base_comment);
|
|
||||||
ruleset_comment.unshift({
|
|
||||||
token : "comment", // closing comment
|
|
||||||
regex : ".*?\\*\\/",
|
|
||||||
next : "ruleset"
|
|
||||||
});
|
|
||||||
|
|
||||||
this.$rules = {
|
|
||||||
"start" : [{
|
|
||||||
token : "comment", // multi line comment
|
|
||||||
regex : "\\/\\*",
|
|
||||||
next : "comment"
|
|
||||||
}, {
|
|
||||||
token: "paren.lparen",
|
|
||||||
regex: "\\{",
|
|
||||||
next: "ruleset"
|
|
||||||
}, {
|
|
||||||
token: "string",
|
|
||||||
regex: "@.*?{",
|
|
||||||
next: "media"
|
|
||||||
},{
|
|
||||||
token: "keyword",
|
|
||||||
regex: "#[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
token: "variable",
|
|
||||||
regex: "\\.[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
token: "string",
|
|
||||||
regex: ":[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
token: "constant",
|
|
||||||
regex: "[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
caseInsensitive: true
|
|
||||||
}],
|
|
||||||
|
|
||||||
"media" : [ {
|
|
||||||
token : "comment", // multi line comment
|
|
||||||
regex : "\\/\\*",
|
|
||||||
next : "media_comment"
|
|
||||||
}, {
|
|
||||||
token: "paren.lparen",
|
|
||||||
regex: "\\{",
|
|
||||||
next: "media_ruleset"
|
|
||||||
},{
|
|
||||||
token: "string",
|
|
||||||
regex: "\\}",
|
|
||||||
next: "start"
|
|
||||||
},{
|
|
||||||
token: "keyword",
|
|
||||||
regex: "#[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
token: "variable",
|
|
||||||
regex: "\\.[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
token: "string",
|
|
||||||
regex: ":[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
token: "constant",
|
|
||||||
regex: "[a-z0-9-_]+"
|
|
||||||
},{
|
|
||||||
caseInsensitive: true
|
|
||||||
}],
|
|
||||||
|
|
||||||
"comment" : comment,
|
|
||||||
|
|
||||||
"ruleset" : ruleset,
|
|
||||||
"ruleset_comment" : ruleset_comment,
|
|
||||||
|
|
||||||
"media_ruleset" : media_ruleset,
|
|
||||||
"media_comment" : media_comment
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.normalizeRules();
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(CssHighlightRules, TextHighlightRules);
|
oop.inherits(CssHighlightRules, TextHighlightRules);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue