From 92935b48967a09a957441da453b44be124ab1a5a Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 12 Jan 2013 12:49:20 +0400 Subject: [PATCH] fix highlighting of CoffeeScript function arguments issue #1168 --- lib/ace/mode/coffee_highlight_rules.js | 117 ++++--------------------- 1 file changed, 16 insertions(+), 101 deletions(-) diff --git a/lib/ace/mode/coffee_highlight_rules.js b/lib/ace/mode/coffee_highlight_rules.js index 78e0bf6e..22298451 100644 --- a/lib/ace/mode/coffee_highlight_rules.js +++ b/lib/ace/mode/coffee_highlight_rules.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -86,23 +86,9 @@ define(function(require, exports, module) { "variable.language": variableLanguage }, "identifier"); - var functionRules = { - "({args})->": { - token: ["paren.lparen", "text", "paren.lparen", "text", "variable.parameter", "text", "paren.rparen", "text", "paren.rparen", "text", "storage.type"], - regex: "(\\()(\\s*)(\\{)(\\s*)([$@A-Za-z_\\x7f-\\uffff][$@\\w\\s,\\x7f-\\uffff]*)(\\s*)(\\})(\\s*)(\\))(\\s*)([\\-=]>)" - }, - "({})->": { - token: ["paren.lparen", "text", "paren.lparen", "text", "paren.rparen", "text", "paren.rparen", "text", "storage.type"], - regex: "(\\()(\\s*)(\\{)(\\s*)(\\})(\\s*)(\\))(\\s*)([\\-=]>)" - }, - "(args)->": { - token: ["paren.lparen", "text", "variable.parameter", "text", "paren.rparen", "text", "storage.type"], - regex: "(\\()(\\s*)([$@A-Za-z_\\x7f-\\uffff][\\s\\x21-\\uffff]*)(\\s*)(\\))(\\s*)([\\-=]>)" - }, - "()->": { - token: ["paren.lparen", "text", "paren.rparen", "text", "storage.type"], - regex: "(\\()(\\s*)(\\))(\\s*)([\\-=]>)" - } + var functionRule = { + token: ["paren.lparen", "variable.parameter", "paren.rparen", "text", "storage.type"], + regex: /(\()((?:"[^")]*?"|'[^')]*?'|\/[^\/)]*?\/|[^()\"'\/])*?)(\))(\s*)([\-=]>)/ }; this.$rules = { @@ -145,94 +131,23 @@ define(function(require, exports, module) { token : "comment", regex : "#.*" }, { - token : [ - "punctuation.operator", "identifier" - ], - regex : "(\\.)(" + illegal + ")" + token : ["punctuation.operator", "text", "identifier"], + regex : "(\\.)(\\s*)(" + identifier + ")" }, { token : "punctuation.operator", regex : "\\." }, { //class A extends B - token : [ - "keyword", "text", "language.support.class", "text", "keyword", "text", "language.support.class" - ], - regex : "(class)(\\s+)(" + identifier + ")(\\s+)(extends)(\\s+)(" + identifier + ")" + token : ["keyword", "text", "language.support.class", + "text", "keyword", "text", "language.support.class"], + regex : "(class)(\\s+)(" + identifier + ")(?:(\\s+)(extends)(\\s+)(" + identifier + "))?" }, { - //class A - token : [ - "keyword", "text", "language.support.class" - ], - regex : "(class)(\\s+)(" + identifier + ")" - }, { - //play = ({args}) -> - token : [ - "entity.name.function", "text", "keyword.operator", "text" - ].concat(functionRules["({args})->"].token), - regex : "(" + identifier + ")(\\s*)(=)(\\s*)" + functionRules["({args})->"].regex - }, { - //play : ({args}) -> - token : [ - "entity.name.function", "text", "punctuation.operator", "text" - ].concat(functionRules["({args})->"].token), - regex : "(" + identifier + ")(\\s*)(:)(\\s*)" + functionRules["({args})->"].regex - }, { - //play = ({}) -> - token : [ - "entity.name.function", "text", "keyword.operator", "text" - ].concat(functionRules["({})->"].token), - regex : "(" + identifier + ")(\\s*)(=)(\\s*)" + functionRules["({})->"].regex - }, { - //play : ({}) -> - token : [ - "entity.name.function", "text", "punctuation.operator", "text" - ].concat(functionRules["({})->"].token), - regex : "(" + identifier + ")(\\s*)(:)(\\s*)" + functionRules["({})->"].regex - }, { - //play = (args) -> - token : [ - "entity.name.function", "text", "keyword.operator", "text" - ].concat(functionRules["(args)->"].token), - regex : "(" + identifier + ")(\\s*)(=)(\\s*)" + functionRules["(args)->"].regex - }, { - //play : (args) -> - token : [ - "entity.name.function", "text", "punctuation.operator", "text" - ].concat(functionRules["(args)->"].token), - regex : "(" + identifier + ")(\\s*)(:)(\\s*)" + functionRules["(args)->"].regex - }, { - //play = () -> - token : [ - "entity.name.function", "text", "keyword.operator", "text" - ].concat(functionRules["()->"].token), - regex : "(" + identifier + ")(\\s*)(=)(\\s*)" + functionRules["()->"].regex - }, { - //play : () -> - token : [ - "entity.name.function", "text", "punctuation.operator", "text" - ].concat(functionRules["()->"].token), - regex : "(" + identifier + ")(\\s*)(:)(\\s*)" + functionRules["()->"].regex - }, { - //play = -> - token : [ - "entity.name.function", "text", "keyword.operator", "text", "storage.type" - ], - regex : "(" + identifier + ")(\\s*)(=)(\\s*)([\\-=]>)" - }, { - //play : -> - token : [ - "entity.name.function", "text", "punctuation.operator", "text", "storage.type" - ], - regex : "(" + identifier + ")(\\s*)(:)(\\s*)([\\-=]>)" + //play = (...) -> + token : ["entity.name.function", "text", "keyword.operator", "text"].concat(functionRule.token), + regex : "(" + identifier + ")(\\s*)([=:])(\\s*)" + functionRule.regex }, - functionRules["({args})->"], - functionRules["({})->"], - functionRules["(args)->"], - functionRules["()->"] - , { - token : "identifier", - regex : "(?:(?:\\.|::)\\s*)" + identifier - }, { + functionRule, + { token : "variable", regex : "@(?:" + identifier + ")?" }, { @@ -240,7 +155,7 @@ define(function(require, exports, module) { regex : identifier }, { token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\." + regex : "\\,|\\." }, { token : "storage.type", regex : "[\\-=]>"