fix function regexp

This commit is contained in:
ukyo 2012-09-30 20:20:36 +09:00
commit ffa0331542
2 changed files with 15 additions and 2 deletions

View file

@ -87,6 +87,8 @@ define(function(require, exports, module) {
"variable.language": variableLanguage
}, "identifier");
var functionRe = "(\\()([^)#]*)(\\))(\\s*)([\\-=]>)"
this.$rules = {
start : [
{
@ -160,7 +162,7 @@ define(function(require, exports, module) {
"entity.name.function", "text", "keyword.operator", "text",
"paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type"
],
regex : "(" + identifier + ")(\\s*)(=|:)(\\s*)(\\()([^)]*)(\\))(\\s*)([\\-=]>)"
regex : "(" + identifier + ")(\\s*)(=|:)(\\s*)" + functionRe
}, {
//play = ->
//play : ->
@ -173,7 +175,7 @@ define(function(require, exports, module) {
token : [
"paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type"
],
regex : "(\\()([^)]*)(\\))(\\s*)([\\-=]>)"
regex : functionRe
}, {
token : "identifier",
regex : "(?:(?:\\.|::)\\s*)" + identifier

View file

@ -104,6 +104,17 @@ module.exports = {
});
},
"test: tokenize function(invalid code): 'foo:(args#) ->'": function() {
var tokens = this.tokenizer.getLineTokens("foo:(args#) ->", "start").tokens;
assert.equal(tokens.length, 5);
[
"identifier", "punctuation.operator", "paren.lparen", "identifier", "comment"
].forEach(function(type, i) {
assert.equal(tokens[i].type, type);
});
},
"test: tokenize function: '(args) ->'": function() {
var tokens = this.tokenizer.getLineTokens("(args) ->", "start").tokens;
assert.equal(tokens.length, 5);