[TxMt] Better JavaScript functions

Andreas Wahlin andreaswahlin at bredband.net
Sun Sep 18 10:01:34 UTC 2005


I added the following to my javascript bundle, over the normal  
function detection code (but that wouldn't make any difference, right?)

         {    name = "meta.function.js";
             match = "^\\s*([a-zA-Z_]\\w*):\\s*(function)\\s*\\(([^)] 
*)\\)";
             captures =
             {    1 = { name = "entity.name.function.js"; };
                 2 = { name = "storage.type.function.js"; };
                 3 = { name = "variable.parameter.function.js"; };
             };
         },

         {    name = "meta.function.js";
             match = "^\\s*(var\\b)?\\s*this\\.([a-zA-Z_]\\w*)\\s*=\ 
\s*(function)\\s*\\(([^)]*)\\)";
             captures =
             {    1 = { name = "storage.type.js"; };
                 2 = { name = "entity.name.function.js"; };
                 3 = { name = "storage.type.function.js"; };
                 4 = { name = "variable.parameter.function.js"; };
             };
         },

the first should match functions like

functionName: function(arguments) { ... }

and the second

(var) this.functionName = function(arguments) { ... }
with the first var being optional.

Is it correct? It seems to work but I don't dare trust my RegExp  
skills ;)
Any other comments?

Andreas



More information about the textmate mailing list