/*!
 * bewbem
 * Copyright(c) 2015 VovanR <mail@vovanr.com>
 * MIT Licensed
 */

module.exports = {
    /**
     * @param {String} name
     * @return {String}
     */
    getBlockName: function (name) {
        var result = name.split('_')[0];

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemName: function (name) {
        var result = '';

        if (/__/.test(name)) {
            result = name.split('__')[1].split('_')[0];
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getBlockModName: function (name) {
        var result = '';

        if (/_/.test(name)) {
            if (!/__/.test(name)) {
                result = name.split('_')[1];
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getBlockModValue: function (name) {
        var result = '';

        if (/_/.test(name)) {
            if (!/__/.test(name)) {
                result = name.split('_')[2] || '';
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemModName: function (name) {
        var result = '';

        if (/__/.test(name)) {
            name = name.split('__')[1];

            if (/_/.test(name)) {
                result = name.split('_')[1];
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemModValue: function (name) {
        var result = '';

        if (/__/.test(name)) {
            name = name.split('__')[1];

            if (/_/.test(name)) {
                result = name.split('_')[2] || '';
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {Object}
     */
    parse: function (name) {
        return {
            block: {
                name: this.getBlockName(name),
                mod: {
                    name: this.getBlockModName(name),
                    value: this.getBlockModValue(name)
                }
            },
            elem: {
                name: this.getElemName(name),
                mod: {
                    name: this.getElemModName(name),
                    value: this.getElemModValue(name)
                }
            }
        };
    },
};

@@ -74,16 +74,65 @@
 ed%0A */%0A%0A
+// For Parser memoization%0Avar parsedCache = %7B%7D;%0A%0A
 module.e
@@ -1978,17 +1978,87 @@
     
-return %7B%0A
+if (!parsedCache.hasOwnProperty(name)) %7B%0A            parsedCache%5Bname%5D = %7B%0A    
     
@@ -2070,24 +2070,28 @@
    block: %7B%0A
+    
             
@@ -2133,39 +2133,47 @@
                 
+ 
+   
 mod: %7B%0A
+    
                 
@@ -2222,32 +2222,36 @@
                 
+   
+ 
 value: this.getB
@@ -2277,34 +2277,42 @@
                 
-%7D%0A
+    %7D%0A    
             %7D,%0A 
@@ -2326,16 +2326,20 @@
     
+  
+  
 elem: %7B%0A
     
@@ -2330,24 +2330,28 @@
     elem: %7B%0A
+    
             
@@ -2392,32 +2392,36 @@
                 
+    
 mod: %7B%0A         
@@ -2423,32 +2423,36 @@
                 
+ 
+   
 name: this.getEl
@@ -2460,32 +2460,36 @@
 mModName(name),%0A
+    
                 
@@ -2518,32 +2518,36 @@
 mModValue(name)%0A
+    
                 
@@ -2552,32 +2552,36 @@
   %7D%0A            
+    
 %7D%0A        %7D;%0A   
@@ -2574,17 +2574,66 @@
         
+ 
-%7D
+   %7D;%0A        %7D%0A%0A        return parsedCache%5Bname%5D
 ;%0A    %7D,

Add memoization to parser #2