#1069 support ruby heredocs
This commit is contained in:
parent
4cdc48cf63
commit
d2d42499ca
4 changed files with 104 additions and 40 deletions
|
|
@ -20,4 +20,16 @@ class Range
|
|||
end
|
||||
end
|
||||
|
||||
{:id => 34, :sdfasdfasdf => "asdasdads"}
|
||||
{:id => 34, :key => "value"}
|
||||
|
||||
|
||||
herDocs = [<<'FOO', <<BAR, <<-BAZ, <<-`EXEC`] #comment
|
||||
FOO #{literal}
|
||||
FOO
|
||||
BAR #{fact(10)}
|
||||
BAR
|
||||
BAZ indented
|
||||
BAZ
|
||||
echo hi
|
||||
EXEC
|
||||
puts herDocs
|
||||
|
|
@ -186,19 +186,7 @@ var LuaHighlightRules = function() {
|
|||
} ]
|
||||
};
|
||||
|
||||
var id = 0;
|
||||
for (var key in this.$rules) {
|
||||
var rule = this.$rules[key];
|
||||
for (var i = 0; i < rule.length; i++) {
|
||||
var state = rule[i];
|
||||
if (state.next && Array.isArray(state.next)) {
|
||||
console.log(state.next)
|
||||
var stateName = state.stateName || ("state" + id++);
|
||||
this.$rules[stateName] = state.next;
|
||||
state.next = stateName;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.normalizeRules();
|
||||
}
|
||||
|
||||
oop.inherits(LuaHighlightRules, TextHighlightRules);
|
||||
|
|
|
|||
|
|
@ -171,6 +171,43 @@ var RubyHighlightRules = function() {
|
|||
}, {
|
||||
token : "punctuation.separator.key-value",
|
||||
regex : "=>"
|
||||
}, {
|
||||
stateName: "heredoc",
|
||||
token : function(value, currentState, stack) {
|
||||
var next = value[0].length == 2 ? "heredoc" : "indentedHeredoc"
|
||||
stack.push(next, value[2])
|
||||
return ["constant", "string", "support.class", "string"]
|
||||
},
|
||||
regex : "(<<-?)(['\"`]?)([\\w]+)(['\"`]?)",
|
||||
rules: {
|
||||
heredoc: [{
|
||||
token: function(value, currentState, stack) {
|
||||
if (value == stack[1]) {
|
||||
stack.shift();
|
||||
stack.shift();
|
||||
return "support.class";
|
||||
}
|
||||
return "string";
|
||||
},
|
||||
regex: ".*$",
|
||||
"next": "start"
|
||||
}],
|
||||
indentedHeredoc: [{
|
||||
token: "string",
|
||||
regex: "^ +"
|
||||
}, {
|
||||
token: function(value, currentState, stack) {
|
||||
if (value == stack[1]) {
|
||||
stack.shift();
|
||||
stack.shift();
|
||||
return "support.class";
|
||||
}
|
||||
return "string";
|
||||
},
|
||||
regex: ".*$",
|
||||
"next": "start"
|
||||
}]
|
||||
}
|
||||
}, {
|
||||
token : "keyword.operator",
|
||||
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
|
||||
|
|
@ -196,6 +233,8 @@ var RubyHighlightRules = function() {
|
|||
}
|
||||
]
|
||||
};
|
||||
|
||||
this.normalizeRules();
|
||||
};
|
||||
|
||||
oop.inherits(RubyHighlightRules, TextHighlightRules);
|
||||
|
|
|
|||
|
|
@ -94,7 +94,32 @@ var TextHighlightRules = function() {
|
|||
|
||||
this.getEmbeds = function() {
|
||||
return this.$embeds;
|
||||
};
|
||||
|
||||
this.normalizeRules = function() {
|
||||
var id = 0;
|
||||
for (var key in this.$rules) {
|
||||
var rule = this.$rules[key];
|
||||
for (var i = 0; i < rule.length; i++) {
|
||||
var state = rule[i];
|
||||
if (state.next && Array.isArray(state.next)) {
|
||||
var stateName = state.stateName || ("state" + id++);
|
||||
this.$rules[stateName] = state.next;
|
||||
state.next = stateName;
|
||||
}
|
||||
if (state.rules) {
|
||||
for (var r in state.rules) {
|
||||
if (this.$rules[r]) {
|
||||
if (this.$rules[r].push)
|
||||
this.$rules[r].push.apply(this.$rules[r], state.rules[r]);
|
||||
} else {
|
||||
this.$rules[r] = state.rules[r];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) {
|
||||
var keywords = Object.create(null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue